summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c
blob: 6ae6f3c233f74208d665400af1aff7194a0dbd49 (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
/* Test -f*sanitize*=all */
/* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
/* { dg-options "-fsanitize=undefined,float-cast-overflow,float-divide-by-zero -fno-sanitize=all -fdump-tree-optimized" } */

int a[4];

int
f1 (int x, int y, int z)
{
  return a[x] + (1 << y) + (100 / z);
}

char *
f2 (int x)
{
  char *p = (char *) __builtin_calloc (64, 1);
  p[x] = 3;
  return p;
}

int
f3 (int x, int *y, double z, double w)
{
  int a[*y];
  if (x)
    __builtin_unreachable ();
  asm volatile ("" : : "r" (&a[0]));
  return z / w;
}

int
main ()
{
  return 0;
}

/* { dg-final { scan-tree-dump-not "__ubsan_" "optimized" } } */
/* { dg-final { scan-tree-dump-not "UBSAN_CHECK_" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */