<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 --- - [globalopt] Crash after dropping user that still has debug value"
   href="https://llvm.org/bugs/show_bug.cgi?id=26786">26786</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[globalopt] Crash after dropping user that still has debug value
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mattias.v.eriksson@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=15965" name="attach_15965" title="Reduced input file with crash in globalopt">attachment 15965</a> <a href="attachment.cgi?id=15965&action=edit" title="Reduced input file with crash in globalopt">[details]</a></span>
Reduced input file with crash in globalopt

With the attached file running:

opt -globalopt -o /dev/null bugpoint-reduced-simplified.ll

crashes like this:
opt: ../include/llvm/Support/Casting.h:81: static bool
llvm::isa_impl_cl<llvm::BasicBlock, llvm::Value *>::doit(const From *) [To =
llvm::BasicBlock, From = llvm::Value *]: Assertion `Val && "isa<> used on a
null pointer"' failed.
0  opt             0x00000000023c542e
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
1  opt             0x00000000023c5839
2  opt             0x00000000023c4143 llvm::sys::RunSignalHandlers() + 131
3  opt             0x00000000023c5c7f
4  libpthread.so.0 0x00007f88d8f5e340
5  libc.so.6       0x00007f88d8186cc9 gsignal + 57
6  libc.so.6       0x00007f88d818a0d8 abort + 328
7  libc.so.6       0x00007f88d817fb86
8  libc.so.6       0x00007f88d817fc32
9  opt             0x0000000000ea11ae
10 opt             0x0000000000ea1158
11 opt             0x0000000000ea1132
12 opt             0x0000000000ea10d5
13 opt             0x0000000001937277
llvm::ValueEnumerator::EnumerateValue(llvm::Value const*) + 471
14 opt             0x000000000193789d
llvm::ValueEnumerator::EnumerateMetadata(llvm::Metadata const*) + 301
15 opt             0x000000000193638e
llvm::ValueEnumerator::ValueEnumerator(llvm::Module const&, bool) + 2702
16 opt             0x0000000001909052
17 opt             0x0000000001908bff llvm::WriteBitcodeToFile(llvm::Module
const*, llvm::raw_ostream&, bool, bool) + 335
18 opt             0x0000000001908a90
19 opt             0x0000000001dca9e1
20 opt             0x0000000001dca4db
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 347
21 opt             0x0000000001dcaf21
llvm::legacy::PassManager::run(llvm::Module&) + 33
22 opt             0x000000000091f2ec main + 8588
23 libc.so.6       0x00007f88d8171ec5 __libc_start_main + 245
24 opt             0x00000000008f3748
Stack dump:
0.      Program arguments: build-master/bin/opt -globalopt -o /dev/null
bugpoint-reduced-simplified.ll 
1.      Running pass 'Bitcode Writer' on module
'bugpoint-reduced-simplified.ll'.
Aborted


I have been debugging this for a while and found that globalopt tries to
extract the bitcast from:

  store i16 0, i16* bitcast (i16** @a.1 to i16*), align 8, !dbg !11

This bitcast also exists in debug info:

  tail call void @llvm.dbg.value(metadata i16* bitcast (i16** @a.1 to i16*),
i64 0, metadata !1, metadata !9), !dbg !10

In makeAllConstantUsesInstructions(Constant *C) dropAllReferences is called on
the bitcast expression and this seems to break the instruction with the
llvm.dbg.value</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>