[llvm-commits] [llvm] r147946 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll

Duncan Sands baldrick at free.fr
Wed Jan 11 04:20:09 PST 2012


Author: baldrick
Date: Wed Jan 11 06:20:08 2012
New Revision: 147946

URL: http://llvm.org/viewvc/llvm-project?rev=147946&view=rev
Log:
Don't try to create a GEP when the pointee type is unsized (such GEPs
are invalid).  Fixes a crash on array1.C from the GCC testsuite when
compiled with dragonegg.

Added:
    llvm/trunk/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll
Modified:
    llvm/trunk/lib/VMCore/ConstantFold.cpp

Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=147946&r1=147945&r2=147946&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Wed Jan 11 06:20:08 2012
@@ -104,7 +104,8 @@
   // the first element.  If so, return the appropriate GEP instruction.
   if (PointerType *PTy = dyn_cast<PointerType>(V->getType()))
     if (PointerType *DPTy = dyn_cast<PointerType>(DestTy))
-      if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
+      if (PTy->getAddressSpace() == DPTy->getAddressSpace()
+          && DPTy->getElementType()->isSized()) {
         SmallVector<Value*, 8> IdxList;
         Value *Zero =
           Constant::getNullValue(Type::getInt32Ty(DPTy->getContext()));

Added: llvm/trunk/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll?rev=147946&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2012-01-11-OpaqueBitcastCrash.ll Wed Jan 11 06:20:08 2012
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -disable-output
+
+%opaque_struct = type opaque
+
+ at G = external global [0 x %opaque_struct]
+
+declare void @foo(%opaque_struct*)
+
+define void @bar() {
+  call void @foo(%opaque_struct* bitcast ([0 x %opaque_struct]* @G to %opaque_struct*))
+  ret void
+}





More information about the llvm-commits mailing list