aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-5.c
blob: fd04ffd56c7b3dc017a7381243dccfcc6b7edda8 (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-additional-options "-mno-speculate-indirect-jumps -Wno-pedantic" } */
/* { dg-warning "'-mno-speculate-indirect-jumps' is deprecated" "" { target *-*-* } 0 } */

/* Test for deliberate misprediction of computed goto.  */

int __attribute__((noinline)) bar (int i)
{
  return 1960 + i;
}

int __attribute__((noinline)) baz (int i)
{
  return i * i;
}

int __attribute__((noinline)) spaz (int i)
{
  return i + 1;
}

int foo (int x)
{
  static void *labptr[] = { &&lab0, &&lab1, &&lab2 };

  if (x < 0 || x > 2)
    return -1;

  goto *labptr[x];

 lab0:
  return bar (x);

 lab1:
  return baz (x) + 1;

 lab2:
  return spaz (x) / 2;
}

int main ()
{
  if (foo (0) != 1960)
    __builtin_abort ();

  if (foo (1) != 2)
    __builtin_abort ();

  if (foo (2) != 1)
    __builtin_abort ();

  if (foo (3) != -1)
    __builtin_abort ();

  return 0;
}