[lld] r374332 - Make nullptr check more robust
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 05:51:42 PDT 2019
Thank you!
On Thu, Oct 10, 2019 at 3:38 PM Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: ruiu
> Date: Thu Oct 10 05:41:08 2019
> New Revision: 374332
>
> URL: http://llvm.org/viewvc/llvm-project?rev=374332&view=rev
> Log:
> 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.
>
> Modified:
> lld/trunk/ELF/Target.cpp
>
> Modified: lld/trunk/ELF/Target.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=374332&r1=374331&r2=374332&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Target.cpp (original)
> +++ lld/trunk/ELF/Target.cpp Thu Oct 10 05:41:08 2019
> @@ -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 {};
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list