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.

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@374332 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/ELF/Target.cpp b/ELF/Target.cpp
index 0eab75c..024e0cf 100644
--- a/ELF/Target.cpp
+++ b/ELF/Target.cpp
@@ -91,18 +91,16 @@
 }
 
 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 {};