[compiler-rt] 68e5614 - [Sanitizer][RISCV] Fix FastUnwindTest

Luís Marques via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 31 16:00:32 PST 2021


Author: Luís Marques
Date: 2021-02-01T00:00:15Z
New Revision: 68e5614b42823cc1eef48916e1e6f551ad61a055

URL: https://github.com/llvm/llvm-project/commit/68e5614b42823cc1eef48916e1e6f551ad61a055
DIFF: https://github.com/llvm/llvm-project/commit/68e5614b42823cc1eef48916e1e6f551ad61a055.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
index 9a47b4e11384..af19da0c5b6c 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
@@ -32,6 +32,14 @@ class FastUnwindTest : public ::testing::Test {
   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 @@ void FastUnwindTest::SetUp() {
   // 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 @@ TEST_F(FastUnwindTest, OneFrameStackTrace) {
   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) {


        


More information about the llvm-commits mailing list