[compiler-rt] 5670ef4 - [NFC][hwasan] Extract a few BaseReport::Copy methods (#66682)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 19:30:30 PDT 2023


Author: Vitaly Buka
Date: 2023-09-19T19:29:33-07:00
New Revision: 5670ef44f81ee831216f84f708d517cc79fab516

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

LOG: [NFC][hwasan] Extract a few BaseReport::Copy methods (#66682)

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_report.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 969741d8564a0a4..0edfa7a53b369bf 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -390,21 +390,8 @@ class BaseReport {
     if (MemIsShadow(untagged_addr))
       return;
 
-    HwasanChunkView chunk = FindHeapChunkByAddress(untagged_addr);
-    heap.begin = chunk.Beg();
-    if (heap.begin) {
-      heap.size = chunk.ActualSize();
-      heap.from_small_heap = chunk.FromSmallHeap();
-      heap.is_allocated = chunk.IsAllocated();
-    }
-
-    hwasanThreadList().VisitAllLiveThreads([&](Thread *t) {
-      if (stack_allocations_count < ARRAY_SIZE(stack_allocations) &&
-          t->AddrIsInStack(untagged_addr)) {
-        stack_allocations[stack_allocations_count++].CopyFrom(t);
-      }
-    });
-
+    CopyHeapChunk();
+    CopyStackAllocations();
     candidate = FindBufferOverflowCandidate();
   }
 
@@ -423,6 +410,8 @@ class BaseReport {
     } heap;
   };
 
+  void CopyHeapChunk();
+  void CopyStackAllocations();
   OverflowCandidate FindBufferOverflowCandidate() const;
   void PrintAddressDescription() const;
   void PrintHeapOrGlobalCandidate() const;
@@ -447,6 +436,25 @@ class BaseReport {
   OverflowCandidate candidate;
 };
 
+void BaseReport::CopyHeapChunk() {
+  HwasanChunkView chunk = FindHeapChunkByAddress(untagged_addr);
+  heap.begin = chunk.Beg();
+  if (heap.begin) {
+    heap.size = chunk.ActualSize();
+    heap.from_small_heap = chunk.FromSmallHeap();
+    heap.is_allocated = chunk.IsAllocated();
+  }
+}
+
+void BaseReport::CopyStackAllocations() {
+  hwasanThreadList().VisitAllLiveThreads([&](Thread *t) {
+    if (stack_allocations_count < ARRAY_SIZE(stack_allocations) &&
+        t->AddrIsInStack(untagged_addr)) {
+      stack_allocations[stack_allocations_count++].CopyFrom(t);
+    }
+  });
+}
+
 BaseReport::OverflowCandidate BaseReport::FindBufferOverflowCandidate() const {
   // Check if this looks like a heap buffer overflow by scanning
   // the shadow left and right and looking for the first adjacent


        


More information about the llvm-commits mailing list