swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.67k stars 10.38k forks source link

Crash with 2024-08-26/6.1 toolchain/C++ interop #76104

Closed mattwhiteside closed 2 months ago

mattwhiteside commented 3 months ago

Description

Trying to create a swift library that links in a C++ library.

Reproduction

I'm trying to compiling the following the C++ code, but extracted into a library:

https://github.com/smarr/SOMpp

The C++ library/code compiles ok on its own. Trying to compile a swift library that links it crashes, even when everything in the umbrella header is commented out.

I've specified the build settings for the C++ library via a Package.swift file (seemed much easier than doing it with Cmake).

Stack dump

Stack dump:
0.  Program arguments: <UserHomeDir>/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-26-a.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types <ProjectDir>/Swift_Sources/SOM_Swift_Lib.swift -target arm64-apple-macos15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -cxx-interoperability-mode=default -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Products/Debug -I /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Products/Debug/PackageFrameworks -F <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Products/Debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -suppress-warnings -swift-version 6 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -const-gather-protocols-file <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-experimental-feature OpaqueTypeErasure -empty-abi-descriptor -plugin-path <UserHomeDir>/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-26-a.xctoolchain/usr/lib/swift/host/plugins -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing#/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -validate-clang-modules-once -clang-build-session-file <UserHomeDir>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc <UserHomeDir>/code/software/swift/SOM_Swift/SOM_Swift.xcodeproj -resource-dir <UserHomeDir>/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-26-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir <UserHomeDir>/code/software/swift/SOM_Swift/SOM_Swift.xcodeproj -Xcc -fmodule-map-file=<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/GeneratedModuleMaps/SOM.modulemap -Xcc -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -Xcc -I<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/swift-overrides.hmap -Xcc -I<ProjectDir>/src/include -Xcc -I<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Products/Debug/include -Xcc -I<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/DerivedSources-normal/arm64 -Xcc -I<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/DerivedSources/arm64 -Xcc -I<UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name SOM_Swift_Lib -package-name sompp -frontend-parseable-output -disable-clang-spi -plugin-path <UserHomeDir>/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-26-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path <UserHomeDir>/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-08-26-a.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -emit-module-doc-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib.swiftdoc -emit-module-source-info-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib.swiftsourceinfo -emit-objc-header-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib-Swift.h -serialize-diagnostics-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib-master-emit-module.dia -emit-dependencies-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib-master-emit-module.d -parse-as-library -o <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib.swiftmodule -emit-abi-descriptor-path <UserHomeDir>/Library/Developer/Xcode/DerivedData/SOM_Swift-guhcnxuhnjailhgwgiwbjoyoqhnl/Build/Intermediates.noindex/SOM_Swift_Lib.build/Debug/SOM_Swift_Lib.build/Objects-normal/arm64/SOM_Swift_Lib.abi.json
1.  Apple Swift version 6.1-dev (LLVM 834570a7ffed2b3, Swift 5080628c0a92e1c)
2.  Compiling with the current language version
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for Darwin)
4.  While running pass #2548 SILModuleTransform "MandatorySILLinker".
5.  While deserializing SIL function "$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC"
6.  *** DESERIALIZATION FAILURE ***
*** If any module named here was modified in the SDK, please delete the ***
*** new swiftmodule files from the SDK and keep only swiftinterfaces.   ***
module '_errno', builder version '6.1(6.1)/Apple Swift version 6.1-dev (LLVM 834570a7ffed2b3, Swift 5080628c0a92e1c)', built from swiftinterface against SDK , resilient, loaded from '<UserHomeDir>/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/_errno-ILO6T5U61QXP.swiftmodule'
SILFunction type mismatch for '$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC': '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>' != '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>'

Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001058c8cb4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001058c7480 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001058c92fc SignalHandler(int) + 304
3  libsystem_platform.dylib 0x0000000190a20184 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001909e8f70 pthread_kill + 288
5  libsystem_c.dylib        0x00000001908f5908 abort + 128
6  swift-frontend           0x00000001011bcde4 swift::ModuleFileSharedCore::fatal(llvm::Error) const + 1224
7  swift-frontend           0x000000010115269c swift::ModuleFile::getSourceLoc() const + 0
8  swift-frontend           0x00000001011975b8 swift::SILDeserializer::readSILFunctionChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, swift::SILFunction*, llvm::StringRef, bool, bool) + 1896
9  swift-frontend           0x00000001011a813c swift::SILDeserializer::lookupSILFunction(swift::SILFunction*, bool) + 184
10 swift-frontend           0x00000001012485b0 swift::SerializedSILLoader::lookupSILFunction(swift::SILFunction*, bool) + 148
11 swift-frontend           0x00000001012806e0 swift::SILLinkerVisitor::process() + 500
12 swift-frontend           0x00000001012804bc swift::SILLinkerVisitor::processFunction(swift::SILFunction*) + 108
13 swift-frontend           0x00000001012fb330 swift::SILModule::linkFunction(swift::SILFunction*, swift::SILModule::LinkingMode) + 108
14 swift-frontend           0x0000000100f8e668 (anonymous namespace)::SILLinker::run() + 128
15 swift-frontend           0x0000000100e3a220 swift::SILPassManager::runModulePass(unsigned int) + 856
16 swift-frontend           0x0000000100e3c618 swift::SILPassManager::execute() + 624
17 swift-frontend           0x0000000100e36ea0 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 72
18 swift-frontend           0x0000000100e36e20 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 68
19 swift-frontend           0x0000000100e8786c swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
20 swift-frontend           0x0000000100e54100 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
21 swift-frontend           0x0000000100e3707c swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
22 swift-frontend           0x0000000100e69bac swift::runSILDiagnosticPasses(swift::SILModule&) + 192
23 swift-frontend           0x000000010064d854 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 80
24 swift-frontend           0x0000000100659180 swift::ExplicitModuleInterfaceBuilder::buildSwiftModuleFromInterface(llvm::StringRef, llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::StringRef) + 2360
25 swift-frontend           0x000000010065a798 std::__1::error_code llvm::function_ref<std::__1::error_code (swift::SubCompilerInstanceInfo&)>::callback_fn<swift::ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>)::$_3::operator()() const::'lambda'(swift::SubCompilerInstanceInfo&)>(long, swift::SubCompilerInstanceInfo&) + 208
26 swift-frontend           0x0000000100665900 swift::InterfaceSubContextDelegateImpl::runInSubCompilerInstance(llvm::StringRef, llvm::StringRef, llvm::StringRef, llvm::StringRef, swift::SourceLoc, bool, llvm::function_ref<std::__1::error_code (swift::SubCompilerInstanceInfo&)>) + 2380
27 swift-frontend           0x000000010065a52c void llvm::function_ref<void ()>::callback_fn<swift::ImplicitModuleInterfaceBuilder::buildSwiftModuleInternal(llvm::StringRef, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>*, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>)::$_3>(long) + 268
28 swift-frontend           0x000000010583ed04 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 164
29 swift-frontend           0x000000010583ee24 RunSafelyOnThread_Dispatch(void*) + 52
30 swift-frontend           0x000000010583ee4c void* llvm::thread::ThreadProxy<std::__1::tuple<void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*>>(void*) + 24
31 libsystem_pthread.dylib  0x00000001909e92e4 _pthread_start + 136
32 libsystem_pthread.dylib  0x00000001909e40fc thread_start + 8

Expected behavior

Compiler doesn't crash.

Environment

swift-DEVELOPMENT-SNAPSHOT-2024-08-26

I'm running this build via Xcode Version 16.0 beta 6 (16A5230g).

Additional information

No response

ebariaux commented 2 months ago

I'm experiencing the same crash / stack trace when trying to build the swift-cmake-examples/4_swift_macros at main · apple/swift-cmake-examples project.

Environment

swift-DEVELOPMENT-SNAPSHOT-2024-09-06 Building from command line on macOS Sonoma 14.6.1

Additional information

Build works OK when using the toolchain bundled with Xcode 15.4

ebariaux commented 2 months ago

FYI the crash I was experiencing is fixed with the swift-DEVELOPMENT-SNAPSHOT-2024-09-11-a version.

mattwhiteside commented 2 months ago

Thank you. Yes it's working now for me too.