1 // Checks that the __sanitizer_on_print hook gets the exact same sanitizer 2 // report as what is printed to stderr. 3 // 4 // RUN: %clangxx %s -o %t 5 // RUN: %run %t %t-onprint.txt 2>%t-stderr.txt || true 6 // RUN: diff %t-onprint.txt %t-stderr.txt 7 // 8 // UNSUPPORTED: android 9 10 #include <cassert> 11 #include <cstdio> 12 #include <cstdlib> 13 14 FILE *f; 15 volatile void *buf; 16 volatile char sink; 17 __sanitizer_on_print(const char * str)18extern "C" void __sanitizer_on_print(const char *str) { 19 fprintf(f, "%s", str); 20 fflush(f); 21 } 22 main(int argc,char * argv[])23int main(int argc, char *argv[]) { 24 assert(argc >= 2); 25 f = fopen(argv[1], "w"); 26 27 // Use-after-free to trigger ASan/TSan reports. 28 void *ptr = malloc(1); 29 buf = ptr; 30 free(ptr); 31 sink = *static_cast<char *>(ptr); 32 return 0; 33 } 34