diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp index bbe89112e4dbe..e9dd919d41497 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 0000000000000..5844749a6d977 --- /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 +#include +#include + +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]] +}