[PATCH] D121284: [llvm-dwarfdump] Avoid possible div-by-zero in debug output

Dmitry Vassiliev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 04:47:20 PST 2022


slydiman created this revision.
slydiman added reviewers: serge-sans-paille, djtodoro, dexonsmith, MaskRay.
slydiman added a project: LLVM.
Herald added a reviewer: jhenderson.
Herald added a subscriber: cmtice.
Herald added a project: All.
slydiman requested review of this revision.
Herald added a subscriber: llvm-commits.

We didn't add a test because this bug only affected the debug output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121284

Files:
  llvm/tools/llvm-dwarfdump/Statistics.cpp


Index: llvm/tools/llvm-dwarfdump/Statistics.cpp
===================================================================
--- llvm/tools/llvm-dwarfdump/Statistics.cpp
+++ llvm/tools/llvm-dwarfdump/Statistics.cpp
@@ -1044,14 +1044,17 @@
                      LocStats.LocalVarNonEntryValLocStats);
   J.objectEnd();
   OS << '\n';
-  LLVM_DEBUG(llvm::dbgs() << "Total Availability: "
-                          << (int)std::round((VarParamWithLoc.Value * 100.0) /
+  LLVM_DEBUG(
+      llvm::dbgs() << "Total Availability: "
+                   << (VarParamTotal.Value
+                           ? (int)std::round((VarParamWithLoc.Value * 100.0) /
                                              VarParamTotal.Value)
-                          << "%\n";
-             llvm::dbgs() << "PC Ranges covered: "
-                          << (int)std::round(
-                                 (GlobalStats.ScopeBytesCovered.Value * 100.0) /
-                                 GlobalStats.ScopeBytes.Value)
-                          << "%\n");
+                           : 0)
+                   << "%\n";
+      llvm::dbgs() << "PC Ranges covered: "
+                   << (int)std::round(
+                          (GlobalStats.ScopeBytesCovered.Value * 100.0) /
+                          GlobalStats.ScopeBytes.Value)
+                   << "%\n");
   return true;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121284.414066.patch
Type: text/x-patch
Size: 1359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220309/9c52e824/attachment.bin>


More information about the llvm-commits mailing list