forked from OSchip/llvm-project
Use the inbounds variant of getelementptr for common pointer arithmetic.
llvm-svn: 78756
This commit is contained in:
parent
76733748e1
commit
43b4484f87
|
@ -889,7 +889,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
|
|||
Idx = Builder.CreateUDiv(Idx,
|
||||
llvm::ConstantInt::get(Idx->getType(),
|
||||
BaseTypeSize));
|
||||
Address = Builder.CreateGEP(Base, Idx, "arrayidx");
|
||||
Address = Builder.CreateInBoundsGEP(Base, Idx, "arrayidx");
|
||||
} else if (const ObjCInterfaceType *OIT =
|
||||
dyn_cast<ObjCInterfaceType>(E->getType())) {
|
||||
llvm::Value *InterfaceSize =
|
||||
|
@ -899,11 +899,11 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
|
|||
Idx = Builder.CreateMul(Idx, InterfaceSize);
|
||||
|
||||
llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
||||
Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy),
|
||||
Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy),
|
||||
Idx, "arrayidx");
|
||||
Address = Builder.CreateBitCast(Address, Base->getType());
|
||||
} else {
|
||||
Address = Builder.CreateGEP(Base, Idx, "arrayidx");
|
||||
Address = Builder.CreateInBoundsGEP(Base, Idx, "arrayidx");
|
||||
}
|
||||
|
||||
QualType T = E->getBase()->getType()->getPointeeType();
|
||||
|
|
|
@ -724,7 +724,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
|
|||
LV = LValue::MakeAddr(lhs, ValTy.getCVRQualifiers(),
|
||||
CGF.getContext().getObjCGCAttrKind(ValTy));
|
||||
} else
|
||||
NextVal = Builder.CreateGEP(InVal, Inc, "ptrincdec");
|
||||
NextVal = Builder.CreateInBoundsGEP(InVal, Inc, "ptrincdec");
|
||||
} else {
|
||||
const llvm::Type *i8Ty =
|
||||
llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
|
||||
|
@ -1094,7 +1094,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
|
|||
return Builder.CreateBitCast(Res, Ptr->getType());
|
||||
}
|
||||
|
||||
return Builder.CreateGEP(Ptr, Idx, "add.ptr");
|
||||
return Builder.CreateInBoundsGEP(Ptr, Idx, "add.ptr");
|
||||
}
|
||||
|
||||
Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
|
||||
|
@ -1160,7 +1160,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
|
|||
return Builder.CreateBitCast(Res, Ops.LHS->getType());
|
||||
}
|
||||
|
||||
return Builder.CreateGEP(Ops.LHS, Idx, "sub.ptr");
|
||||
return Builder.CreateInBoundsGEP(Ops.LHS, Idx, "sub.ptr");
|
||||
} else {
|
||||
// pointer - pointer
|
||||
Value *LHS = Ops.LHS;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t &&
|
||||
// RUN: grep "call void @_ZN1AC1Ev" %t | count 1 &&
|
||||
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr (%.truct.A\* @a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
|
||||
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr inbounds (%.truct.A\* @a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
|
||||
|
||||
struct A {
|
||||
A();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// RUN: clang-cc -triple=x86_64-apple-darwin9 -emit-llvm %s -o %t &&
|
||||
// RUN: grep "call void @_ZN1AC1Ev" %t | count 1 &&
|
||||
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr (%.truct.A\* @_ZZ1fvE1a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
|
||||
// RUN: grep "call i32 @__cxa_atexit(void (i8\*)\* bitcast (void (%.truct.A\*)\* @_ZN1AD1Ev to void (i8\*)\*), i8\* getelementptr inbounds (%.truct.A\* @_ZZ1fvE1a, i32 0, i32 0), i8\* bitcast (i8\*\* @__dso_handle to i8\*))" %t | count 1
|
||||
|
||||
struct A {
|
||||
A();
|
||||
|
|
Loading…
Reference in New Issue