Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / taint-assert-BUG_ON.c
blob328940d29839b1512eee0570f2eaf9970951719f
1 /* We need this, otherwise the warnings are emitted inside the macros, which
2 makes it hard to write the DejaGnu directives. */
3 /* { dg-additional-options " -ftrack-macro-expansion=0" } */
5 /* Adapted from code in the Linux kernel, which has this: */
6 /* SPDX-License-Identifier: GPL-2.0 */
8 #define __noreturn __attribute__ ((__noreturn__))
10 void panic(const char *fmt, ...) __noreturn;
12 int _printk(const char *fmt, ...);
13 #define __printk_index_emit(...) do {} while (0)
14 #define printk_index_wrap(_p_func, _fmt, ...) \
15 ({ \
16 __printk_index_emit(_fmt, NULL, NULL); \
17 _p_func(_fmt, ##__VA_ARGS__); \
19 #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
20 #define barrier_before_unreachable() do { } while (0)
22 #define BUG() do { \
23 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
24 barrier_before_unreachable(); \
25 panic("BUG!"); \
26 } while (0)
28 #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
30 void __attribute__((tainted_args))
31 test_BUG(int n)
33 if (n > 100) /* { dg-message "use of attacker-controlled value for control flow" } */
34 BUG(); /* { dg-warning "-Wanalyzer-tainted-assertion" "warning" } */
35 /* { dg-message "treating 'panic' as an assertion failure handler due to '__attribute__\\(\\(__noreturn__\\)\\)'" "final event" { target *-*-* } .-1 } */
38 void __attribute__((tainted_args))
39 test_BUG_ON(int n)
41 BUG_ON(n > 100); /* { dg-warning "-Wanalyzer-tainted-assertion" "warning" } */
42 /* { dg-message "treating 'panic' as an assertion failure handler due to '__attribute__\\(\\(__noreturn__\\)\\)'" "final event" { target *-*-* } .-1 } */
45 int __attribute__((tainted_args))
46 test_switch_BUG_1(int n)
48 switch (n) { /* { dg-message "use of attacker-controlled value for control flow" } */
49 default:
50 case 0:
51 return 5;
52 case 1:
53 return 22;
54 case 2:
55 return -1;
56 case 42:
57 BUG (); /* { dg-warning "-Wanalyzer-tainted-assertion" } */
61 int __attribute__((tainted_args))
62 test_switch_BUG(int n)
64 switch (n) { /* { dg-message "use of attacker-controlled value for control flow" } */
65 case 0:
66 return 5;
67 case 1:
68 return 22;
69 case 2:
70 return -1;
72 BUG (); /* { dg-warning "-Wanalyzer-tainted-assertion" } */