This patch fixes bug 23800. 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.

http://reviews.llvm.org/D10838

Files:
  lib/CodeGen/CGExprScalar.cpp

Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1215,7 +1215,13 @@
           Value *LHS = nullptr, *RHS = nullptr;
           if (CurIdx == 0) {
             // insert into undef -> shuffle (src, undef)
-            Args.push_back(C);
+            // extractelement index can be any integer type
+            // shufflemask is only allowed to contain 32 bit integers
+            // make sure we can savely convert to 32 bit
+            assert(llvm::ConstantInt::isValueValidForType(CGF.Int32Ty,
+                                                          C->getZExtValue()) &&
+                   "Index operand too large for shufflevector mask!");
+            Args.push_back(Builder.getInt32(C->getZExtValue()));
             Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
 
             LHS = EI->getVectorOperand();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1215,7 +1215,13 @@
           Value *LHS = nullptr, *RHS = nullptr;
           if (CurIdx == 0) {
             // insert into undef -> shuffle (src, undef)
-            Args.push_back(C);
+            // extractelement index can be any integer type
+            // shufflemask is only allowed to contain 32 bit integers
+            // make sure we can savely convert to 32 bit
+            assert(llvm::ConstantInt::isValueValidForType(CGF.Int32Ty,
+                                                          C->getZExtValue()) &&
+                   "Index operand too large for shufflevector mask!");
+            Args.push_back(Builder.getInt32(C->getZExtValue()));
             Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty));
 
             LHS = EI->getVectorOperand();
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to