[Sanitizer][RISCV] Fix FastUnwindTest
Fixes the `FastUnwindTest` unit test for RISC-V.
These changes reflect the different stack organization commonly used for
that architecture.
Differential Revision: https://reviews.llvm.org/D90574
GitOrigin-RevId: 68e5614b42823cc1eef48916e1e6f551ad61a055
diff --git a/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp b/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
index 9a47b4e..af19da0 100644
--- a/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
+++ b/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
@@ -32,6 +32,14 @@
uhwptr fake_top;
uhwptr fake_bottom;
BufferedStackTrace trace;
+
+#if defined(__riscv)
+ const uptr kFpOffset = 4;
+ const uptr kBpOffset = 2;
+#else
+ const uptr kFpOffset = 2;
+ const uptr kBpOffset = 0;
+#endif
};
static uptr PC(uptr idx) {
@@ -49,17 +57,17 @@
// Fill an array of pointers with fake fp+retaddr pairs. Frame pointers have
// even indices.
for (uptr i = 0; i + 1 < fake_stack_size; i += 2) {
- fake_stack[i] = (uptr)&fake_stack[i+2]; // fp
+ fake_stack[i] = (uptr)&fake_stack[i + kFpOffset]; // fp
fake_stack[i+1] = PC(i + 1); // retaddr
}
// Mark the last fp point back up to terminate the stack trace.
fake_stack[RoundDownTo(fake_stack_size - 1, 2)] = (uhwptr)&fake_stack[0];
// Top is two slots past the end because UnwindFast subtracts two.
- fake_top = (uhwptr)&fake_stack[fake_stack_size + 2];
+ fake_top = (uhwptr)&fake_stack[fake_stack_size + kFpOffset];
// Bottom is one slot before the start because UnwindFast uses >.
fake_bottom = (uhwptr)mapping;
- fake_bp = (uptr)&fake_stack[0];
+ fake_bp = (uptr)&fake_stack[kBpOffset];
start_pc = PC(0);
}
@@ -120,7 +128,7 @@
trace.Unwind(start_pc, fake_bp, nullptr, true, 1);
EXPECT_EQ(1U, trace.size);
EXPECT_EQ(start_pc, trace.trace[0]);
- EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp);
+ EXPECT_EQ((uhwptr)&fake_stack[kBpOffset], trace.top_frame_bp);
}
TEST_F(FastUnwindTest, ZeroFramesStackTrace) {