summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/mips/pr51513-2.c
blob: b921904fdff116c5ea18d554f251f8072c05b3ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* { dg-do run } */
/* { dg-options "-mips16 -mcode-readable=yes" } */

/* PR tree-optimization/51513 verification variant for MIPS16, #2.  */

int __attribute__ ((weak))
frob (int i)
{
  switch (i)
    {
    case -5:
      return -2;
    case -3:
      return -1;
    case 0:
      return 0;
    case 3:
      return 1;
    case 5:
      break;
    default:
      __builtin_unreachable ();
    }
  return i;
}

int
main (void)
{
  return !(frob (-5) == -2
	   & frob (-3) == -1
	   & frob (0) == 0
	   & frob (3) == 1
	   & frob (5) == 5);
}

/* Without the fix for PR tree-optimization/51513 truncated code
   would be emitted for `frob', like:

	.text
	.align	2
	.weak	frob
	.set	mips16
	.set	nomicromips
	.ent	frob
	.type	frob, @function
frob:
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	addiu	$2,$4,5
	.end	frob
	.size	frob, .-frob

  meaning `frob' will have no chance to return, let alone produce
  the result expected.  */