[compiler-rt] 150395c - [hwasan] report failing thread for invalid free.

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 00:54:06 PDT 2021


Author: Florian Mayer
Date: 2021-08-03T08:53:53+01:00
New Revision: 150395c2bcee8e9a4c876eada81515fc917ac3b6

URL: https://github.com/llvm/llvm-project/commit/150395c2bcee8e9a4c876eada81515fc917ac3b6
DIFF: https://github.com/llvm/llvm-project/commit/150395c2bcee8e9a4c876eada81515fc917ac3b6.diff

LOG: [hwasan] report failing thread for invalid free.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D107270

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_report.cpp
    compiler-rt/test/hwasan/TestCases/double-free.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index bee1a93ef923f..625ce051d856b 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -560,8 +560,14 @@ void ReportInvalidFree(StackTrace *stack, uptr tagged_addr) {
   Printf("%s", d.Error());
   uptr pc = stack->size ? stack->trace[0] : 0;
   const char *bug_type = "invalid-free";
-  Report("ERROR: %s: %s on address %p at pc %p\n", SanitizerToolName, bug_type,
-         untagged_addr, pc);
+  const Thread *thread = GetCurrentThread();
+  if (thread) {
+    Report("ERROR: %s: %s on address %p at pc %p on thread T%zd\n",
+           SanitizerToolName, bug_type, untagged_addr, pc, thread->unique_id());
+  } else {
+    Report("ERROR: %s: %s on address %p at pc %p on unknown thread\n",
+           SanitizerToolName, bug_type, untagged_addr, pc);
+  }
   Printf("%s", d.Access());
   Printf("tags: %02x/%02x (ptr/mem)\n", ptr_tag, mem_tag);
   Printf("%s", d.Default());

diff  --git a/compiler-rt/test/hwasan/TestCases/double-free.c b/compiler-rt/test/hwasan/TestCases/double-free.c
index e97aae6edb4c2..9917fc71258b6 100644
--- a/compiler-rt/test/hwasan/TestCases/double-free.c
+++ b/compiler-rt/test/hwasan/TestCases/double-free.c
@@ -11,7 +11,7 @@ int main() {
   char * volatile x = (char*)malloc(40);
   free(x);
   free(x);
-// CHECK: ERROR: HWAddressSanitizer: invalid-free on address
+// CHECK: ERROR: HWAddressSanitizer: invalid-free on address {{.*}} at pc {{.*}} on thread T{{[0-9]+}}
 // CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)
 // CHECK: freed by thread {{.*}} here:
 // CHECK: previously allocated here:


        


More information about the llvm-commits mailing list