diff options
author | Rui Ueyama <ruiu@google.com> | 2019-10-10 12:41:08 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2019-10-10 12:41:08 +0000 |
commit | 9adea6e4fae349564a946db22f8c5759567d30d1 (patch) | |
tree | 975e245d904ad465e9f6f4377839c9e6c4602453 | |
parent | 342b1b2e9b376835f17630d9697be4b78a019389 (diff) | |
download | bcm5719-llvm-9adea6e4fae349564a946db22f8c5759567d30d1.tar.gz bcm5719-llvm-9adea6e4fae349564a946db22f8c5759567d30d1.zip |
Make nullptr check more robust
The only condition that isecLoc becomes null is
Out::bufferStart == nullptr,
isec->getParent()->offset == 0, and
isec->outSecOff == 0.
We can check the first condition only once.
llvm-svn: 374332
-rw-r--r-- | lld/ELF/Target.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 0eab75c959c..024e0cfec27 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -91,18 +91,16 @@ TargetInfo *getTarget() { } template <class ELFT> static ErrorPlace getErrPlace(const uint8_t *loc) { + if (!Out::bufferStart) + return {}; + for (InputSectionBase *d : inputSections) { auto *isec = cast<InputSection>(d); if (!isec->getParent()) continue; uint8_t *isecLoc = Out::bufferStart + isec->getParent()->offset + isec->outSecOff; - if (isecLoc > loc) - continue; - // isecLoc might be nullptr here, with isec->getSize() being non-zero. - // Adding these two together is not defined in C++. - if (loc < reinterpret_cast<uint8_t *>( - reinterpret_cast<std::uintptr_t>(isecLoc) + isec->getSize())) + if (isecLoc <= loc && loc < isecLoc + isec->getSize()) return {isec, isec->template getLocation<ELFT>(loc - isecLoc) + ": "}; } return {}; |