[compiler-rt] r355242 - [NFC][Sanitizer] Replace last uses of old Unwind API

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 15:50:47 PST 2019


Author: yln
Date: Fri Mar  1 15:50:47 2019
New Revision: 355242

URL: http://llvm.org/viewvc/llvm-project?rev=355242&view=rev
Log:
[NFC][Sanitizer] Replace last uses of old Unwind API

Replace remaining uses of old Unwind API in unit tests.

Allows us to remove the old API and WillUseFastUnwind can be made
private.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D58754

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=355242&r1=355241&r2=355242&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Fri Mar  1 15:50:47 2019
@@ -139,6 +139,8 @@ struct BufferedStackTrace : public Stack
 
   BufferedStackTrace(const BufferedStackTrace &) = delete;
   void operator=(const BufferedStackTrace &) = delete;
+
+  friend class FastUnwindTest;
 };
 
 // Check if given pointer points into allocated stack area.

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc?rev=355242&r1=355241&r2=355242&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cc Fri Mar  1 15:50:47 2019
@@ -20,18 +20,15 @@ class FastUnwindTest : public ::testing:
  protected:
   virtual void SetUp();
   virtual void TearDown();
-  bool TryFastUnwind(uptr max_depth) {
-    if (!StackTrace::WillUseFastUnwind(true))
-      return false;
-    trace.Unwind(max_depth, start_pc, (uptr)&fake_stack[0], 0, fake_top,
-                 fake_bottom, true);
-    return true;
-  }
+
+  void UnwindFast();
 
   void *mapping;
   uhwptr *fake_stack;
   const uptr fake_stack_size = 10;
   uhwptr start_pc;
+
+  uhwptr fake_bp;
   uhwptr fake_top;
   uhwptr fake_bottom;
   BufferedStackTrace trace;
@@ -62,6 +59,7 @@ void FastUnwindTest::SetUp() {
   fake_top = (uhwptr)&fake_stack[fake_stack_size + 2];
   // Bottom is one slot before the start because UnwindFast uses >.
   fake_bottom = (uhwptr)mapping;
+  fake_bp = (uptr)&fake_stack[0];
   start_pc = PC(0);
 }
 
@@ -70,9 +68,14 @@ void FastUnwindTest::TearDown() {
   UnmapOrDie(mapping, 2 * ps);
 }
 
+#if SANITIZER_CAN_FAST_UNWIND
+
+void FastUnwindTest::UnwindFast() {
+  trace.UnwindFast(start_pc, fake_bp, fake_top, fake_bottom, kStackTraceMax);
+}
+
 TEST_F(FastUnwindTest, Basic) {
-  if (!TryFastUnwind(kStackTraceMax))
-    return;
+  UnwindFast();
   // Should get all on-stack retaddrs and start_pc.
   EXPECT_EQ(6U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
@@ -85,8 +88,7 @@ TEST_F(FastUnwindTest, Basic) {
 TEST_F(FastUnwindTest, FramePointerLoop) {
   // Make one fp point to itself.
   fake_stack[4] = (uhwptr)&fake_stack[4];
-  if (!TryFastUnwind(kStackTraceMax))
-    return;
+  UnwindFast();
   // Should get all on-stack retaddrs up to the 4th slot and start_pc.
   EXPECT_EQ(4U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
@@ -98,8 +100,7 @@ TEST_F(FastUnwindTest, FramePointerLoop)
 TEST_F(FastUnwindTest, MisalignedFramePointer) {
   // Make one fp misaligned.
   fake_stack[4] += 3;
-  if (!TryFastUnwind(kStackTraceMax))
-    return;
+  UnwindFast();
   // Should get all on-stack retaddrs up to the 4th slot and start_pc.
   EXPECT_EQ(4U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
@@ -109,16 +110,14 @@ TEST_F(FastUnwindTest, MisalignedFramePo
 }
 
 TEST_F(FastUnwindTest, OneFrameStackTrace) {
-  if (!TryFastUnwind(1))
-    return;
+  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);
 }
 
 TEST_F(FastUnwindTest, ZeroFramesStackTrace) {
-  if (!TryFastUnwind(0))
-    return;
+  trace.Unwind(start_pc, fake_bp, nullptr, true, 0);
   EXPECT_EQ(0U, trace.size);
   EXPECT_EQ(0U, trace.top_frame_bp);
 }
@@ -128,8 +127,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) {
   // current FP.
   fake_stack[0] = (uhwptr)&fake_stack[-50];
   fake_stack[1] = PC(1);
-  if (!TryFastUnwind(3))
-    return;
+  UnwindFast();
   EXPECT_EQ(2U, trace.size);
   EXPECT_EQ(PC(0), trace.trace[0]);
   EXPECT_EQ(PC(1), trace.trace[1]);
@@ -138,8 +136,7 @@ TEST_F(FastUnwindTest, FPBelowPrevFP) {
 TEST_F(FastUnwindTest, CloseToZeroFrame) {
   // Make one pc a NULL pointer.
   fake_stack[5] = 0x0;
-  if (!TryFastUnwind(kStackTraceMax))
-    return;
+  UnwindFast();
   // The stack should be truncated at the NULL pointer (and not include it).
   EXPECT_EQ(3U, trace.size);
   EXPECT_EQ(start_pc, trace.trace[0]);
@@ -148,16 +145,16 @@ TEST_F(FastUnwindTest, CloseToZeroFrame)
   }
 }
 
+#endif // SANITIZER_CAN_FAST_UNWIND
+
 TEST(SlowUnwindTest, ShortStackTrace) {
-  if (StackTrace::WillUseFastUnwind(false))
-    return;
   BufferedStackTrace stack;
   uptr pc = StackTrace::GetCurrentPc();
   uptr bp = GET_CURRENT_FRAME();
-  stack.Unwind(0, pc, bp, 0, 0, 0, false);
+  stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/0);
   EXPECT_EQ(0U, stack.size);
   EXPECT_EQ(0U, stack.top_frame_bp);
-  stack.Unwind(1, pc, bp, 0, 0, 0, false);
+  stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/1);
   EXPECT_EQ(1U, stack.size);
   EXPECT_EQ(pc, stack.trace[0]);
   EXPECT_EQ(bp, stack.top_frame_bp);




More information about the llvm-commits mailing list