<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 --- - LTO crashes after the linker ignores (r256003) not-imported DISubprograms that are otherwise used as a DIImportedEntity's entity."
   href="https://llvm.org/bugs/show_bug.cgi?id=26037">26037</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LTO crashes after the linker ignores (r256003) not-imported DISubprograms that are otherwise used as a DIImportedEntity's entity.
          </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>All
          </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>Linker
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>ahmed.bougacha@gmail.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>Since r256003, OSX bootstraps (e.g.,
<a href="http://lab.llvm.org:8080/green/job/llvm-stage2-cmake-RgLTO/">http://lab.llvm.org:8080/green/job/llvm-stage2-cmake-RgLTO/</a>) have been crashing
with assertion failures. I think the issue is reducible to:

 $ cat a.cpp
namespace A { void a(); }
using A::a;

 $ cat main.cpp
int main() { return 0; }

 $ clang++ -flto -g3 a.cpp main.cpp
clang-3.8: error: unable to execute command: Segmentation fault: 11
clang-3.8: error: linker command failed due to signal (use -v to see
invocation)


Here, the `using' translates into a DIImportedEntity, which references an
otherwise not-imported DISubprogram, "A::a". findNeededSubprograms, introduced
by r256003, only looks at explicitly imported subprograms, which causes this
one to not be linked in.



Here's some more relevant details:

The failure is:

  Assertion failed: (Val && "isa<> used on a null pointer"), function doit,
file
/Users/buildslave/jenkins/sharedspace/phase1@2/llvm/include/llvm/Support/Casting.h,
line 95.

In:

    frame #3: 0x00000001034e0ad1 libLTO.dylib`__assert_rtn + 81
    frame #4: 0x0000000103511313
libLTO.dylib`llvm::DwarfCompileUnit::constructImportedEntityDIE(llvm::DIImportedEntity
const*) + 1075
    frame #5: 0x000000010351678e
libLTO.dylib`llvm::DwarfDebug::constructAndAddImportedEntityDIE(llvm::DwarfCompileUnit&,
llvm::DIImportedEntity const*) + 94
    frame #6: 0x0000000103515105 libLTO.dylib`llvm::DwarfDebug::beginModule() +
1333
    frame #7: 0x0000000103514b63
libLTO.dylib`llvm::DwarfDebug::DwarfDebug(llvm::AsmPrinter*, llvm::Module*) +
2275
    frame #8: 0x00000001034f0f68
libLTO.dylib`llvm::AsmPrinter::doInitialization(llvm::Module&) + 1496
    frame #9: 0x00000001033c513b
libLTO.dylib`llvm::FPPassManager::doInitialization(llvm::Module&) + 75
    frame #10: 0x00000001033c5560
libLTO.dylib`llvm::legacy::PassManagerImpl::run(llvm::Module&) + 816
    frame #11: 0x00000001038db37b libLTO.dylib`codegen(llvm::Module*,
llvm::raw_pwrite_stream&, llvm::Target const*, llvm::StringRef,
llvm::StringRef, llvm::TargetOptions const&, llvm::Reloc::Model,
llvm::CodeModel::Model, llvm::CodeGenOpt::Level,
llvm::TargetMachine::CodeGenFileType) + 315
    frame #12: 0x00000001038db043
libLTO.dylib`llvm::splitCodeGen(std::__1::unique_ptr<llvm::Module,
std::__1::default_delete<llvm::Module> >,
llvm::ArrayRef<llvm::raw_pwrite_stream*>, llvm::StringRef, llvm::StringRef,
llvm::TargetOptions const&, llvm::Reloc::Model, llvm::CodeModel::Model,
llvm::CodeGenOpt::Level, llvm::TargetMachine::CodeGenFileType) + 371
    frame #13: 0x000000010342dee2
libLTO.dylib`llvm::LTOCodeGenerator::compileOptimized(llvm::ArrayRef<llvm::raw_pwrite_stream*>)
+ 274
    frame #14: 0x000000010342dbd2
libLTO.dylib`llvm::LTOCodeGenerator::compileOptimizedToFile(char const**) + 354
    frame #15: 0x000000010342dfa3
libLTO.dylib`llvm::LTOCodeGenerator::compileOptimized() + 51
    frame #16: 0x000000010342e4c2
libLTO.dylib`llvm::LTOCodeGenerator::compile(bool, bool, bool, bool) + 50
    frame #17: 0x000000010280a1c0 libLTO.dylib`lto_codegen_compile + 64

caused by:

frame #10: 0x000000010ae1838e
libLTO.dylib`llvm::DwarfCompileUnit::constructImportedEntityDIE(this=0x00000002c1e033e0,
Module=0x000000027e3f2ee8) + 174 at DwarfCompileUnit.cpp:646
   643       insertDIE(Module, IMDie);
   644       DIE *EntityDie;
   645       auto *Entity = resolve(Module->getEntity());
-> 646       if (auto *NS = dyn_cast<DINamespace>(Entity))
   647         EntityDie = getOrCreateNameSpace(NS);
   648       else if (auto *M = dyn_cast<DIModule>(Entity))
   649         EntityDie = getOrCreateModule(M);
(lldb) p Entity
(llvm::DINode *) $0 = 0x0000000000000000

In the relevant .bc (MIRParser.cpp.o), we have:

!97361 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !90731, line: 56)

!90731 = distinct !DISubprogram(name: "isspace", linkageName: "_Z7isspacei",
scope: !90732, file: !90732, line: 267, type: !90733, isLocal: false,
isDefinition: true, scopeLine: 268, flags: DIFlagPrototyped, isOptimized: true,
variables: !90735)


But the entity just disappeared:

(lldb) p ({ for (auto *IE : CUNode->getImportedEntities()) { IE->dump(); } })
<0x10f104628> = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
<0x1006f8568>, entity: <0x1024d3658>, line: 48)
<0x10f104668> = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
<0x1006f8568>, entity: <0x10230bef8>, line: 49)
[..]
<0x10f115968> = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
<0x1006f8568>, entity: <0x10f115920>, line: 55)
<0x27e3f2ee8> = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
<0x1006f8568>, line: 56)
<0x10f115b88> = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
<0x1006f8568>, entity: <0x10f115b40>, line: 57)
[..]


whereas:
$ llvm-dis lib/CodeGen/MIRParser/CMakeFiles/LLVMMIRParser.dir/MIRParser.cpp.o
-o - | grep '!DIImportedEntity'

!97055 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !2714, line: 48)
!97056 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !1454, line: 49)
!97057 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !97058, line: 53)
[..]
!97359 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !97360, line: 55)
!97361 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !90731, line: 56)
!97362 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !1038,
entity: !97363, line: 57)
[..]</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>