[compiler-rt] b80affb - [NFC][sanitizer] Early return for empty StackTraces

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 12:54:08 PST 2021


Author: Vitaly Buka
Date: 2021-11-23T12:53:54-08:00
New Revision: b80affb8a1494560c83c6d2bf1164ff8fe031401

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

LOG: [NFC][sanitizer] Early return for empty StackTraces

Current callers should filter them out anyway,
but with this patch we don't need rely on that assumption.

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
index 74be6df8b8cf..9a727d28b6e6 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
@@ -17,6 +17,8 @@ namespace __sanitizer {
 static constexpr u32 kStackSizeBits = 16;
 
 StackStore::Id StackStore::Store(const StackTrace &trace) {
+  if (!trace.size && !trace.tag)
+    return 0;
   uptr *stack_trace = Alloc(trace.size + 1);
   CHECK_LT(trace.size, 1 << kStackSizeBits);
   *stack_trace = trace.size + (trace.tag << kStackSizeBits);
@@ -25,6 +27,8 @@ StackStore::Id StackStore::Store(const StackTrace &trace) {
 }
 
 StackTrace StackStore::Load(Id id) {
+  if (!id)
+    return {};
   const uptr *stack_trace = reinterpret_cast<const uptr *>(id);
   uptr size = *stack_trace & ((1 << kStackSizeBits) - 1);
   uptr tag = *stack_trace >> kStackSizeBits;


        


More information about the llvm-commits mailing list