<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - lli crashes during optimization when a node references itself"
   href="https://bugs.llvm.org/show_bug.cgi?id=39957">39957</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lli crashes during optimization when a node references itself
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>lli
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jynelson@email.sc.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>lli (and only lli) crashes while optimizing a module where a node references
itself. llc properly notes that the module is invalid. clang generates machine
code without a warning. Strangely enough, if there's no optimization to be
done, lli does not crash, instead giving the proper warning.

▶️ cat bug.ll
declare i32 @puts(i8*)
@.true = constant [5 x i8] c"true\00"
@.false = constant [6 x i8] c"false\00"

define i32 @main() {
  %tmp15 = getelementptr [5 x i8], [5 x i8]* @.true, i32 0, i64 0
  %tmp16 = getelementptr [6 x i8], [6 x i8]* @.false, i32 0, i64 0
  %tmp17 = icmp ne i1 %tmp17, 0
  %tmp14 = select i1 %tmp17, i8* %tmp15, i8* %tmp16
  %unused_register12 = call i32 @puts (i8* %tmp14)
  ret i32 0
}

▶️ llc bug.ll
Only PHI nodes may reference their own value!
  %tmp17 = icmp ne i1 %tmp17, false
llc: bug.ll: error: input module is broken!

▶️ ./lli bug.ll
Stack dump:
0.      Program arguments: ./lli /home/joshua/Documents/Programming/lox/bug.ll 
1.      Running pass 'Function Pass Manager' on module
'/home/joshua/Documents/Programming/lox/bug.ll'.
2.      Running pass 'Machine Common Subexpression Elimination' on function
'@main'
#0 0x0000000000cf7934 PrintStackTraceSignalHandler(void*) (./lli+0xcf7934)
#1 0x0000000000cf595e llvm::sys::RunSignalHandlers() (./lli+0xcf595e)
#2 0x0000000000cf7af2 SignalHandler(int) (./lli+0xcf7af2)
#3 0x00007f527462e890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#4 0x0000000000715a96 (anonymous
namespace)::MachineCSE::runOnMachineFunction(llvm::MachineFunction&)
(./lli+0x715a96)
#5 0x00000000007307c9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
(./lli+0x7307c9)
#6 0x00000000009279d1 llvm::FPPassManager::runOnFunction(llvm::Function&)
(./lli+0x9279d1)
#7 0x0000000000927c03 llvm::FPPassManager::runOnModule(llvm::Module&)
(./lli+0x927c03)
#8 0x000000000092814e llvm::legacy::PassManagerImpl::run(llvm::Module&)
(./lli+0x92814e)
#9 0x00000000009ffa48 llvm::MCJIT::emitObject(llvm::Module*) (./lli+0x9ffa48)
#10 0x00000000009ffca4 llvm::MCJIT::generateCodeForModule(llvm::Module*)
(./lli+0x9ffca4)
#11 0x0000000000a0065e llvm::MCJIT::finalizeObject() (./lli+0xa0065e)
#12 0x00000000005c7235 main (./lli+0x5c7235)
#13 0x00007f5273501b97 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
#14 0x00000000005c4549 _start (./lli+0x5c4549)
Segmentation fault (core dumped)

▶️ ./lli --version
LLVM (<a href="http://llvm.org/">http://llvm.org/</a>):
  LLVM version 7.0.0
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake

▶️ cat <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Customize Bugzilla to have some LLVM flavah"
   href="show_bug.cgi?id=2">bug2</a>.ll
define i32 @main () {
  %tmp17 = icmp eq i32 %tmp17, 1
  ret i32 %tmp17
}

▶️ lli <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Customize Bugzilla to have some LLVM flavah"
   href="show_bug.cgi?id=2">bug2</a>.ll
lli: <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Customize Bugzilla to have some LLVM flavah"
   href="show_bug.cgi?id=2">bug2</a>.ll:2:3: error: instruction forward referenced with type 'i32'
  %tmp17 = icmp eq i32 %tmp17, 1
  ^</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>