xref: /llvm-project/compiler-rt/test/hwasan/TestCases/short-granule-disabled.cpp (revision 433b2eaf91afa35006899da8fd7f9bde3df3507c)
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 
main()12 int main() {
13   void *p = malloc(16);
14   memset(p, 0xff, 16);
15   free(p);
16 
17   // Relies on the LRU cache immediately recycling the allocation above.
18   p = malloc(8);
19   free(p); // Regression was here, in the magic-string check in the runtime.
20   return 0;
21 }
22