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, ...) \
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)
23 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
24 barrier_before_unreachable(); \
28 #define BUG_ON(condition) do { if (condition) BUG(); } while (0)
30 void __attribute__((tainted_args
))
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
))
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" } */
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" } */
72 BUG (); /* { dg-warning "-Wanalyzer-tainted-assertion" } */