middle-end: Fix stalled swapped condition code value [PR115836]
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / asm-x86-dyndbg-2.c
blobd5e748c9acd7334df3474a6c9a3f35ce5223e1e5
1 /* Test reduced from use of dynamic_pr_debug on Linux kernel, to verify that
2 we treat the static struct _ddebug as not needing to be tracked by the
3 analyzer, thus optimizing away bloat in the analyzer's state tracking. */
5 /* { dg-do compile { target x86_64-*-* } } */
6 /* { dg-additional-options "-fdump-analyzer-untracked" } */
8 /* Adapted from various files in the Linux kernel, all of which have: */
9 /* SPDX-License-Identifier: GPL-2.0 */
11 #ifndef __cplusplus
12 typedef _Bool bool;
13 #define true 1
14 #define false 0
15 #endif
17 typedef struct {} atomic_t;
19 /* Adapted from include/linux/compiler_attributes.h */
20 #define __always_inline inline __attribute__((__always_inline__))
22 /* Adapted from include/linux/compiler-gcc.h */
23 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
25 /* Adapted from include/linux/jump_label.h, which has: */
27 struct static_key {};
29 /* Adapted from arch/x86/include/asm/jump_label.h */
31 static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
33 asm_volatile_goto("1:"
34 : : "i" (key), "i" (branch) : : l_yes);
36 return false;
37 l_yes:
38 return true;
41 static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
43 asm_volatile_goto("1:"
44 : : "i" (key), "i" (branch) : : l_yes);
46 return false;
47 l_yes:
48 return true;
51 /* Adapted from include/linux/dynamic_debug.h */
53 struct _ddebug {
54 /* [...snip...] */
55 const char *function;
56 const char *filename;
57 const char *format;
58 unsigned int lineno:18;
59 /* [...snip...] */
60 unsigned int flags:8;
61 struct static_key key;
62 } __attribute__((aligned(8)));
64 extern void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
66 static void expanded_dynamic_pr_debug(void) {
67 do {
68 static struct _ddebug __attribute__((__aligned__(8)))
69 __attribute__((__section__("__dyndbg"))) __UNIQUE_ID_ddebug277 = { /* { dg-warning "track '__UNIQUE_ID_ddebug277': no" } */
70 .function = __func__,
71 .filename = __FILE__,
72 .format = ("hello world"),
73 .lineno = __LINE__,
74 .flags = 0};
75 if (arch_static_branch(&__UNIQUE_ID_ddebug277.key, false))
76 __dynamic_pr_debug(&__UNIQUE_ID_ddebug277,
77 "hello world");
78 } while (0);