diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp --- a/compiler-rt/lib/hwasan/hwasan_report.cpp +++ b/compiler-rt/lib/hwasan/hwasan_report.cpp @@ -652,7 +652,10 @@ // See the frame breakdown defined in __hwasan_tag_mismatch (from // hwasan_tag_mismatch_aarch64.S). void ReportRegisters(uptr *frame, uptr pc) { - Printf("Registers where the failure occurred (pc %p):\n", pc); + // hwasan_check* reduces the stack pointer by 256, then __hwasan_tag_mismatch + // passes it to this function. + Printf("Registers where the failure occurred (pc %p, sp %p):\n", pc, + reinterpret_cast(frame) + 256); // We explicitly print a single line (4 registers/line) each iteration to // reduce the amount of logcat error messages printed. Each Printf() will diff --git a/compiler-rt/test/hwasan/TestCases/stack-pointer-report.c b/compiler-rt/test/hwasan/TestCases/stack-pointer-report.c new file mode 100644 --- /dev/null +++ b/compiler-rt/test/hwasan/TestCases/stack-pointer-report.c @@ -0,0 +1,22 @@ +// RUN: %clang_hwasan -DSIZE=2 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s + +// Register reporting is not supported on x86_64. +// XFAIL: x86_64 + +#include +#include + +__attribute__((noinline)) void f() { + char z[SIZE]; + // Copy stack pointer just before the fault into x11, so we can compare that + // x11 is equal to the sp in the report. + __asm __volatile__("mov x11, sp"); + volatile char sink = z[SIZE]; +} + +int main() { + f(); +} + +// CHECK: sp 0x[[STACK:[0-9a-f]+]] +// CHECK: x11 {{[0]*}}{{[0-9a-f]+}}[[STACK]]