2014-04-15 Max Ostapenko <m.ostapenko@partner.samsung.com>
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / load-bool-enum.c
blob4ffd6325bc1021b34c4ea4f8839fe0dd030759c9
1 /* { dg-do run } */
2 /* { dg-options "-fsanitize=bool,enum" } */
4 #ifndef __cplusplus
5 #define bool _Bool
6 #endif
7 enum A { B = -3, C = 2 } a;
8 bool b;
10 __attribute__((noinline, noclone)) enum A
11 foo (bool *p)
13 *p = b; /* { dg-output "load-bool-enum.c:13:\[^\n\r]*runtime error: \[^\n\r]*load of value 4, which is not a valid value for type '(_B|b)ool'\[^\n\r]*(\n|\r\n|\r)*" } */
14 return a; /* { dg-output "\[^\n\r]*load-bool-enum.c:14:\[^\n\r]*runtime error: \[^\n\r]*load of value 9, which is not a valid value for type 'A'\[^\n\r]*(\n|\r\n|\r)*" { target c++ } } */
17 int
18 main ()
20 char c = 4;
21 int d = 9;
22 if (sizeof (int) != sizeof (a) || sizeof (b) != 1)
23 return 0;
24 __builtin_memcpy (&a, &d, sizeof (int));
25 __builtin_memcpy (&b, &c, 1);
26 bool e;
27 foo (&e);
28 return 0;