(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
asan/
use-after-scope-2.c
       1  // { dg-do run }
       2  // { dg-shouldfail "asan" }
       3  
       4  int *bar (int *x, int *y) { return y; }
       5  
       6  int foo (void)
       7  {
       8    char *p;
       9    {
      10      char a = 0;
      11      p = &a;
      12    }
      13  
      14    if (*p)
      15      return 1;
      16    else
      17      return 0;
      18  }
      19  
      20  int
      21  main (void)
      22  {
      23    char *ptr;
      24    {
      25      char my_char[9];
      26      ptr = &my_char[0];
      27    }
      28  
      29    int a[16];
      30    int *p, *q = a;
      31    {
      32      int b[16];
      33      p = bar (a, b);
      34    }
      35    bar (a, q);
      36    {
      37      int c[16];
      38      q = bar (a, c);
      39    }
      40    int v = *bar (a, q);
      41    return v;
      42  }
      43  
      44  
      45  // { dg-output "ERROR: AddressSanitizer: stack-use-after-scope on address.*(\n|\r\n|\r)" }
      46  // { dg-output "READ of size 4 at.*" }
      47  // { dg-output ".*'c' \\(line 37\\) <== Memory access at offset \[0-9\]* is inside this variable.*" }