<div dir="ltr">Looks good, please submit.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 13, 2014 at 9:07 AM, Joey Gouly <span dir="ltr"><<a href="mailto:joey.gouly@gmail.com" target="_blank">joey.gouly@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">r205941 changed the logic, so that a cast happens *before* 'Result' is compared to 'AddrMode.BaseReg'.<br>

In the case that 'AddrMode.BaseReg' is nullptr, 'Result' will also be nullptr, so the cast causes an assertion.<br>
We should use dyn_cast_or_null here to check 'Result' is not null and it is an instruction.<br>
<br>
Bug found by Mats Petersson, and I reduced his IR to get a test case.<br>
<br>
Also r205941 didn't have a test case, so it'd be good to get one for that commit too.<br>
<br>
<a href="http://reviews.llvm.org/D3746" target="_blank">http://reviews.llvm.org/D3746</a><br>
<br>
Files:<br>
  lib/CodeGen/CodeGenPrepare.cpp<br>
  test/CodeGen/X86/codegen-prepare-crash.ll<br>
<br>
Index: lib/CodeGen/CodeGenPrepare.cpp<br>
===================================================================<br>
--- lib/CodeGen/CodeGenPrepare.cpp<br>
+++ lib/CodeGen/CodeGenPrepare.cpp<br>
@@ -2759,7 +2759,7 @@<br>
         // the original IR value was tossed in favor of a constant back when<br>
         // the AddrMode was created we need to bail out gracefully if widths<br>
         // do not match instead of extending it.<br>
-        Instruction *I = dyn_cast<Instruction>(Result);<br>
+        Instruction *I = dyn_cast_or_null<Instruction>(Result);<br>
         if (I && (Result != AddrMode.BaseReg))<br>
           I->eraseFromParent();<br>
         return false;<br>
Index: test/CodeGen/X86/codegen-prepare-crash.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/CodeGen/X86/codegen-prepare-crash.ll<br>
@@ -0,0 +1,14 @@<br>
+; RUN: llc < %s<br>
+target triple = "x86_64-unknown-linux-gnu"<br>
+<br>
+@g = external global [10 x i32]<br>
+<br>
+define void @f(i32 %u) {<br>
+  %1 = add i32 %u, 4<br>
+  br label %P.Proc8.exit<br>
+<br>
+P.Proc8.exit:<br>
+  %valueindex35.i = getelementptr [10 x i32]* @g, i32 0, i32 %1<br>
+  store i32 %u, i32* %valueindex35.i<br>
+  ret void<br>
+}<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>