[compiler-rt] 7c3b67d - [hwasan] Respect strip_path_prefix printing locals (#76132)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 21 16:03:10 PST 2023
Author: Vitaly Buka
Date: 2023-12-21T16:03:06-08:00
New Revision: 7c3b67d2038cfb48a80299089f6a1308eee1df7f
URL: https://github.com/llvm/llvm-project/commit/7c3b67d2038cfb48a80299089f6a1308eee1df7f
DIFF: https://github.com/llvm/llvm-project/commit/7c3b67d2038cfb48a80299089f6a1308eee1df7f.diff
LOG: [hwasan] Respect strip_path_prefix printing locals (#76132)
Added:
compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
Modified:
compiler-rt/lib/hwasan/hwasan_report.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index bbe89112e4dbe1..e9dd919d414972 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -205,6 +205,7 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
tag_t addr_tag, uptr untagged_addr) {
uptr frames = Min((uptr)flags()->stack_history_size, sa->size());
bool found_local = false;
+ InternalScopedString location;
for (uptr i = 0; i < frames; i++) {
const uptr *record_addr = &(*sa)[i];
uptr record = *record_addr;
@@ -236,8 +237,13 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
Printf("\nPotentially referenced stack objects:\n");
found_local = true;
}
- Printf(" %s in %s %s:%d\n", local.name, local.function_name,
- local.decl_file, local.decl_line);
+ StackTracePrinter::GetOrInit()->RenderSourceLocation(
+ &location, local.decl_file, local.decl_line, /* column= */ 0,
+ common_flags()->symbolize_vs_style,
+ common_flags()->strip_path_prefix);
+ Printf(" %s in %s %s\n", local.name, local.function_name,
+ location.data());
+ location.clear();
}
frame.Clear();
}
diff --git a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
new file mode 100644
index 00000000000000..5844749a6d9772
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
@@ -0,0 +1,27 @@
+// RUN: %clang_hwasan -O0 %s -o %t && %env_hwasan_opts=strip_path_prefix='"%S/"' not %run %t 2>&1 | FileCheck %s
+
+// Stack histories currently are not recorded on x86.
+// XFAIL: target=x86_64{{.*}}
+
+#include <assert.h>
+#include <sanitizer/hwasan_interface.h>
+#include <stdio.h>
+
+int t;
+
+__attribute__((noinline)) char *buggy() {
+ char *volatile p;
+ char zzz = {};
+ char yyy = {};
+ p = t ? &yyy : &zzz;
+ return p;
+}
+
+int main() {
+ char *p = buggy();
+ return *p;
+ // CHECK: READ of size 1 at
+ // CHECK: #0 {{.*}} in main strip_path_prefix.c:[[@LINE-2]]
+ // CHECK: Potentially referenced stack objects:
+ // CHECK: zzz in buggy strip_path_prefix.c:[[@LINE-12]]
+}
More information about the llvm-commits
mailing list