[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:30:07 PDT 2021
wenlei added inline comments.
================
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);
----------------
wlei wrote:
> wenlei wrote:
> > Before the loop, `RangeBegin <= RangeEnd` should be guaranteed, right? Would this look cleaner?
> >
> > ```
> > do {
> >
> > ...
> > } while (IP.advance() && IP.Address <= RangeEnd);
> >
> > ```
> Seems not guaranteed, see the comments:
> ```
> // Disjoint ranges may have range in the middle of two instr,
> // e.g. If Instr1 at Addr1, and Instr2 at Addr2, disjoint range
> // can be Addr1+1 to Addr2-1. We should ignore such range.
> if (IP.Address > RangeEnd)
> continue;
> ```
> or change to ?
> ```
> if (IP.Address > RangeEnd)
> continue;
> do {
>
> ...
> } while (IP.advance() && IP.Address <= RangeEnd);
>
> ```
Ok, I see. Yeah, that works. We could have `if (RangeStart > RangeEnd)` check before constructing the `IP`, and together with that comment.
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