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

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 14:33:01 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());
----------------
MatzeB wrote:

Maybe hint to the user why this is an error condition?
```suggestion
        return error(instrprof_error::malformed,
                     ("counter value " + Twine(CounterValue) +
                      " is greater than " + Twine(MaxCounterValue) + " (unreasonably large)")
                         .str());
```

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


More information about the llvm-commits mailing list