summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2015-08-02 15:28:10 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2015-08-02 15:28:10 +0000
commit4034b9f0b932c7e8c47a18fe1ef7d43e273e2913 (patch)
tree1950dc3e2b31fe83f60f6b4ffbf718623fb013c5 /clang/lib/CodeGen
parent87368fdd3064ac1ec5bedc8461b470af374e0534 (diff)
downloadbcm5719-llvm-4034b9f0b932c7e8c47a18fe1ef7d43e273e2913.tar.gz
bcm5719-llvm-4034b9f0b932c7e8c47a18fe1ef7d43e273e2913.zip
Fix invalid shufflevector operands
This patch fixes bug 23800 ( https://llvm.org/bugs/show_bug.cgi?id=23800#c2 ). There existed a case where the index operand from extractelement was directly used to create a shufflevector mask. Since the index can be of any integral type but the mask must only contain 32 bit integers a 64 bit index operand led to an assertion error later on. Committed on behalf of mpflanzer (Moritz Pflanzer) Differential Revision: http://reviews.llvm.org/D10838 llvm-svn: 243851
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index f3e48362130..195c7a4678f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1162,6 +1162,16 @@ static llvm::Constant *getMaskElt(llvm::ShuffleVectorInst *SVI, unsigned Idx,
return llvm::ConstantInt::get(I32Ty, Off+MV);
}
+static llvm::Constant *getAsInt32(llvm::ConstantInt *C, llvm::Type *I32Ty) {
+ if (C->getBitWidth() != 32) {
+ assert(llvm::ConstantInt::isValueValidForType(I32Ty,
+ C->getZExtValue()) &&
+ "Index operand too large for shufflevector mask!");
+ return llvm::ConstantInt::get(I32Ty, C->getZExtValue());
+ }
+ return C;
+}
+
Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
bool Ignore = TestAndClearIgnoreResultAssign();
(void)Ignore;
@@ -1212,7 +1222,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) {
Value *LHS = nullptr, *RHS = nullptr;
if (CurIdx == 0) {
// insert into undef -> shuffle (src, undef)
- Args.push_back(C);
+ // shufflemask must use an i32
+ Args.push_back(getAsInt32(C, CGF.Int32Ty));
Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
LHS = EI->getVectorOperand();
OpenPOWER on IntegriCloud