[llvm] r208705 - [CGP] r205941 changed the logic, so that a cast happens *before* 'Result' is

Joey Gouly joey.gouly at gmail.com
Tue May 13 08:42:46 PDT 2014


Author: joey
Date: Tue May 13 10:42:45 2014
New Revision: 208705

URL: http://llvm.org/viewvc/llvm-project?rev=208705&view=rev
Log:
[CGP] r205941 changed the logic, so that a cast happens *before* 'Result' is
compared to 'AddrMode.BaseReg'. In the case that 'AddrMode.BaseReg' is
nullptr, 'Result' will also be nullptr, so the cast causes an assertion. We
should use dyn_cast_or_null here to check 'Result' is not null and it is an
instruction.

Bug found by Mats Petersson, and I reduced his IR to get a test case.

Added:
    llvm/trunk/test/CodeGen/X86/codegen-prepare-crash.ll
Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=208705&r1=208704&r2=208705&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Tue May 13 10:42:45 2014
@@ -2759,7 +2759,7 @@ bool CodeGenPrepare::OptimizeMemoryInst(
         // the original IR value was tossed in favor of a constant back when
         // the AddrMode was created we need to bail out gracefully if widths
         // do not match instead of extending it.
-        Instruction *I = dyn_cast<Instruction>(Result);
+        Instruction *I = dyn_cast_or_null<Instruction>(Result);
         if (I && (Result != AddrMode.BaseReg))
           I->eraseFromParent();
         return false;

Added: llvm/trunk/test/CodeGen/X86/codegen-prepare-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/codegen-prepare-crash.ll?rev=208705&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/codegen-prepare-crash.ll (added)
+++ llvm/trunk/test/CodeGen/X86/codegen-prepare-crash.ll Tue May 13 10:42:45 2014
@@ -0,0 +1,14 @@
+; RUN: llc < %s
+target triple = "x86_64-unknown-linux-gnu"
+
+ at g = external global [10 x i32]
+
+define void @f(i32 %u) {
+  %1 = add i32 %u, 4
+  br label %P.Proc8.exit
+
+P.Proc8.exit:
+  %valueindex35.i = getelementptr [10 x i32]* @g, i32 0, i32 %1
+  store i32 %u, i32* %valueindex35.i
+  ret void
+}





More information about the llvm-commits mailing list