1  /* { dg-do run } */
       2  /* { dg-require-effective-target hwaddress_exec } */
       3  /* { dg-options "-fno-builtin-malloc -fno-builtin-free" } */
       4  /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
       5  /* { dg-shouldfail "hwasan" } */
       6  
       7  #include <stdio.h>
       8  #ifdef __cplusplus
       9  extern "C" {
      10  #endif
      11  extern void *malloc (__SIZE_TYPE__);
      12  extern void free (void *);
      13  #ifdef __cplusplus
      14  }
      15  #endif
      16  
      17  struct Simple {
      18    int value;
      19  };
      20  
      21  int f(struct Simple simple) {
      22    return simple.value;
      23  }
      24  
      25  int main() {
      26    struct Simple *psimple = (struct Simple *) malloc(sizeof(struct Simple));
      27    psimple->value = 42;
      28    free(psimple);
      29    printf("%d\n", f(*psimple));
      30    return 0;
      31  }
      32  
      33  /* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */
      34  /* { dg-output "READ of size 4 at 0x\[0-9a-f\]* tags: \[\[:xdigit:\]\]\[\[:xdigit:\]\]/\[\[:xdigit:\]\]\[\[:xdigit:\]\] \\(ptr/mem\\) in thread T0.*" } */
      35  /* { dg-output "freed by thread T0 here:.*" } */
      36  /* { dg-output "previously allocated here:" } */