[llvm] [llvm-profdata] Emit error when counter value is greater than 2^56. (PR #69513)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 04:41:19 PDT 2023


================
@@ -676,8 +679,14 @@ Error RawInstrProfReader<IntPtrT>::readRawCounts(
       // A value of zero signifies the block is covered.
       Record.Counts.push_back(*Ptr == 0 ? 1 : 0);
     } else {
-      const auto *CounterValue = reinterpret_cast<const uint64_t *>(Ptr);
-      Record.Counts.push_back(swap(*CounterValue));
+      uint64_t CounterValue = swap(*reinterpret_cast<const uint64_t *>(Ptr));
+      if (CounterValue > MaxCounterValue)
+        return error(instrprof_error::malformed,
+                     ("counter value " + Twine(CounterValue) +
+                      " is greater than " + Twine(MaxCounterValue))
+                         .str());
----------------
zmodem wrote:

+1, "counter value 72057594037927936 is greater than 72057594037927935" isn't as helpful as "counter value 72057594037927936 suggests corrupted profile data"

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


More information about the llvm-commits mailing list