forked from OSchip/llvm-project
[CodeGen] Pass element type to EmitCheckedInBoundsGEP()
Same as for other GEP creation methods.
This commit is contained in:
parent
5653d127d7
commit
d930c3155c
|
@ -18023,7 +18023,7 @@ RValue CodeGenFunction::EmitBuiltinAlignTo(const CallExpr *E, bool AlignUp) {
|
||||||
if (getLangOpts().isSignedOverflowDefined())
|
if (getLangOpts().isSignedOverflowDefined())
|
||||||
Result = Builder.CreateGEP(Int8Ty, Base, Difference, "aligned_result");
|
Result = Builder.CreateGEP(Int8Ty, Base, Difference, "aligned_result");
|
||||||
else
|
else
|
||||||
Result = EmitCheckedInBoundsGEP(Base, Difference,
|
Result = EmitCheckedInBoundsGEP(Int8Ty, Base, Difference,
|
||||||
/*SignedIndices=*/true,
|
/*SignedIndices=*/true,
|
||||||
/*isSubtraction=*/!AlignUp,
|
/*isSubtraction=*/!AlignUp,
|
||||||
E->getExprLoc(), "aligned_result");
|
E->getExprLoc(), "aligned_result");
|
||||||
|
|
|
@ -3585,7 +3585,7 @@ static llvm::Value *emitArraySubscriptGEP(CodeGenFunction &CGF,
|
||||||
SourceLocation loc,
|
SourceLocation loc,
|
||||||
const llvm::Twine &name = "arrayidx") {
|
const llvm::Twine &name = "arrayidx") {
|
||||||
if (inbounds) {
|
if (inbounds) {
|
||||||
return CGF.EmitCheckedInBoundsGEP(ptr, indices, signedIndices,
|
return CGF.EmitCheckedInBoundsGEP(elemType, ptr, indices, signedIndices,
|
||||||
CodeGenFunction::NotSubtraction, loc,
|
CodeGenFunction::NotSubtraction, loc,
|
||||||
name);
|
name);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2631,12 +2631,12 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
||||||
= CGF.getContext().getAsVariableArrayType(type)) {
|
= CGF.getContext().getAsVariableArrayType(type)) {
|
||||||
llvm::Value *numElts = CGF.getVLASize(vla).NumElts;
|
llvm::Value *numElts = CGF.getVLASize(vla).NumElts;
|
||||||
if (!isInc) numElts = Builder.CreateNSWNeg(numElts, "vla.negsize");
|
if (!isInc) numElts = Builder.CreateNSWNeg(numElts, "vla.negsize");
|
||||||
|
llvm::Type *elemTy = value->getType()->getPointerElementType();
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined())
|
if (CGF.getLangOpts().isSignedOverflowDefined())
|
||||||
value = Builder.CreateGEP(value->getType()->getPointerElementType(),
|
value = Builder.CreateGEP(elemTy, value, numElts, "vla.inc");
|
||||||
value, numElts, "vla.inc");
|
|
||||||
else
|
else
|
||||||
value = CGF.EmitCheckedInBoundsGEP(
|
value = CGF.EmitCheckedInBoundsGEP(
|
||||||
value, numElts, /*SignedIndices=*/false, isSubtraction,
|
elemTy, value, numElts, /*SignedIndices=*/false, isSubtraction,
|
||||||
E->getExprLoc(), "vla.inc");
|
E->getExprLoc(), "vla.inc");
|
||||||
|
|
||||||
// Arithmetic on function pointers (!) is just +-1.
|
// Arithmetic on function pointers (!) is just +-1.
|
||||||
|
@ -2647,7 +2647,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined())
|
if (CGF.getLangOpts().isSignedOverflowDefined())
|
||||||
value = Builder.CreateGEP(CGF.Int8Ty, value, amt, "incdec.funcptr");
|
value = Builder.CreateGEP(CGF.Int8Ty, value, amt, "incdec.funcptr");
|
||||||
else
|
else
|
||||||
value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
|
value = CGF.EmitCheckedInBoundsGEP(CGF.Int8Ty, value, amt,
|
||||||
|
/*SignedIndices=*/false,
|
||||||
isSubtraction, E->getExprLoc(),
|
isSubtraction, E->getExprLoc(),
|
||||||
"incdec.funcptr");
|
"incdec.funcptr");
|
||||||
value = Builder.CreateBitCast(value, input->getType());
|
value = Builder.CreateBitCast(value, input->getType());
|
||||||
|
@ -2655,13 +2656,13 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
||||||
// For everything else, we can just do a simple increment.
|
// For everything else, we can just do a simple increment.
|
||||||
} else {
|
} else {
|
||||||
llvm::Value *amt = Builder.getInt32(amount);
|
llvm::Value *amt = Builder.getInt32(amount);
|
||||||
|
llvm::Type *elemTy = value->getType()->getPointerElementType();
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined())
|
if (CGF.getLangOpts().isSignedOverflowDefined())
|
||||||
value = Builder.CreateGEP(value->getType()->getPointerElementType(),
|
value = Builder.CreateGEP(elemTy, value, amt, "incdec.ptr");
|
||||||
value, amt, "incdec.ptr");
|
|
||||||
else
|
else
|
||||||
value = CGF.EmitCheckedInBoundsGEP(value, amt, /*SignedIndices=*/false,
|
value = CGF.EmitCheckedInBoundsGEP(
|
||||||
isSubtraction, E->getExprLoc(),
|
elemTy, value, amt, /*SignedIndices=*/false, isSubtraction,
|
||||||
"incdec.ptr");
|
E->getExprLoc(), "incdec.ptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector increment/decrement.
|
// Vector increment/decrement.
|
||||||
|
@ -2771,8 +2772,8 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined())
|
if (CGF.getLangOpts().isSignedOverflowDefined())
|
||||||
value = Builder.CreateGEP(CGF.Int8Ty, value, sizeValue, "incdec.objptr");
|
value = Builder.CreateGEP(CGF.Int8Ty, value, sizeValue, "incdec.objptr");
|
||||||
else
|
else
|
||||||
value = CGF.EmitCheckedInBoundsGEP(value, sizeValue,
|
value = CGF.EmitCheckedInBoundsGEP(
|
||||||
/*SignedIndices=*/false, isSubtraction,
|
CGF.Int8Ty, value, sizeValue, /*SignedIndices=*/false, isSubtraction,
|
||||||
E->getExprLoc(), "incdec.objptr");
|
E->getExprLoc(), "incdec.objptr");
|
||||||
value = Builder.CreateBitCast(value, input->getType());
|
value = Builder.CreateBitCast(value, input->getType());
|
||||||
}
|
}
|
||||||
|
@ -3508,16 +3509,15 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
|
||||||
// GEP indexes are signed, and scaling an index isn't permitted to
|
// GEP indexes are signed, and scaling an index isn't permitted to
|
||||||
// signed-overflow, so we use the same semantics for our explicit
|
// signed-overflow, so we use the same semantics for our explicit
|
||||||
// multiply. We suppress this if overflow is not undefined behavior.
|
// multiply. We suppress this if overflow is not undefined behavior.
|
||||||
|
llvm::Type *elemTy = pointer->getType()->getPointerElementType();
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined()) {
|
if (CGF.getLangOpts().isSignedOverflowDefined()) {
|
||||||
index = CGF.Builder.CreateMul(index, numElements, "vla.index");
|
index = CGF.Builder.CreateMul(index, numElements, "vla.index");
|
||||||
pointer = CGF.Builder.CreateGEP(
|
pointer = CGF.Builder.CreateGEP(elemTy, pointer, index, "add.ptr");
|
||||||
pointer->getType()->getPointerElementType(), pointer, index,
|
|
||||||
"add.ptr");
|
|
||||||
} else {
|
} else {
|
||||||
index = CGF.Builder.CreateNSWMul(index, numElements, "vla.index");
|
index = CGF.Builder.CreateNSWMul(index, numElements, "vla.index");
|
||||||
pointer =
|
pointer = CGF.EmitCheckedInBoundsGEP(
|
||||||
CGF.EmitCheckedInBoundsGEP(pointer, index, isSigned, isSubtraction,
|
elemTy, pointer, index, isSigned, isSubtraction, op.E->getExprLoc(),
|
||||||
op.E->getExprLoc(), "add.ptr");
|
"add.ptr");
|
||||||
}
|
}
|
||||||
return pointer;
|
return pointer;
|
||||||
}
|
}
|
||||||
|
@ -3531,12 +3531,13 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
|
||||||
return CGF.Builder.CreateBitCast(result, pointer->getType());
|
return CGF.Builder.CreateBitCast(result, pointer->getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::Type *elemTy = pointer->getType()->getPointerElementType();
|
||||||
if (CGF.getLangOpts().isSignedOverflowDefined())
|
if (CGF.getLangOpts().isSignedOverflowDefined())
|
||||||
return CGF.Builder.CreateGEP(
|
return CGF.Builder.CreateGEP(elemTy, pointer, index, "add.ptr");
|
||||||
pointer->getType()->getPointerElementType(), pointer, index, "add.ptr");
|
|
||||||
|
|
||||||
return CGF.EmitCheckedInBoundsGEP(pointer, index, isSigned, isSubtraction,
|
return CGF.EmitCheckedInBoundsGEP(
|
||||||
op.E->getExprLoc(), "add.ptr");
|
elemTy, pointer, index, isSigned, isSubtraction, op.E->getExprLoc(),
|
||||||
|
"add.ptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct an fmuladd intrinsic to represent a fused mul-add of MulOp and
|
// Construct an fmuladd intrinsic to represent a fused mul-add of MulOp and
|
||||||
|
@ -5057,12 +5058,12 @@ static GEPOffsetAndOverflow EmitGEPOffsetInBytes(Value *BasePtr, Value *GEPVal,
|
||||||
}
|
}
|
||||||
|
|
||||||
Value *
|
Value *
|
||||||
CodeGenFunction::EmitCheckedInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
CodeGenFunction::EmitCheckedInBoundsGEP(llvm::Type *ElemTy, Value *Ptr,
|
||||||
|
ArrayRef<Value *> IdxList,
|
||||||
bool SignedIndices, bool IsSubtraction,
|
bool SignedIndices, bool IsSubtraction,
|
||||||
SourceLocation Loc, const Twine &Name) {
|
SourceLocation Loc, const Twine &Name) {
|
||||||
llvm::Type *PtrTy = Ptr->getType();
|
llvm::Type *PtrTy = Ptr->getType();
|
||||||
Value *GEPVal = Builder.CreateInBoundsGEP(
|
Value *GEPVal = Builder.CreateInBoundsGEP(ElemTy, Ptr, IdxList, Name);
|
||||||
PtrTy->getPointerElementType(), Ptr, IdxList, Name);
|
|
||||||
|
|
||||||
// If the pointer overflow sanitizer isn't enabled, do nothing.
|
// If the pointer overflow sanitizer isn't enabled, do nothing.
|
||||||
if (!SanOpts.has(SanitizerKind::PointerOverflow))
|
if (!SanOpts.has(SanitizerKind::PointerOverflow))
|
||||||
|
|
|
@ -6124,7 +6124,7 @@ llvm::Value *CGOpenMPRuntime::emitTaskReductionInit(
|
||||||
llvm::Value *Idxs[] = {llvm::ConstantInt::get(CGM.SizeTy, /*V=*/0),
|
llvm::Value *Idxs[] = {llvm::ConstantInt::get(CGM.SizeTy, /*V=*/0),
|
||||||
llvm::ConstantInt::get(CGM.SizeTy, Cnt)};
|
llvm::ConstantInt::get(CGM.SizeTy, Cnt)};
|
||||||
llvm::Value *GEP = CGF.EmitCheckedInBoundsGEP(
|
llvm::Value *GEP = CGF.EmitCheckedInBoundsGEP(
|
||||||
TaskRedInput.getPointer(), Idxs,
|
TaskRedInput.getElementType(), TaskRedInput.getPointer(), Idxs,
|
||||||
/*SignedIndices=*/false, /*IsSubtraction=*/false, Loc,
|
/*SignedIndices=*/false, /*IsSubtraction=*/false, Loc,
|
||||||
".rd_input.gep.");
|
".rd_input.gep.");
|
||||||
LValue ElemLVal = CGF.MakeNaturalAlignAddrLValue(GEP, RDType);
|
LValue ElemLVal = CGF.MakeNaturalAlignAddrLValue(GEP, RDType);
|
||||||
|
|
|
@ -4563,7 +4563,7 @@ public:
|
||||||
/// \p SignedIndices indicates whether any of the GEP indices are signed.
|
/// \p SignedIndices indicates whether any of the GEP indices are signed.
|
||||||
/// \p IsSubtraction indicates whether the expression used to form the GEP
|
/// \p IsSubtraction indicates whether the expression used to form the GEP
|
||||||
/// is a subtraction.
|
/// is a subtraction.
|
||||||
llvm::Value *EmitCheckedInBoundsGEP(llvm::Value *Ptr,
|
llvm::Value *EmitCheckedInBoundsGEP(llvm::Type *ElemTy, llvm::Value *Ptr,
|
||||||
ArrayRef<llvm::Value *> IdxList,
|
ArrayRef<llvm::Value *> IdxList,
|
||||||
bool SignedIndices,
|
bool SignedIndices,
|
||||||
bool IsSubtraction,
|
bool IsSubtraction,
|
||||||
|
|
Loading…
Reference in New Issue