summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/safe-indirect-jump-2.c
blob: b51034fa1b0c259bd705a2658828074dea7f38f4 (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
/* { dg-do compile } */
/* { dg-options "-mno-speculate-indirect-jumps" } */

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

int bar (int);
int baz (int);
int spaz (int);

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;
}

/* The following assumes CR7 as the first chosen volatile.  */

/* { dg-final { scan-assembler "crset 30" } } */
/* { dg-final { scan-assembler "beqctr- 7" } } */
/* { dg-final { scan-assembler "b ." } } */