[llvm-bugs] [Bug 37684] New: [LTO] llvm::Type* {anonymous}::TypeMapTy::get(llvm::Type*, llvm::SmallPtrSet<llvm::StructType*, 8u>&): Assertion `!(Pair.first != Ty && Pair.second == Ty) && "mapping to a source type"' failed.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 4 16:55:12 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37684

            Bug ID: 37684
           Summary: [LTO] llvm::Type*
                    {anonymous}::TypeMapTy::get(llvm::Type*,
                    llvm::SmallPtrSet<llvm::StructType*, 8u>&): Assertion
                    `!(Pair.first != Ty && Pair.second == Ty) && "mapping
                    to a source type"' failed.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Linker
          Assignee: unassignedbugs at nondot.org
          Reporter: vlad at tsyrklevich.net
                CC: kcc at google.com, llvm-bugs at lists.llvm.org,
                    peter at pcc.me.uk, tejohnson at google.com

The following test cases:
$ cat ClangRefactor.cpp.o.ll
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @c() !dbg !6 {
  unreachable
}
!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}
!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 1, !"ThinLTO", i32 0}
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,
retainedTypes: !4)
!3 = !DIFile(filename:
"/llvm/tools/clang/tools/clangrefactor/ClangRefactor.cpp", directory: "")
!4 = !{!5}
!5 = !DICompositeType(tag: DW_TAG_class_type, file: !3, flags: DIFlagFwdDecl,
identifier: "_ZTSN5clang17ObjCInterfaceDeclE")
!6 = distinct !DISubprogram(unit: !2)

$ cat ASTContext.cpp.o.ll
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%"class.clang::DiagnosticsEngine" = type {}
%"class.clang::ObjCCategoryDecl" = type {}
define %"class.clang::DiagnosticsEngine" @a() {
  unreachable
}
define i1 @b(%"class.clang::ObjCCategoryDecl"*) {
  unreachable
}
!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}
!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 1, !"ThinLTO", i32 0}
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3,
retainedTypes: !4)
!3 = !DIFile(filename: "/llvm/tools/clang/lib/AST/ASTContext.cpp", directory:
"")
!4 = !{!5, !8}
!5 = !DICompositeType(tag: DW_TAG_class_type, file: !3, templateParams: !6)
!6 = !{!7}
!7 = !DITemplateValueParameter(value: i1 (%"class.clang::ObjCCategoryDecl"*)*
@b)
!8 = !DICompositeType(tag: DW_TAG_structure_type, scope: !9)
!9 = !DISubroutineType(types: !10)
!10 = !{!11, !13}
!11 = !DICompositeType(tag: DW_TAG_class_type, scope: !12, file: !3)
!12 = distinct !DISubprogram(unit: !2)
!13 = !DICompositeType(tag: DW_TAG_array_type, vtableHolder: !14, identifier:
"_ZTSN5clang17ObjCInterfaceDeclE")
!14 = !DICompositeType(tag: DW_TAG_class_type, scope: !9, file: !3)

Hit the titled assertion when linked the following way:
$ opt -module-summary ASTContext.cpp.o.ll -o ASTContext.cpp.o
$ opt -module-summary ClangRefactor.cpp.o.ll -o ClangRefactor.cpp.o
$ llvm-lto2 run -o a ClangRefactor.cpp.o ASTContext.cpp.o -r
ClangRefactor.cpp.o,c,px -r ASTContext.cpp.o,a,px -r ASTContext.cpp.o,b,px

With stack trace:
#9 0x0000560b1b2ea432 (anonymous namespace)::TypeMapTy::get(llvm::Type*,
llvm::SmallPtrSet<llvm::StructType*, 8u>&) /llvm/lib/Linker/IRMover.cpp:246:0
#10 0x0000560b1b2ea645 (anonymous namespace)::TypeMapTy::get(llvm::Type*,
llvm::SmallPtrSet<llvm::StructType*, 8u>&) /llvm/lib/Linker/IRMover.cpp:284:0
#11 0x0000560b1b2ea13f (anonymous namespace)::TypeMapTy::get(llvm::Type*)
/llvm/lib/Linker/IRMover.cpp:232:0
#12 0x0000560b1b2e9f20 (anonymous
namespace)::TypeMapTy::linkDefinedTypeBodies()
/llvm/lib/Linker/IRMover.cpp:207:0
#13 0x0000560b1b2ec72e (anonymous namespace)::IRLinker::computeTypeMapping()
/llvm/lib/Linker/IRMover.cpp:739:0
#14 0x0000560b1b2eff09 (anonymous namespace)::IRLinker::run()
/llvm/lib/Linker/IRMover.cpp:1353:0
#15 0x0000560b1b2f0a2c llvm::IRMover::move(std::unique_ptr<llvm::Module,
std::default_delete<llvm::Module> >, llvm::ArrayRef<llvm::GlobalValue*>,
std::function<void (llvm::GlobalValue&, std::function<void
(llvm::GlobalValue&)>)>, bool) /llvm/lib/Linker/IRMover.cpp:1486:0
#16 0x0000560b1a867725
llvm::lto::LTO::linkRegularLTO(llvm::lto::LTO::RegularLTOState::AddedModule,
bool) /llvm/lib/LTO/LTO.cpp:720:0
#17 0x0000560b1a868217
llvm::lto::LTO::runRegularLTO(std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>)
/llvm/lib/LTO/LTO.cpp:830:0
#18 0x0000560b1a868000
llvm::lto::LTO::run(std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)>,
std::function<std::function<std::unique_ptr<llvm::lto::NativeObjectStream,
std::default_delete<llvm::lto::NativeObjectStream> > (unsigned int)> (unsigned
int, llvm::StringRef)>) /llvm/lib/LTO/LTO.cpp:817:0
#19 0x0000560b18e9d4c7 lld::elf::BitcodeCompiler::compile()
/llvm/tools/lld/ELF/LTO.cpp:237:0
#20 0x0000560b18ef94a7 void
lld::elf::SymbolTable::addCombinedLTOObject<llvm::object::ELFType<(llvm::support::endianness)1,
true> >() /llvm/tools/lld/ELF/SymbolTable.cpp:132:0
#21 0x0000560b18e0e340 void
lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)1,
true> >(llvm::opt::InputArgList&) /llvm/tools/lld/ELF/Driver.cpp:1272:0
#22 0x0000560b18dfdffe lld::elf::LinkerDriver::main(llvm::ArrayRef<char
const*>) /llvm/tools/lld/ELF/Driver.cpp:400:0
#23 0x0000560b18df9d1f lld::elf::link(llvm::ArrayRef<char const*>, bool,
llvm::raw_ostream&) /llvm/tools/lld/ELF/Driver.cpp:103:0
#24 0x0000560b18c5f466 main /llvm/tools/lld/tools/lld/lld.cpp:122:0

This is a reduced test case for the exception hit when trying to bootstrap LLVM
with regular LTO with ThinLTO summaries as per https://reviews.llvm.org/D34156

This bug is similar to https://bugs.llvm.org/show_bug.cgi?id=30799

I believe what's happening is that the debug info in ClangRefactor.cpp.o causes
the debug info from ASTContext.cpp.o to be loaded and since that includes a
DITemplateValueParameter that references the ObjCCategoryDecl type it is also
loaded into ClangRefactor.cpp.o and added to DstStructTypesSet.

ASTContext.cpp.o is linked next; however, the DiagnosticsEngine type is used
before ObjCCategoryDecl so it's added to the typemap first. It has the same
type as ObjCCategoryDecl so DstStructTypesSet.findNonOpaque() finds it and maps
DiagnosticsEngine -> ObjCCategoryDecl; however, ObjCCategoryDecl has not
actually been added to the type map yet. It's only in DstStructTypesSet. Once
TypeMapTy::get() is reached to find ObjCCategoryDecl the loop with the
assertion is reached because it appears as if it's a source type (e.g. there is
no ObjCCategoryDecl->ObjCCategoryDecl mapping?)

I have a simple patch I'm trying to self-host now.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180604/ef17baa3/attachment.html>


More information about the llvm-bugs mailing list