(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
analyzer/
taint-assert-macro-expansion.c
       1  /* Integration test of how the execution path looks for
       2     -Wanalyzer-tainted-assertion with macro-tracking enabled
       3     (the default).  */
       4  
       5  // TODO: remove need for this option
       6  /* { dg-additional-options "-fanalyzer-checker=taint" } */
       7  
       8  /* { dg-additional-options "-fdiagnostics-show-path-depths" } */
       9  /* { dg-additional-options "-fdiagnostics-path-format=inline-events -fdiagnostics-show-caret" } */
      10  
      11  /* An assertion macro that has a call to a __noreturn__ function.  */
      12  
      13  extern void my_assert_fail (const char *expr, const char *file, int line)
      14    __attribute__ ((__noreturn__));
      15  
      16  #define MY_ASSERT_1(EXPR) \
      17    do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0) /* { dg-warning "use of attacked-controlled value in condition for assertion \\\[CWE-617\\\] \\\[-Wanalyzer-tainted-assertion\\\]" } */
      18  
      19  int __attribute__((tainted_args))
      20  test_tainted_MY_ASSERT_1 (int n)
      21  {
      22    MY_ASSERT_1 (n > 0);
      23    return n * n;
      24  }
      25  
      26  /* { dg-begin-multiline-output "" }
      27     do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      28                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      29     { dg-end-multiline-output "" } */
      30  // note: in expansion of macro 'MY_ASSERT_1'
      31  /* { dg-begin-multiline-output "" }
      32     MY_ASSERT_1 (n > 0);
      33     ^~~~~~~~~~~
      34    'test_tainted_MY_ASSERT_1': event 1 (depth 0)
      35      |
      36      | test_tainted_MY_ASSERT_1 (int n)
      37      | ^~~~~~~~~~~~~~~~~~~~~~~~
      38      | |
      39      | (1) function 'test_tainted_MY_ASSERT_1' marked with '__attribute__((tainted_args))'
      40      |
      41      +--> 'test_tainted_MY_ASSERT_1': event 2 (depth 1)
      42             |
      43             | test_tainted_MY_ASSERT_1 (int n)
      44             | ^~~~~~~~~~~~~~~~~~~~~~~~
      45             | |
      46             | (2) entry to 'test_tainted_MY_ASSERT_1'
      47             |
      48           'test_tainted_MY_ASSERT_1': event 3 (depth 1)
      49             |
      50             |   do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      51             |           ^
      52             |           |
      53             |           (3) use of attacker-controlled value for control flow
      54     { dg-end-multiline-output "" } */
      55  // note: in expansion of macro 'MY_ASSERT_1'
      56  /* { dg-begin-multiline-output "" }
      57             |   MY_ASSERT_1 (n > 0);
      58             |   ^~~~~~~~~~~
      59             |
      60           'test_tainted_MY_ASSERT_1': event 4 (depth 1)
      61             |
      62             |   do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      63             |           ^
      64             |           |
      65             |           (4) following 'true' branch (when 'n <= 0')...
      66     { dg-end-multiline-output "" } */
      67  // note: in expansion of macro 'MY_ASSERT_1'
      68  /* { dg-begin-multiline-output "" }
      69             |   MY_ASSERT_1 (n > 0);
      70             |   ^~~~~~~~~~~
      71             |
      72           'test_tainted_MY_ASSERT_1': event 5 (depth 1)
      73             |
      74             |   do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      75             |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      76             |                     |
      77             |                     (5) ...to here
      78     { dg-end-multiline-output "" } */
      79  // note: in expansion of macro 'MY_ASSERT_1'
      80  /* { dg-begin-multiline-output "" }
      81             |   MY_ASSERT_1 (n > 0);
      82             |   ^~~~~~~~~~~
      83             |
      84           'test_tainted_MY_ASSERT_1': event 6 (depth 1)
      85             |
      86             |   do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
      87             |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      88             |                     |
      89             |                     (6) treating 'my_assert_fail' as an assertion failure handler due to '__attribute__((__noreturn__))'
      90     { dg-end-multiline-output "" } */
      91  // note: in expansion of macro 'MY_ASSERT_1'
      92  /* { dg-begin-multiline-output "" }
      93             |   MY_ASSERT_1 (n > 0);
      94             |   ^~~~~~~~~~~
      95             |
      96     { dg-end-multiline-output "" } */