<div dir="ltr">Ping</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 1:51 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Ping</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 20, 2015 at 11:35 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Wed, Jul 10, 2013 at 3:51 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: hfinkel<br>
Date: Wed Jul 10 17:51:01 2013<br>
New Revision: 186044<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=186044&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=186044&view=rev</a><br>
Log:<br>
Don't assert if we can't constant fold extract/insertvalue<br>
<br>
A non-constant-foldable static initializer expression containing insertvalue or<br>
extractvalue had been causing an assert:<br>
<br>
  Constants.cpp:1971: Assertion `FC && "ExtractValue constant expr couldn't be<br>
                                 folded!"' failed.<br>
<br>
Now we report a more-sensible "Unsupported expression in static initializer"<br>
error instead.<br>
<br>
Fixes PR15417.<br>
<br>
Added:<br>
    llvm/trunk/test/Other/nonconst-static-ev.ll<br>
    llvm/trunk/test/Other/nonconst-static-iv.ll<br></blockquote></span><div><br>*casts Necromancy*<br><br>So in case it interests you, these .ll files crash llvm-as. <br><br><div>$ ninja llvm-as && ./bin/llvm-as ../../../../../../src/test/CodeGen/X86/nonconst-static-iv.ll -o /dev/null</div><div>ninja: no work to do.</div><div>Unknown binary instruction!</div><div>UNREACHABLE executed at lib/Bitcode/Writer/BitcodeWriter.cpp:84!</div><div>#0 0x7cce3e llvm::sys::PrintStackTrace(llvm::raw_ostream&) lib/Support/Unix/Signals.inc:436:15</div><div>#1 0x7cdd89 PrintStackTraceSignalHandler(void*) lib/Support/Unix/Signals.inc:495:1</div><div>#2 0x7ce069 SignalHandler(int) lib/Support/Unix/Signals.inc:210:62</div><div>#3 0x7fc2ba2e6340 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10340)</div><div>#4 0x7fc2b9a28cc9 gsignal /build/buildd/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0</div><div>#5 0x7fc2b9a2c0d8 abort /build/buildd/eglibc-2.19/stdlib/abort.c:91:0</div><div>#6 0x78dad0 LLVMInstallFatalErrorHandler lib/Support/ErrorHandling.cpp:132:0</div><div>#7 0x4725cc GetEncodedBinaryOpcode(unsigned int) lib/Bitcode/Writer/BitcodeWriter.cpp:86:27</div><div>#8 0x47184b WriteConstants(unsigned int, unsigned int, llvm::ValueEnumerator const&, llvm::BitstreamWriter&, bool) lib/Bitcode/Writer/BitcodeWriter.cpp:1530:28</div><div>#9 0x46e3db WriteModuleConstants(llvm::ValueEnumerator const&, llvm::BitstreamWriter&) lib/Bitcode/Writer/BitcodeWriter.cpp:1621:7</div><div>#10 0x469ecf WriteModule(llvm::Module const*, llvm::BitstreamWriter&, bool) lib/Bitcode/Writer/BitcodeWriter.cpp:2360:3</div><div>#11 0x469d37 llvm::WriteBitcodeToFile(llvm::Module const*, llvm::raw_ostream&, bool) lib/Bitcode/Writer/BitcodeWriter.cpp:2482:5</div><div>#12 0x406a27 WriteOutputFile(llvm::Module const*) llvm/src/tools/llvm-as/llvm-as.cpp:80:5</div><div>#13 0x406752 main llvm/src/tools/llvm-as/llvm-as.cpp:118:3</div><div>#14 0x7fc2b9a13ec5 __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:321:0</div><div>#15 0x4063e4 _start (/mnt/fast/dev/llvm/build/clang/debug/split/notypes/nostandalone/bin/llvm-as+0x4063e4)</div><div>Stack dump:</div><div>0.      Program arguments: ./bin/llvm-as ../../../../../../src/test/CodeGen/X86/nonconst-static-iv.ll -o /dev/null </div><div>Aborted</div> </div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Modified:<br>
    llvm/trunk/lib/IR/Constants.cpp<br>
<br>
Modified: llvm/trunk/lib/IR/Constants.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=186044&r1=186043&r2=186044&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=186044&r1=186043&r2=186044&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/Constants.cpp (original)<br>
+++ llvm/trunk/lib/IR/Constants.cpp Wed Jul 10 17:51:01 2013<br>
@@ -1954,14 +1954,22 @@ Constant *ConstantExpr::getShuffleVector<br>
<br>
 Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val,<br>
                                        ArrayRef<unsigned> Idxs) {<br>
+  assert(Agg->getType()->isFirstClassType() &&<br>
+         "Non-first-class type for constant insertvalue expression");<br>
+<br>
   assert(ExtractValueInst::getIndexedType(Agg->getType(),<br>
                                           Idxs) == Val->getType() &&<br>
          "insertvalue indices invalid!");<br>
-  assert(Agg->getType()->isFirstClassType() &&<br>
-         "Non-first-class type for constant insertvalue expression");<br>
-  Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs);<br>
-  assert(FC && "insertvalue constant expr couldn't be folded!");<br>
-  return FC;<br>
+  Type *ReqTy = Val->getType();<br>
+<br>
+  if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs))<br>
+    return FC;<br>
+<br>
+  Constant *ArgVec[] = { Agg, Val };<br>
+  const ExprMapKeyType Key(Instruction::InsertValue, ArgVec, 0, 0, Idxs);<br>
+<br>
+  LLVMContextImpl *pImpl = Agg->getContext().pImpl;<br>
+  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);<br>
 }<br>
<br>
 Constant *ConstantExpr::getExtractValue(Constant *Agg,<br>
@@ -1975,9 +1983,14 @@ Constant *ConstantExpr::getExtractValue(<br>
<br>
   assert(Agg->getType()->isFirstClassType() &&<br>
          "Non-first-class type for constant extractvalue expression");<br>
-  Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs);<br>
-  assert(FC && "ExtractValue constant expr couldn't be folded!");<br>
-  return FC;<br>
+  if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs))<br>
+    return FC;<br>
+<br>
+  Constant *ArgVec[] = { Agg };<br>
+  const ExprMapKeyType Key(Instruction::ExtractValue, ArgVec, 0, 0, Idxs);<br>
+<br>
+  LLVMContextImpl *pImpl = Agg->getContext().pImpl;<br>
+  return pImpl->ExprConstants.getOrCreate(ReqTy, Key);<br>
 }<br>
<br>
 Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) {<br>
<br>
Added: llvm/trunk/test/Other/nonconst-static-ev.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-ev.ll?rev=186044&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-ev.ll?rev=186044&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Other/nonconst-static-ev.ll (added)<br>
+++ llvm/trunk/test/Other/nonconst-static-ev.ll Wed Jul 10 17:51:01 2013<br>
@@ -0,0 +1,8 @@<br>
+; RUN: not llc < %s 2> %t<br>
+; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s<br>
+<br>
+@0 = global i8 extractvalue ([1 x i8] select (i1 ptrtoint (i32* @1 to i1), [1 x i8] [ i8 1 ], [1 x i8] [ i8 2 ]), 0)<br>
+@1 = external global i32<br>
+<br>
+; CHECK-ERRORS: Unsupported expression in static initializer: extractvalue<br>
+<br>
<br>
Added: llvm/trunk/test/Other/nonconst-static-iv.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-iv.ll?rev=186044&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/nonconst-static-iv.ll?rev=186044&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Other/nonconst-static-iv.ll (added)<br>
+++ llvm/trunk/test/Other/nonconst-static-iv.ll Wed Jul 10 17:51:01 2013<br>
@@ -0,0 +1,8 @@<br>
+; RUN: not llc < %s 2> %t<br>
+; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s<br>
+<br>
+@0 = global i8 insertvalue( { i8 } select (i1 ptrtoint (i32* @1 to i1), { i8 } { i8 1 }, { i8 } { i8 2 }), i8 0, 0)<br>
+@1 = external global i32<br>
+<br>
+; CHECK-ERRORS: Unsupported expression in static initializer: insertvalue<br>
+<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">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>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>