[llvm-commits] PATCH: Fix crash in APInt.cpp

James Benton jbenton at vmware.com
Fri Jun 8 06:18:47 PDT 2012


Fixed the following crash in llvm::APInt::lshr when shiftAmt > BitWidth.
Added a test which causes this crash.

Program received signal SIGSEGV, Segmentation fault.
0x0000000000ff5c9d in llvm::APInt::lshr (this=0x7fffffffc880, shiftAmt=160)
     at /home/james/private_vmware/llvm/lib/Support/APInt.cpp:1173
1173                 (pVal[i+offset+1] << (APINT_BITS_PER_WORD - 
wordShift));


#0  0x0000000000ff5c9d in llvm::APInt::lshr (this=0x7fffffffc870, 
shiftAmt=160)
     at llvm/lib/Support/APInt.cpp:1173
#1  0x00000000009168d2 in (anonymous namespace)::DAGCombiner::visitAND 
(this=0x7fffffffcf90, N=0x181b3c0)
     at llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:2496
-------------- next part --------------
Index: lib/Support/APInt.cpp
===================================================================
--- lib/Support/APInt.cpp	(revision 158078)
+++ lib/Support/APInt.cpp	(working copy)
@@ -1135,7 +1135,7 @@
   // If all the bits were shifted out, the result is 0. This avoids issues
   // with shifting by the size of the integer type, which produces undefined
   // results. We define these "undefined results" to always be 0.
-  if (shiftAmt == BitWidth)
+  if (shiftAmt >= BitWidth)
     return APInt(BitWidth, 0);
 
   // If none of the bits are shifted out, the result is *this. This avoids
Index: test/CodeGen/Generic/2012-06-08-APIntCrash.ll
===================================================================
--- test/CodeGen/Generic/2012-06-08-APIntCrash.ll	(revision 0)
+++ test/CodeGen/Generic/2012-06-08-APIntCrash.ll	(revision 0)
@@ -0,0 +1,8 @@
+; RUN: llc < %s
+
+define <8 x i32> @test1(<8 x i32>* %ptr)
+{
+	%1 = load <8 x i32>* %ptr, align 32
+	%2 = and <8 x i32> %1, <i32 0, i32 0, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 -1>
+	ret <8 x i32> %2;
+}


More information about the llvm-commits mailing list