diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2009-06-06 19:09:26 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2009-06-06 19:09:26 +0000 |
| commit | 07bbeca4062451701482e6dceb141790bc2f42a9 (patch) | |
| tree | 1223766bb6ffb79aaeea68744564a23e5b20758f /clang/lib | |
| parent | 5f75ff84b76b0267cb2066096c0eb287b66fdaf8 (diff) | |
| download | bcm5719-llvm-07bbeca4062451701482e6dceb141790bc2f42a9.tar.gz bcm5719-llvm-07bbeca4062451701482e6dceb141790bc2f42a9.zip | |
PR4339: make sure to properly extend/trunc the index of a vector element
insert/extract; the relevant instructions are defined to take only an
i32.
llvm-svn: 73005
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index c5f23879d1c..c52e6bd0c5c 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -843,14 +843,16 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { // The index must always be an integer, which is not an aggregate. Emit it. llvm::Value *Idx = EmitScalarExpr(E->getIdx()); - + QualType IdxTy = E->getIdx()->getType(); + bool IdxSigned = IdxTy->isSignedIntegerType(); + // If the base is a vector type, then we are forming a vector element lvalue // with this subscript. if (E->getBase()->getType()->isVectorType()) { // Emit the vector as an lvalue to get its address. LValue LHS = EmitLValue(E->getBase()); assert(LHS.isSimple() && "Can only subscript lvalue vectors here!"); - // FIXME: This should properly sign/zero/extend or truncate Idx to i32. + Idx = Builder.CreateIntCast(Idx, llvm::Type::Int32Ty, IdxSigned, "vidx"); return LValue::MakeVectorElt(LHS.getAddress(), Idx, E->getBase()->getType().getCVRQualifiers()); } @@ -859,8 +861,6 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { llvm::Value *Base = EmitScalarExpr(E->getBase()); // Extend or truncate the index type to 32 or 64-bits. - QualType IdxTy = E->getIdx()->getType(); - bool IdxSigned = IdxTy->isSignedIntegerType(); unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); if (IdxBitwidth != LLVMPointerWidth) Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth), |

