[PATCH] D113238: [llvm-profgen] Fix index out of bounds error while using ip.advance

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 22:08:39 PDT 2021


wenlei added inline comments.


================
Comment at: llvm/tools/llvm-profgen/ProfileGenerator.cpp:358
       for (auto &R : FuncI.second.Ranges) {
-        Ranges[{R.first, R.second}] += 0;
+        Ranges[{R.first, R.second - 1}] += 0;
       }
----------------
So this is fixing a separate bug? And ranges end is actually `endOffset` + 1? If that's the case, some comments for `RangesTy Ranges` would be helpful.


================
Comment at: llvm/tools/llvm-profgen/ProfileGenerator.cpp:388
     // can be Addr1+1 to Addr2-1. We should ignore such range.
     while (IP.Address <= RangeEnd) {
       uint64_t Offset = Binary->virtualAddrToOffset(IP.Address);
----------------
Before the loop, `RangeBegin <= RangeEnd` should be guaranteed, right? Would this look cleaner?

```
do {

  ...
} while (IP.advance() && IP.Address <= RangeEnd);

```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113238



More information about the llvm-commits mailing list