[gcc]
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / safe-indirect-jump-5.c
blob5a4cd9a838e6c13aefcd72271ef3ee89e3e9a3f2
1 /* { dg-do run } */
2 /* { dg-additional-options "-mno-speculate-indirect-jumps -Wno-pedantic" } */
4 /* Test for deliberate misprediction of computed goto. */
6 int __attribute__((noinline)) bar (int i)
8 return 1960 + i;
11 int __attribute__((noinline)) baz (int i)
13 return i * i;
16 int __attribute__((noinline)) spaz (int i)
18 return i + 1;
21 int foo (int x)
23 static void *labptr[] = { &&lab0, &&lab1, &&lab2 };
25 if (x < 0 || x > 2)
26 return -1;
28 goto *labptr[x];
30 lab0:
31 return bar (x);
33 lab1:
34 return baz (x) + 1;
36 lab2:
37 return spaz (x) / 2;
40 int main ()
42 if (foo (0) != 1960)
43 __builtin_abort ();
45 if (foo (1) != 2)
46 __builtin_abort ();
48 if (foo (2) != 1)
49 __builtin_abort ();
51 if (foo (3) != -1)
52 __builtin_abort ();
54 return 0;