[llvm-branch-commits] [NFC][asan] Re-use ErrorGeneric::shadow_val (PR #195684)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon May 4 09:30:06 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

<details>
<summary>Changes</summary>

This requires change in ErrorGeneric constructor, to now we skip partial
shadow only if next one has a better value.

Before shadow_val was either `0x[a-f].` or 0.
Now it may be partial granule as well.

However it's NFC as  `0 < shadow_val < ASAN_SHADOW_GRANULARITY` does not
affect reporting outside of `CheckPoisonRecords`.


---
Full diff: https://github.com/llvm/llvm-project/pull/195684.diff


1 Files Affected:

- (modified) compiler-rt/lib/asan/asan_errors.cpp (+8-21) 


``````````diff
diff --git a/compiler-rt/lib/asan/asan_errors.cpp b/compiler-rt/lib/asan/asan_errors.cpp
index 7b59c6c860bee..802c838ee5307 100644
--- a/compiler-rt/lib/asan/asan_errors.cpp
+++ b/compiler-rt/lib/asan/asan_errors.cpp
@@ -482,7 +482,8 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, uptr sp_, uptr addr,
       if (*shadow_addr == 0 && access_size > ASAN_SHADOW_GRANULARITY)
         shadow_addr++;
       // If we are in the partial right redzone, look at the next shadow byte.
-      if (*shadow_addr > 0 && *shadow_addr < 128) shadow_addr++;
+      if (*shadow_addr > 0 && *shadow_addr < 128 && shadow_addr[1] >= 128)
+        shadow_addr++;
       bool far_from_bounds = false;
       shadow_val = *shadow_addr;
       int bug_type_score = 0;
@@ -648,24 +649,6 @@ static void PrintShadowMemoryForAddress(uptr addr) {
 }
 
 static void CheckPoisonRecords(uptr addr) {
-  if (!AddrIsInMem(addr))
-    return;
-
-  const u8* shadow_addr = (const u8*)MemToShadow(addr);
-  u8 shadow_val = shadow_addr[0];
-  // If we are in the partial right redzone, look at the next shadow byte.
-  if (shadow_val > 0 && shadow_val < ASAN_SHADOW_GRANULARITY) {
-    u8 shadow_next = shadow_addr[1];
-    if (shadow_next >= ASAN_SHADOW_GRANULARITY)
-      shadow_val = shadow_next;
-  }
-
-  if (shadow_val != kAsanUserPoisonedMemoryMagic &&
-      shadow_val != kAsanContiguousContainerOOBMagic &&
-      shadow_val >= ASAN_SHADOW_GRANULARITY) {
-    return;
-  }
-
   Printf("\n");
 
   if (flags()->poison_history_size <= 0) {
@@ -714,8 +697,12 @@ void ErrorGeneric::Print() {
   ReportErrorSummary(bug_descr, &stack);
   PrintShadowMemoryForAddress(addr);
 
-  // This is an experimental flag, hence we don't make a special handler.
-  CheckPoisonRecords(addr);
+  // This is an experimental feature, hence we don't make a special handler.
+  if (shadow_val == kAsanUserPoisonedMemoryMagic ||
+      shadow_val == kAsanContiguousContainerOOBMagic ||
+      (shadow_val > 0 && shadow_val < ASAN_SHADOW_GRANULARITY)) {
+    CheckPoisonRecords(addr);
+  }
 }
 
 }  // namespace __asan

``````````

</details>


https://github.com/llvm/llvm-project/pull/195684


More information about the llvm-branch-commits mailing list