[compiler-rt] 72e14fb - [NFC][hwasan] Reduce nesting in function

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 15:29:28 PST 2024


Author: Vitaly Buka
Date: 2024-02-15T15:29:12-08:00
New Revision: 72e14fb33fa8f0c9b08b328367fb3abd1f7d1a49

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

LOG: [NFC][hwasan] Reduce nesting in function

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 5dfbd215d896b4..80763c2ada943c 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -218,63 +218,63 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
     uptr pc_mask = (1ULL << kRecordFPShift) - 1;
     uptr pc = record & pc_mask;
     FrameInfo frame;
-    if (Symbolizer::GetOrInit()->SymbolizeFrame(pc, &frame)) {
-      for (LocalInfo &local : frame.locals) {
-        if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset)
-          continue;
-        if (!(local.name && internal_strlen(local.name)) &&
-            !(local.function_name && internal_strlen(local.function_name)) &&
-            !(local.decl_file && internal_strlen(local.decl_file)))
-          continue;
-        tag_t obj_tag = base_tag ^ local.tag_offset;
-        if (obj_tag != addr_tag)
-          continue;
-        // Guess top bits of local variable from the faulting address, because
-        // we only store bits 4-19 of FP (bits 0-3 are guaranteed to be zero).
-        uptr local_beg = (fp + local.frame_offset) |
-                         (untagged_addr & ~(uptr(kRecordFPModulus) - 1));
-        uptr local_end = local_beg + local.size;
-
-        if (!found_local) {
-          Printf("\nPotentially referenced stack objects:\n");
-          found_local = true;
-        }
-
-        uptr offset;
-        const char *whence;
-        const char *cause;
-        if (local_beg <= untagged_addr && untagged_addr < local_end) {
-          offset = untagged_addr - local_beg;
-          whence = "inside";
-          cause = "use-after-scope";
-        } else if (untagged_addr >= local_end) {
-          offset = untagged_addr - local_end;
-          whence = "after";
-          cause = "stack-buffer-overflow";
-        } else {
-          offset = local_beg - untagged_addr;
-          whence = "before";
-          cause = "stack-buffer-overflow";
-        }
-        Decorator d;
-        Printf("%s", d.Error());
-        Printf("Cause: %s\n", cause);
-        Printf("%s", d.Default());
-        Printf("%s", d.Location());
-        StackTracePrinter::GetOrInit()->RenderSourceLocation(
-            &location, local.decl_file, local.decl_line, /* column= */ 0,
-            common_flags()->symbolize_vs_style,
-            common_flags()->strip_path_prefix);
-        Printf(
-            "%p is located %zd bytes %s a %zd-byte local variable %s [%p,%p) "
-            "in %s %s\n",
-            untagged_addr, offset, whence, local_end - local_beg, local.name,
-            local_beg, local_end, local.function_name, location.data());
-        location.clear();
-        Printf("%s\n", d.Default());
+    if (!Symbolizer::GetOrInit()->SymbolizeFrame(pc, &frame))
+      continue;
+    for (LocalInfo &local : frame.locals) {
+      if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset)
+        continue;
+      if (!(local.name && internal_strlen(local.name)) &&
+          !(local.function_name && internal_strlen(local.function_name)) &&
+          !(local.decl_file && internal_strlen(local.decl_file)))
+        continue;
+      tag_t obj_tag = base_tag ^ local.tag_offset;
+      if (obj_tag != addr_tag)
+        continue;
+      // Guess top bits of local variable from the faulting address, because
+      // we only store bits 4-19 of FP (bits 0-3 are guaranteed to be zero).
+      uptr local_beg = (fp + local.frame_offset) |
+                       (untagged_addr & ~(uptr(kRecordFPModulus) - 1));
+      uptr local_end = local_beg + local.size;
+
+      if (!found_local) {
+        Printf("\nPotentially referenced stack objects:\n");
+        found_local = true;
+      }
+
+      uptr offset;
+      const char *whence;
+      const char *cause;
+      if (local_beg <= untagged_addr && untagged_addr < local_end) {
+        offset = untagged_addr - local_beg;
+        whence = "inside";
+        cause = "use-after-scope";
+      } else if (untagged_addr >= local_end) {
+        offset = untagged_addr - local_end;
+        whence = "after";
+        cause = "stack-buffer-overflow";
+      } else {
+        offset = local_beg - untagged_addr;
+        whence = "before";
+        cause = "stack-buffer-overflow";
       }
-      frame.Clear();
+      Decorator d;
+      Printf("%s", d.Error());
+      Printf("Cause: %s\n", cause);
+      Printf("%s", d.Default());
+      Printf("%s", d.Location());
+      StackTracePrinter::GetOrInit()->RenderSourceLocation(
+          &location, local.decl_file, local.decl_line, /* column= */ 0,
+          common_flags()->symbolize_vs_style,
+          common_flags()->strip_path_prefix);
+      Printf(
+          "%p is located %zd bytes %s a %zd-byte local variable %s [%p,%p) "
+          "in %s %s\n",
+          untagged_addr, offset, whence, local_end - local_beg, local.name,
+          local_beg, local_end, local.function_name, location.data());
+      location.clear();
+      Printf("%s\n", d.Default());
     }
+    frame.Clear();
   }
 
   if (found_local)


        


More information about the llvm-commits mailing list