Debian Codegraph @

gcc/testsuite/c-c++-common/ubsan/attrib-2.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow" } */
3
4 /* Test that we don't instrument functions marked with
5 no_sanitize_undefined attribute. */
6
7 #ifndef __cplusplus
8 #define bool _Bool
9 #endif
10 enum A { B = -3, C = 2 } a;
11 bool b;
12
13 __attribute__((no_sanitize_undefined))
14 static void
15 vla_bound (void)
16 {
17 int i = -1;
18 volatile int a[i];
19 }
20
21 __attribute__((no_sanitize_undefined))
22 static void
23 si_overflow (void)
24 {
25 int x = 123, y = 267;
26 volatile int z1 = x + y;
27 volatile int z2 = x - y;
28 volatile int z3 = x * y;
29 volatile int z4 = x / y;
30 }
31
32 __attribute__((no_sanitize_undefined))
33 static void
34 null (int *p)
35 {
36 *p = 42;
37 }
38
39 __attribute__((no_sanitize_undefined))
40 static void
41 retrn (int *p)
42 {
43 *p = 42;
44 }
45
46 __attribute__((no_sanitize_undefined))
47 static enum A
48 bool_enum (bool *p)
49 {
50 *p = b;
51 return a;
52 }
53
54 __attribute__((no_sanitize_undefined))
55 static void
56 float_zero (void)
57 {
58 volatile float a = 4.2f, b = 0.0f, c;
59 c = a / b;
60 }
61
62 __attribute__((no_sanitize_undefined))
63 static void
64 float_cast (void)
65 {
66 volatile double d = 300;
67 volatile signed char c;
68 c = d;
69 }
70
71 __attribute__((no_sanitize(("undefined"))))
72 static void
73 float_cast2 (void)
74 {
75 volatile double d = 300;
76 volatile signed char c;
77 c = d;
78 }
79
80
81 /* { dg-final { scan-assembler-not "__ubsan_handle" } } */