(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
asan/
pr70541.c
       1  /* { dg-do run } */
       2  /* { dg-options "-fno-builtin-malloc -fno-builtin-free" } */
       3  /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
       4  /* { dg-shouldfail "asan" } */
       5  
       6  #include <stdio.h>
       7  #include <stdlib.h>
       8  
       9  struct Simple {
      10    int value;
      11  };
      12  
      13  int f(struct Simple simple) {
      14    return simple.value;
      15  }
      16  
      17  int main() {
      18    struct Simple *psimple = (struct Simple *) malloc(sizeof(struct Simple));
      19    psimple->value = 42;
      20    free(psimple);
      21    printf("%d\n", f(*psimple));
      22    return 0;
      23  }
      24  
      25  /* { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address\[^\n\r]*" } */
      26  /* { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" } */
      27  /* { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" } */
      28  /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:21|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
      29  /* { dg-output "\[^\n\r]*freed by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
      30  /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)free|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
      31  /* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:20|\[^\n\r]*:0)|\[(\]).*(\n|\r\n|\r)" } */
      32  /* { dg-output "\[^\n\r]*previously allocated by thread T0 here:\[^\n\r]*(\n|\r\n|\r)" } */
      33  /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*(interceptor_|wrap_|)malloc|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */
      34  /* { dg-output "    #1 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*pr70541.c:18|\[^\n\r]*:0)|\[(\])\[^\n\r]*(\n|\r\n|\r)" } */