Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/asm-x86-dyndbg-2.c

raw
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. */
4
5 /* { dg-do compile { target x86_64-*-* } } */
6 /* { dg-additional-options "-fdump-analyzer-untracked" } */
7
8 /* Adapted from various files in the Linux kernel, all of which have: */
9 /* SPDX-License-Identifier: GPL-2.0 */
10
11 typedef struct {} atomic_t;
12
13 /* Adapted from include/linux/compiler_attributes.h */
14 #define __always_inline inline __attribute__((__always_inline__))
15
16 /* Adapted from include/linux/compiler-gcc.h */
17 #define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
18
19 /* Adapted from include/linux/jump_label.h, which has: */
20
21 struct static_key {};
22
23 /* Adapted from arch/x86/include/asm/jump_label.h */
24
25 static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
26 {
27 asm_volatile_goto("1:"
28 : : "i" (key), "i" (branch) : : l_yes);
29
30 return false;
31 l_yes:
32 return true;
33 }
34
35 static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
36 {
37 asm_volatile_goto("1:"
38 : : "i" (key), "i" (branch) : : l_yes);
39
40 return false;
41 l_yes:
42 return true;
43 }
44
45 /* Adapted from include/linux/dynamic_debug.h */
46
47 struct _ddebug {
48 /* [...snip...] */
49 const char *function;
50 const char *filename;
51 const char *format;
52 unsigned int lineno:18;
53 /* [...snip...] */
54 unsigned int flags:8;
55 struct static_key key;
56 } __attribute__((aligned(8)));
57
58 extern void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
59
60 static void expanded_dynamic_pr_debug(void) {
61 do {
62 static struct _ddebug __attribute__((__aligned__(8)))
63 __attribute__((__section__("__dyndbg"))) __UNIQUE_ID_ddebug277 = { /* { dg-warning "track '__UNIQUE_ID_ddebug277': no" } */
64 .function = __func__,
65 .filename = __FILE__,
66 .format = ("hello world"),
67 .lineno = __LINE__,
68 .flags = 0};
69 if (arch_static_branch(&__UNIQUE_ID_ddebug277.key, false))
70 __dynamic_pr_debug(&__UNIQUE_ID_ddebug277,
71 "hello world");
72 } while (0);
73 }