Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion `member->getDeclContext() == nominal && "Added member to the wrong context"' failed when using CXX interop #65646

Open
natinusala opened this issue May 4, 2023 · 0 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift clang importer Area → compiler: The clang importer compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software swift 5.9 type checker Area → compiler: Semantic analysis

Comments

@natinusala
Copy link

Description
When trying to import RmlUi from Swift using CXX interop, compilation crashes with the following error:

error: compile command failed due to signal 6 (use -v to see invocation)
swift-frontend: /home/build-user/swift/lib/AST/DeclContext.cpp:980: void swift::IterableDeclContext::addMember(swift::Decl *, swift::Decl *, bool): Assertion `member->getDeclContext() == nominal && "Added member to the wrong context"' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend -frontend -c -primary-file /home/natinusala/RmlKit/Sources/RmlKitDemo/main.swift -emit-dependencies-path /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug/RmlKitDemo.build/main.d -emit-reference-dependencies-path /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug/RmlKitDemo.build/main.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -cxx-interoperability-mode=swift-5.9 -I /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug -I /usr/local/include/RmlUi -color-diagnostics -enable-testing -g -module-cache-path /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-driver -entry-point-function-name RmlKitDemo_main -empty-abi-descriptor -plugin-path /home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/lib/swift/host/plugins -plugin-path /home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/local/lib/swift/host/plugins -resource-dir /home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/home/natinusala/RmlKit/Sources/RmlUi/module.modulemap -Xcc -fPIC -module-name RmlKitDemo -o /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug/RmlKitDemo.build/main.swift.o -index-store-path /home/natinusala/RmlKit/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.      Swift version 5.9-dev (LLVM 7d8e26e27470723, Swift 8597eca85f3b074)
2.      Compiling with the current language version
3.      While evaluating request AllMembersRequest(__ObjC.(file).Rml.PropertyIdSet)
 #0 0x000055689ad9fbd3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x6f72bd3)
 #1 0x000055689ad9d8fe llvm::sys::RunSignalHandlers() (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x6f708fe)
 #2 0x000055689ad9ff3a SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f9285966520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f92859baa7c __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x00007f92859baa7c __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x00007f92859baa7c pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x00007f9285966476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f928594c7f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x00007f928594c71b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#10 0x00007f928595de96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005568964caef6 swift::IterableDeclContext::addMember(swift::Decl*, swift::Decl*, bool) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x269def6)
#12 0x00005568961b51a9 swift::ClangImporter::Implementation::loadAllMembersOfRecordDecl(swift::NominalTypeDecl*, clang::RecordDecl const*) crtstuff.c:0:0
#13 0x00005568961b591a swift::ClangImporter::Implementation::loadAllMembers(swift::Decl*, unsigned long) crtstuff.c:0:0
#14 0x00005568964ca7c0 swift::IterableDeclContext::loadAllMembers() const (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x269d7c0)
#15 0x00005568964ca6b9 swift::IterableDeclContext::getMembers() const (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x269d6b9)
#16 0x0000556895f3a0af evaluateMembersRequest(swift::IterableDeclContext*, (anonymous namespace)::MembersRequestKind) TypeCheckDecl.cpp:0:0
#17 0x00005568964d3b94 llvm::Expected<swift::AllMembersRequest::OutputType> swift::Evaluator::getResultUncached<swift::AllMembersRequest>(swift::AllMembersRequest const&) crtstuff.c:0:0
#18 0x00005568964d389b llvm::Expected<swift::AllMembersRequest::OutputType> swift::Evaluator::getResultCached<swift::AllMembersRequest, (void*)0>(swift::AllMembersRequest const&) crtstuff.c:0:0
#19 0x00005568964cacad swift::AllMembersRequest::OutputType swift::evaluateOrDefault<swift::AllMembersRequest>(swift::Evaluator&, swift::AllMembersRequest, swift::AllMembersRequest::OutputType) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x269dcad)
#20 0x00005568964cac5f swift::IterableDeclContext::getAllMembers() const (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x269dc5f)
#21 0x00005568963531a6 (anonymous namespace)::PrintAST::printMembersOfDecl(swift::Decl*, bool, bool, bool, bool)::$_96::operator()(swift::IterableDeclContext*) const ASTPrinter.cpp:0:0
#22 0x000055689635075d (anonymous namespace)::PrintAST::printMembersOfDecl(swift::Decl*, bool, bool, bool, bool) ASTPrinter.cpp:0:0
#23 0x000055689634ebbf swift::ASTVisitor<(anonymous namespace)::PrintAST, void, void, void, void, void, void>::visit(swift::Decl*) ASTPrinter.cpp:0:0
#24 0x0000556896345cc0 (anonymous namespace)::PrintAST::visit(swift::Decl*) ASTPrinter.cpp:0:0
#25 0x00005568963509ff (anonymous namespace)::PrintAST::printMembersOfDecl(swift::Decl*, bool, bool, bool, bool) ASTPrinter.cpp:0:0
#26 0x000055689634ebbf swift::ASTVisitor<(anonymous namespace)::PrintAST, void, void, void, void, void, void>::visit(swift::Decl*) ASTPrinter.cpp:0:0
#27 0x0000556896345cc0 (anonymous namespace)::PrintAST::visit(swift::Decl*) ASTPrinter.cpp:0:0
#28 0x0000556896345815 swift::Decl::print(swift::ASTPrinter&, swift::PrintOptions const&) const (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x2518815)
#29 0x00005568959ab695 printModuleInterfaceDecl(swift::Decl*, swift::ASTPrinter&, swift::PrintOptions&, bool, llvm::StringRef) ModuleInterfacePrinting.cpp:0:0
#30 0x00005568959a7b08 swift::ide::printModuleInterface(swift::ModuleDecl*, llvm::ArrayRef<llvm::StringRef>, swift::OptionSet<swift::ide::ModuleTraversal, unsigned int>, swift::ASTPrinter&, swift::PrintOptions const&, bool) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x1b7ab08)
#31 0x00005568959b4428 void llvm::function_ref<void ()>::callback_fn<swift::ide::printSymbolicSwiftClangModuleInterface(swift::ModuleDecl*, swift::ASTPrinter&, clang::Module const*)::$_11>(long) ModuleInterfacePrinting.cpp:0:0
#32 0x00005568961641b5 swift::ClangImporter::withSymbolicFeatureEnabled(llvm::function_ref<void ()>) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x23371b5)
#33 0x00005568959a9d6f swift::ide::printSymbolicSwiftClangModuleInterface(swift::ModuleDecl*, swift::ASTPrinter&, clang::Module const*) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0x1b7cd6f)
#34 0x0000556894d913cb emitSymbolicInterfaceForClangModule(swift::ClangModuleUnit*, swift::ModuleDecl*, clang::Module const*, llvm::StringRef, clang::CompilerInstance const&, swift::DiagnosticEngine&) IndexRecord.cpp:0:0
#35 0x0000556894d8ee38 addModuleDependencies(llvm::ArrayRef<swift::ImportedModule>, llvm::StringRef, bool, bool, bool, bool, llvm::StringRef, clang::CompilerInstance const&, swift::DiagnosticEngine&, clang::index::IndexUnitWriter&, (anonymous namespace)::StringScratchSpace&, swift::PathRemapper const&, swift::SourceFile*) IndexRecord.cpp:0:0
#36 0x0000556894d8e162 recordSourceFileUnit(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, bool, bool, llvm::StringRef, llvm::ArrayRef<clang::FileEntry const*>, clang::CompilerInstance const&, swift::PathRemapper const&, swift::DiagnosticEngine&) IndexRecord.cpp:0:0
#37 0x0000556894d8dd69 swift::index::indexAndRecord(swift::SourceFile*, llvm::StringRef, llvm::StringRef, bool, bool, bool, bool, bool, llvm::StringRef, swift::DependencyTracker const&, swift::PathRemapper const&) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0xf60d69)
#38 0x0000556894bc382b emitIndexDataForSourceFile(swift::SourceFile*, swift::CompilerInstance const&) FrontendTool.cpp:0:0
#39 0x0000556894bc17ac performEndOfPipelineActions(swift::CompilerInstance&) FrontendTool.cpp:0:0
#40 0x0000556894bbf3ba generateCode(swift::CompilerInstance&, llvm::StringRef, llvm::Module*, llvm::GlobalVariable*) FrontendTool.cpp:0:0
#41 0x0000556894bba41e performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#42 0x0000556894bb912b swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0xd8c12b)
#43 0x0000556894bced85 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#44 0x0000556894bbc3c9 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#45 0x0000556894bbb0f5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0xd8e0f5)
#46 0x0000556894a19b45 swift::mainEntry(int, char const**) (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0xbecb45)
#47 0x00007f928594dd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#48 0x00007f928594de40 call_init ./csu/../csu/libc-start.c:128:20
#49 0x00007f928594de40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#50 0x0000556894a19295 _start (/home/natinusala/.swiftenv/versions/5.9-DEVELOPMENT-SNAPSHOT-2023-05-01-a/usr/bin/swift-frontend+0xbec295)

It seems to come from this header file.

Steps to reproduce

  • Build and install RmlUi
  • Put the following rmlui.pc somewhere in plg-config path
prefix=/usr/local
exec_prefix=${prefix}
includedir=/usr/local/include/RmlUi
libdir=/usr/local/lib

Name: RmlUi
Description: RmlUi - The HTML/CSS User Interface library evolved
Version: master
URL: https://mikke89.github.io/RmlUiDoc/
Libs: -L${libdir} -lRmlCore -lRmlDebugger
Libs.private:  -lrt -lm -ldl
Cflags: -I${includedir}

Expected behavior
The compiler does not crash.

Environment

  • Swift version 5.9-dev (LLVM 7d8e26e27470723, Swift 8597eca)
    Target: x86_64-unknown-linux-gnu
  • Deployment target: x86_64-unknown-linux-gnu
@natinusala natinusala added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 4, 2023
@AnthonyLatsis AnthonyLatsis added c++ interop Feature: Interoperability with C++ compiler The Swift compiler itself type checker Area → compiler: Semantic analysis crash Bug: A crash, i.e., an abnormal termination of software swift 5.9 c++ to swift Feature → c++ interop: c++ to swift clang importer Area → compiler: The clang importer and removed triage needed This issue needs more specific labels labels May 4, 2023
@hyp hyp self-assigned this May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift clang importer Area → compiler: The clang importer compiler The Swift compiler itself crash Bug: A crash, i.e., an abnormal termination of software swift 5.9 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants