<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Running -jump-threading twice crashes opt in ValueHandleBase::ValueIsDeleted"
   href="https://llvm.org/bugs/show_bug.cgi?id=24517">24517</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Running -jump-threading twice crashes opt in ValueHandleBase::ValueIsDeleted
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>opt
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14751" name="attach_14751" title="Reproducer">attachment 14751</a> <a href="attachment.cgi?id=14751&action=edit" title="Reproducer">[details]</a></span>
Reproducer

Running

build-all/bin/opt -S ./bugpoint-reduced-simplified.ll -jump-threading
-jump-threading

on the attached bugpoint-reduced ll-file ends with

While deleting: label %bb1
An asserting value handle still pointed to this value!
UNREACHABLE executed at ../lib/IR/Value.cpp:686!

It's on the second invocation of jump-threading that it breaks, when it calls
llvm::removeUnreachableBlocks:

0  opt             0x0000000001635faa
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 42
1  opt             0x0000000001635606 llvm::sys::RunSignalHandlers() + 54
2  opt             0x00000000016378fa
3  libpthread.so.0 0x00007f8c62e30340
4  libc.so.6       0x00007f8c62058cc9 gsignal + 57
5  libc.so.6       0x00007f8c6205c0d8 abort + 328
6  opt             0x00000000015f68fd llvm::llvm_unreachable_internal(char
const*, char const*, unsigned int) + 461
7  opt             0x00000000012b8e2b
llvm::ValueHandleBase::ValueIsDeleted(llvm::Value*) + 1051
8  opt             0x00000000012b879b llvm::Value::~Value() + 43
9  opt             0x000000000117abb9 llvm::BasicBlock::~BasicBlock() + 9
10 opt             0x000000000167281c
llvm::removeUnreachableBlocks(llvm::Function&) + 2940
11 opt             0x00000000014c1667
12 opt             0x0000000001288744
llvm::FPPassManager::runOnFunction(llvm::Function&) + 516
13 opt             0x000000000128898b
llvm::FPPassManager::runOnModule(llvm::Module&) + 43
14 opt             0x0000000001288e67
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 903
15 opt             0x0000000000605864 main + 8148
16 libc.so.6       0x00007f8c62043ec5 __libc_start_main + 245
17 opt             0x00000000005f6df2

The code looks like this when jump-threading is invoked the second time:

*** IR Dump Before Jump Threading ***
define void @fn1() {
.split.us:
  br label %bb2.us.us

bb2.us.us:                                        ; preds = %bb2.us.us,
%.split.us
  br label %bb2.us.us

bb1.us:                                           ; preds = %bb1.us
  br label %bb1.us

bb2.us4:                                          ; preds = %bb2.us4
  br label %bb2.us4

bb2:                                              ; preds = %bb1
  %_tmp3 = icmp slt i16 %_tmp18, 2
  br i1 %_tmp3, label %bb1, label %bb1

bb1:                                              ; preds = %bb2, %bb2
  %_tmp18 = load i16, i16* @c
  %_tmp20 = icmp ne i16 %_tmp18, 0
  br i1 %_tmp20, label %bb2, label %bb6

bb6:                                              ; preds = %bb1
  ret void
}

And when it tries to delete bb1 it crashes.</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>