diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h @@ -229,10 +229,10 @@ uptr local_stack; \ uptr sp = (uptr)&local_stack -#define GET_CURRENT_PC() \ - ({ \ - this_pc: \ - StackTrace::GetNextInstructionPc((uptr) && this_pc); \ +#define GET_CURRENT_PC() \ + ({ \ + this_pc##__LINE__ \ + : StackTrace::GetNextInstructionPc((uptr) && this_pc##__LINE__); \ }) #endif // SANITIZER_STACKTRACE_H 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 @@ -269,6 +269,15 @@ EXPECT_EQ(1U, stack.size); EXPECT_EQ(pc, stack.trace[0]); EXPECT_EQ(bp, stack.top_frame_bp); + pc = GET_CURRENT_PC(); + stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/0); + EXPECT_EQ(0U, stack.size); + // Ensure that GET_CURRENT_PC() macro can be used + // multiple times in a single function. + pc = GET_CURRENT_PC(); + stack.Unwind(pc, bp, nullptr, false, /*max_depth=*/1); + EXPECT_EQ(1U, stack.size); + EXPECT_EQ(pc, stack.trace[0]); } // Dummy implementation. This should never be called, but is required to link