aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/c-c++-common/ubsan/pr60613-1.c
blob: 6794532a486881e00b4f1d879a2b3828e1017c62 (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
/* PR sanitizer/60613 */
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined" } */

#include <stdio.h>

long long y;

__attribute__((noinline, noclone)) long long
foo (long long x)
{
  asm ("");
  if (x >= 0 || x < -2040)
    return 23;
  x += 2040;
  return x - y;
}

__attribute__((noinline, noclone)) long long
bar (long long x)
{
  asm ("");
  return 8LL - x;
}

int
main ()
{
  fputs ("UBSAN TEST START\n", stderr);

  y = 1;
  if (foo (8 - 2040) != 8 - 1)
    __builtin_abort ();
  if (bar (1) != 8 - 1)
    __builtin_abort ();

  fputs ("UBSAN TEST END\n", stderr);
  return 0;
}

/* { dg-output "UBSAN TEST START(\n|\r\n|\r)UBSAN TEST END" } */