Debian Codegraph @

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

raw
1 /* PR sanitizer/115127 */
2 /* { dg-do run } */
3 /* { dg-options "-fsanitize=undefined" } */
4
5 #include <stdio.h>
6
7 __attribute__((noipa)) int
8 f1 (unsigned a)
9 {
10 return __builtin_clz (a) == 0;
11 }
12
13 __attribute__((noipa)) int
14 f2 (unsigned long a)
15 {
16 return __builtin_clzl (a) != 0;
17 }
18
19 __attribute__((noipa)) int
20 f3 (unsigned long long a)
21 {
22 return __builtin_clzll (a) == __CHAR_BIT__ * __SIZEOF_LONG_LONG__ - 1;
23 }
24
25 __attribute__((noipa)) int
26 f4 (unsigned a)
27 {
28 return __builtin_clz (a) != __CHAR_BIT__ * __SIZEOF_INT__ - 1;
29 }
30
31 __attribute__((noipa)) int
32 f5 (unsigned long a)
33 {
34 return __builtin_ctzl (a) == 0;
35 }
36
37 __attribute__((noipa)) int
38 f6 (unsigned long long a)
39 {
40 return __builtin_ctzll (a) != 0;
41 }
42
43 __attribute__((noipa)) int
44 f7 (unsigned a)
45 {
46 return __builtin_ctz (a) == 4;
47 }
48
49 __attribute__((noipa)) int
50 f8 (unsigned long a)
51 {
52 return __builtin_ctzl (a) != 4;
53 }
54
55 __attribute__((noipa)) int
56 f9 (unsigned long long a)
57 {
58 return __builtin_ctzll (a) >= 4;
59 }
60
61 __attribute__((noipa)) int
62 f10 (unsigned a)
63 {
64 return __builtin_ctz (a) < 4;
65 }
66
67 int
68 main ()
69 {
70 fprintf (stderr, "FOO MARKER1\n");
71 f1 (0);
72 f2 (0);
73 f3 (0);
74 f4 (0);
75 fprintf (stderr, "FOO MARKER2\n");
76 f5 (0);
77 f6 (0);
78 f7 (0);
79 f8 (0);
80 f9 (0);
81 f10 (0);
82 fprintf (stderr, "FOO MARKER3\n");
83 }
84
85 /* { dg-output "FOO MARKER1(\n|\r\n|\r)" } */
86 /* { dg-output "(\[^\n\r]*runtime error: passing zero to __builtin_clz\\\(\\\), which is not a valid argument\[^\n\r]*(\n|\r\n|\r)){4}" } */
87 /* { dg-output "FOO MARKER2(\n|\r\n|\r)" } */
88 /* { dg-output "(\[^\n\r]*runtime error: passing zero to __builtin_ctz\\\(\\\), which is not a valid argument\[^\n\r]*(\n|\r\n|\r)){6}" } */
89 /* { dg-output "FOO MARKER3" } */