[PATCH] D109217: [NOT FOR COMMIT] [llvm-dwarfdump] Fix unsigned overflow when calculating stats

Djordje Todorovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 6 02:01:43 PDT 2021


djtodoro added inline comments.


================
Comment at: llvm/tools/llvm-dwarfdump/Statistics.cpp:380-381
     GlobalStats.ScopeBytesCovered += ScopeBytesCovered;
+    assert(GlobalStats.ScopeBytesCovered <= UINT64_MAX &&
+           "ScopeBytesCovered - overflow");
     GlobalStats.ScopeBytes += BytesInScope;
----------------
dblaikie wrote:
> Orlando wrote:
> > I think this assert should come before the assignment and be something like this to catch a value that would "overflow" by wrapping:
> > `assert(GlobalStats.ScopeBytesCovered + ScopeBytesCovered >= GlobalStats.ScopeBytesCovered &&  "ScopeBytesCovered - overflow");`
> > Otherwise I don't think this assertion will ever catch anything, since all uint64_t values are <= UINT64_MAX.
> > 
> Yep! I think the more general assert probably looks like this:
> ```
> assert(x <= max - y)
> x += y;
> ```
Oh yes, thanks



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109217/new/

https://reviews.llvm.org/D109217



More information about the llvm-commits mailing list