1// RUN: %clangxx_hwasan %s -o %t && %run %t 2>&1
2
3#include <sanitizer/hwasan_interface.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8// Regression test for https://reviews.llvm.org/D107938#2961070, where, on
9// reusing an allocation, we forgot to reset the short granule tag if the
10// allocator was disabled. This lead to a false positive magic-string mismatch.
11
12int main() {
13 void *p = malloc(size: 16);
14 memset(s: p, c: 0xff, n: 16);
15 free(ptr: p);
16
17 // Relies on the LRU cache immediately recycling the allocation above.
18 p = malloc(size: 8);
19 free(ptr: p); // Regression was here, in the magic-string check in the runtime.
20 return 0;
21}
22

source code of compiler-rt/test/hwasan/TestCases/short-granule-disabled.cpp