From f8efa958c2f3df5761d6927215f52f6bba62b788 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 6 Sep 2019 14:19:04 +0000 Subject: [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371208 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index fc5f07219b..77ec54d6cb 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -4662,6 +4662,8 @@ CodeGenFunction::EmitCheckedInBoundsGEP(Value *Ptr, ArrayRef IdxList, auto *IntPtr = Builder.CreatePtrToInt(GEP->getPointerOperand(), IntPtrTy); auto *ComputedGEP = Builder.CreateAdd(IntPtr, EvaluatedGEP.TotalOffset); + llvm::SmallVector, 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(Value *Ptr, ArrayRef IdxList, 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; } -- cgit v1.2.1