xref: /linux/lib/test_context-analysis.c (revision 9b00c1609deeb7d6f68a61f3ec6988ab7e6f4535)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Compile-only tests for common patterns that should not generate false
4  * positive errors when compiled with Clang's context analysis.
5  */
6 
7 #include <linux/build_bug.h>
8 
9 /*
10  * Test that helper macros work as expected.
11  */
12 static void __used test_common_helpers(void)
13 {
14 	BUILD_BUG_ON(context_unsafe(3) != 3); /* plain expression */
15 	BUILD_BUG_ON(context_unsafe((void)2; 3) != 3); /* does not swallow semi-colon */
16 	BUILD_BUG_ON(context_unsafe((void)2, 3) != 3); /* does not swallow commas */
17 	context_unsafe(do { } while (0)); /* works with void statements */
18 }
19