diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp @@ -49,17 +49,29 @@ // 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) { +#if defined(__riscv) + fake_stack[i] = (uptr)&fake_stack[i+4]; // fp +#else fake_stack[i] = (uptr)&fake_stack[i+2]; // fp +#endif 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. +#if defined(__riscv) + fake_top = (uhwptr)&fake_stack[fake_stack_size + 4]; +#else fake_top = (uhwptr)&fake_stack[fake_stack_size + 2]; +#endif // Bottom is one slot before the start because UnwindFast uses >. fake_bottom = (uhwptr)mapping; + #if defined(__riscv) + fake_bp = (uptr)&fake_stack[2]; + #else fake_bp = (uptr)&fake_stack[0]; + #endif start_pc = PC(0); } @@ -113,7 +125,11 @@ trace.Unwind(start_pc, fake_bp, nullptr, true, 1); EXPECT_EQ(1U, trace.size); EXPECT_EQ(start_pc, trace.trace[0]); +#if defined(__riscv) + EXPECT_EQ((uhwptr)&fake_stack[2], trace.top_frame_bp); +#else EXPECT_EQ((uhwptr)&fake_stack[0], trace.top_frame_bp); +#endif } TEST_F(FastUnwindTest, ZeroFramesStackTrace) {