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