| 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 { |
| 12 |
int counter; |
| 13 |
} atomic_t; |
| 14 |
|
| 15 |
/* Adapted from include/linux/compiler_attributes.h */ |
| 16 |
#define __always_inline inline __attribute__((__always_inline__)) |
| 17 |
|
| 18 |
/* Adapted from include/linux/compiler-gcc.h */ |
| 19 |
#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) |
| 20 |
|
| 21 |
/* Adapted from include/linux/jump_label.h, which has: */ |
| 22 |
|
| 23 |
struct static_key { |
| 24 |
atomic_t enabled; |
| 25 |
union { |
| 26 |
/* [...snip...] */ |
| 27 |
struct jump_entry *entries; |
| 28 |
/* [...snip...] */ |
| 29 |
}; |
| 30 |
}; |
| 31 |
|
| 32 |
struct static_key_true { |
| 33 |
struct static_key key; |
| 34 |
}; |
| 35 |
|
| 36 |
struct static_key_false { |
| 37 |
struct static_key key; |
| 38 |
}; |
| 39 |
|
| 40 |
extern bool ____wrong_branch_error(void); |
| 41 |
|
| 42 |
/* Adapted from arch/x86/include/asm/jump_label.h */ |
| 43 |
|
| 44 |
#define JUMP_TABLE_ENTRY \ |
| 45 |
".pushsection __jump_table, \"aw\" \n\t" \ |
| 46 |
/*_ASM_ALIGN*/ "\n\t" \ |
| 47 |
".long 1b - . \n\t" \ |
| 48 |
".long %l[l_yes] - . \n\t" \ |
| 49 |
/*_ASM_PTR*/ "%c0 + %c1 - .\n\t" \ |
| 50 |
".popsection \n\t" |
| 51 |
|
| 52 |
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) |
| 53 |
{ |
| 54 |
asm_volatile_goto("1:" |
| 55 |
/*".byte " __stringify(BYTES_NOP5) "\n\t" */ |
| 56 |
JUMP_TABLE_ENTRY |
| 57 |
: : "i" (key), "i" (branch) : : l_yes); |
| 58 |
|
| 59 |
return false; |
| 60 |
l_yes: |
| 61 |
return true; |
| 62 |
} |
| 63 |
|
| 64 |
static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) |
| 65 |
{ |
| 66 |
asm_volatile_goto("1:" |
| 67 |
"jmp %l[l_yes]\n\t" |
| 68 |
JUMP_TABLE_ENTRY |
| 69 |
: : "i" (key), "i" (branch) : : l_yes); |
| 70 |
|
| 71 |
return false; |
| 72 |
l_yes: |
| 73 |
return true; |
| 74 |
} |
| 75 |
|
| 76 |
/* Adapted from include/linux/dynamic_debug.h */ |
| 77 |
|
| 78 |
struct _ddebug { |
| 79 |
/* [...snip...] */ |
| 80 |
const char *function; |
| 81 |
const char *filename; |
| 82 |
const char *format; |
| 83 |
unsigned int lineno:18; |
| 84 |
/* [...snip...] */ |
| 85 |
unsigned int flags:8; |
| 86 |
union { |
| 87 |
struct static_key_true dd_key_true; |
| 88 |
struct static_key_false dd_key_false; |
| 89 |
} key; |
| 90 |
} __attribute__((aligned(8))); |
| 91 |
|
| 92 |
extern void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...); |
| 93 |
|
| 94 |
static void expanded_dynamic_pr_debug(void) { |
| 95 |
do { |
| 96 |
static struct _ddebug __attribute__((__aligned__(8))) |
| 97 |
__attribute__((__section__("__dyndbg"))) __UNIQUE_ID_ddebug277 = { /* { dg-warning "track '__UNIQUE_ID_ddebug277': no" } */ |
| 98 |
.function = __func__, |
| 99 |
.filename = __FILE__, |
| 100 |
.format = ("hello world"), |
| 101 |
.lineno = __LINE__, |
| 102 |
.flags = 0}; |
| 103 |
if (({ |
| 104 |
bool branch; |
| 105 |
if (__builtin_types_compatible_p( |
| 106 |
typeof(*&__UNIQUE_ID_ddebug277.key.dd_key_false), |
| 107 |
struct static_key_true)) |
| 108 |
branch = arch_static_branch_jump( |
| 109 |
&(&__UNIQUE_ID_ddebug277.key.dd_key_false)->key, false); |
| 110 |
else if (__builtin_types_compatible_p( |
| 111 |
typeof(*&__UNIQUE_ID_ddebug277.key.dd_key_false), |
| 112 |
struct static_key_false)) |
| 113 |
branch = arch_static_branch( |
| 114 |
&(&__UNIQUE_ID_ddebug277.key.dd_key_false)->key, false); |
| 115 |
else |
| 116 |
branch = ____wrong_branch_error(); |
| 117 |
__builtin_expect(!!(branch), 0); |
| 118 |
})) |
| 119 |
__dynamic_pr_debug(&__UNIQUE_ID_ddebug277, |
| 120 |
"hello world"); |
| 121 |
} while (0); |
| 122 |
} |