diff options
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 9067787f323..4a7171ebd85 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -799,8 +799,11 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { 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), + + // If Pointer width is less than 32 than extend to 32. + unsigned IdxValidWidth = (LLVMPointerWidth < 32 ) ? 32 : LLVMPointerWidth; + if (IdxBitwidth != IdxValidWidth) + Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(IdxValidWidth), IdxSigned, "idxprom"); // We know that the pointer points to a type of the correct size, unless the |