diff options
author | Chris Lattner <sabre@nondot.org> | 2010-06-26 22:40:46 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-06-26 22:40:46 +0000 |
commit | a4d94ab50ff3164bcbf4709a92a98e06c23a7459 (patch) | |
tree | e569f4446b9aeed107c28ad5960c300406f7bd51 | |
parent | 640d3267228415328c0feb2bcc35757230ab4db7 (diff) |
minor cleanup: don't emit the base of an array subscript until after
we're done diddling around with the index stuff. Use a cheaper type
comparison.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106963 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 2c7ea39d8b..706bf09a7f 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1335,19 +1335,15 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { E->getBase()->getType().getCVRQualifiers()); } - // The base must be a pointer, which is not an aggregate. Emit it. - llvm::Value *Base = EmitScalarExpr(E->getBase()); - // Extend or truncate the index type to 32 or 64-bits. - unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); - if (IdxBitwidth != LLVMPointerWidth) + if (!Idx->getType()->isIntegerTy(LLVMPointerWidth)) Idx = Builder.CreateIntCast(Idx, - llvm::IntegerType::get(VMContext, LLVMPointerWidth), + llvm::IntegerType::get(VMContext, LLVMPointerWidth), IdxSigned, "idxprom"); - + // FIXME: As llvm implements the object size checking, this can come out. if (CatchUndefined) { - if (const ImplicitCastExpr *ICE=dyn_cast<ImplicitCastExpr>(E->getBase())) { + if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E->getBase())){ if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) { if (ICE->getCastKind() == CastExpr::CK_ArrayToPointerDecay) { if (const ConstantArrayType *CAT @@ -1364,6 +1360,9 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { } } + // The base must be a pointer, which is not an aggregate. Emit it. + llvm::Value *Base = EmitScalarExpr(E->getBase()); + // We know that the pointer points to a type of the correct size, unless the // size is a VLA or Objective-C interface. llvm::Value *Address = 0; |