[llvm-branch-commits] [cfe-branch] r245077 - Merging r243851:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 14 11:08:55 PDT 2015


Author: hans
Date: Fri Aug 14 13:08:54 2015
New Revision: 245077

URL: http://llvm.org/viewvc/llvm-project?rev=245077&view=rev
Log:
Merging r243851:
------------------------------------------------------------------------
r243851 | rksimon | 2015-08-02 08:28:10 -0700 (Sun, 02 Aug 2015) | 7 lines

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
------------------------------------------------------------------------

Added:
    cfe/branches/release_37/test/CodeGenOpenCL/vector_shufflevector_valid.cl
      - copied unchanged from r243851, cfe/trunk/test/CodeGenOpenCL/vector_shufflevector_valid.cl
Modified:
    cfe/branches/release_37/   (props changed)
    cfe/branches/release_37/lib/CodeGen/CGExprScalar.cpp

Propchange: cfe/branches/release_37/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 14 13:08:54 2015
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:242244,242285,242293,242297,242313,242382,242422,242499,242574,242600,242660,242662,242667,242678,242766,242854,242905,242973,243018,243048,243085,243098,243101,243105,243144,243153,243196,243206,243277,243280,243285,243289,243343,243417,243463,243538,243594,243642-243644,243945-243950,243964,244000,244719,244794
+/cfe/trunk:242244,242285,242293,242297,242313,242382,242422,242499,242574,242600,242660,242662,242667,242678,242766,242854,242905,242973,243018,243048,243085,243098,243101,243105,243144,243153,243196,243206,243277,243280,243285,243289,243343,243417,243463,243538,243594,243642-243644,243851,243945-243950,243964,244000,244719,244794
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_37/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_37/lib/CodeGen/CGExprScalar.cpp?rev=245077&r1=245076&r2=245077&view=diff
==============================================================================
--- cfe/branches/release_37/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/branches/release_37/lib/CodeGen/CGExprScalar.cpp Fri Aug 14 13:08:54 2015
@@ -1166,6 +1166,16 @@ static llvm::Constant *getMaskElt(llvm::
   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;
@@ -1216,7 +1226,8 @@ Value *ScalarExprEmitter::VisitInitListE
           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();




More information about the llvm-branch-commits mailing list