r371208 - [NFC][CodeGen][UBSan] EmitCheckedInBoundsGEP(): pass a vector to EmitCheck()

Roman Lebedev via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 07:19:04 PDT 2019


Author: lebedevri
Date: Fri Sep  6 07:19:04 2019
New Revision: 371208

URL: http://llvm.org/viewvc/llvm-project?rev=371208&view=rev
Log:
[NFC][CodeGen][UBSan] EmitCheckedInBoundsGEP(): pass a vector to EmitCheck()

Will be easier to add a new 'check' in a follow-up.

This was originally part of https://reviews.llvm.org/D67122

Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=371208&r1=371207&r2=371208&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Sep  6 07:19:04 2019
@@ -4662,6 +4662,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(
   auto *IntPtr = Builder.CreatePtrToInt(GEP->getPointerOperand(), IntPtrTy);
   auto *ComputedGEP = Builder.CreateAdd(IntPtr, EvaluatedGEP.TotalOffset);
 
+  llvm::SmallVector<std::pair<llvm::Value *, SanitizerMask>, 1> Checks;
+
   // The GEP is valid if:
   // 1) The total offset doesn't overflow, and
   // 2) The sign of the difference between the computed address and the base
@@ -4693,12 +4695,14 @@ CodeGenFunction::EmitCheckedInBoundsGEP(
     ValidGEP = Builder.CreateICmpULE(ComputedGEP, IntPtr);
   }
   ValidGEP = Builder.CreateAnd(ValidGEP, NoOffsetOverflow);
+  Checks.emplace_back(ValidGEP, SanitizerKind::PointerOverflow);
+
+  assert(!Checks.empty() && "Should have produced some checks.");
 
   llvm::Constant *StaticArgs[] = {EmitCheckSourceLocation(Loc)};
   // Pass the computed GEP to the runtime to avoid emitting poisoned arguments.
   llvm::Value *DynamicArgs[] = {IntPtr, ComputedGEP};
-  EmitCheck(std::make_pair(ValidGEP, SanitizerKind::PointerOverflow),
-            SanitizerHandler::PointerOverflow, StaticArgs, DynamicArgs);
+  EmitCheck(Checks, SanitizerHandler::PointerOverflow, StaticArgs, DynamicArgs);
 
   return GEPVal;
 }




More information about the cfe-commits mailing list