swiftlang / swift

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

5.10 build crash: While running pass SILModuleTransform "CrossModuleOptimization" #74649

Open sliemeobn opened 3 weeks ago

sliemeobn commented 3 weeks ago

Description

I ran into this when setting up a benchmarks package in this repo.

Building the target with swift build -c release works, but using the swift package benchmark plugin command fails with a build error (full command below)

1.      Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for Elementary)
4.      While running pass #116648 SILModuleTransform "CrossModuleOptimization".

Reproduction

Bechmarks package in this repo Run swift package benchmark

Stack dump

0  swift-frontend           0x0000000109ca7f3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109ca70f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109ca8544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x0000000187b03584 _sigtramp + 56
4  swift-frontend           0x0000000104e20fb4 swift::SILCloner<(anonymous namespace)::InstructionVisitor>::doesOpTupleDisappear(swift::CanTypeWrapper<swift::TupleType>) + 300
5  swift-frontend           0x0000000104e1b89c (anonymous namespace)::InstructionVisitor::makeTypesUsableFromInline(swift::SILInstruction*, (anonymous namespace)::CrossModuleOptimization&) + 4276
6  swift-frontend           0x0000000104e18fb0 (anonymous namespace)::CrossModuleOptimization::serializeFunction(swift::SILFunction*, llvm::DenseMap<swift::SILFunction*, bool, llvm::DenseMapInfo<swift::SILFunction*, void>, llvm::detail::DenseMapPair<swift::SILFunction*, bool>> const&) + 228
7  swift-frontend           0x0000000104e187f8 (anonymous namespace)::CrossModuleOptimizationPass::run() + 468
8  swift-frontend           0x0000000104fe0978 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 16476
9  swift-frontend           0x0000000105019354 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
10 swift-frontend           0x0000000104ffd184 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 476
11 swift-frontend           0x0000000104fffe94 swift::runSILOptimizationPasses(swift::SILModule&) + 504
12 swift-frontend           0x00000001047b516c swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 1224
13 swift-frontend           0x00000001045a5f98 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1128
14 swift-frontend           0x00000001045a5a18 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2100
15 swift-frontend           0x00000001045a9694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
16 swift-frontend           0x00000001045a76d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
17 swift-frontend           0x0000000104536e8c swift::mainEntry(int, char const**) + 2612
18 dyld                     0x000000018774a0e0 start + 2360

### Expected behavior

no crash

### Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

### Additional information

Full command output:

% swift package benchmark
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build complete! (0.21s)
Building for debugging...
[1/1] Write swift-version--58304C5D6DBC2206.txt
Build complete! (0.42s)
Build complete!
Building BenchmarkTool in release mode...
Building benchmark targets in release mode for benchmark run...
Building ElementaryBenchmarks
Building for production...
[0/2] Write swift-version--58304C5D6DBC2206.txt
Build complete! (0.13s)
Building for production...
[0/3] Write swift-version--58304C5D6DBC2206.txt
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.      Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/AttributeStorage.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/CoreModel.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/Html+Attributes.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/Html+Elements.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/Html+Rendering.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/HtmlBuilder.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/Core/HtmlTextRenderer.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/HtmlAttributes.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/HtmlDocument.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/HtmlElements.swift /Users/simon/dev/swift-projects/Elementary/Sources/Elementary/HtmlTags.swift -supplementary-output-file-map /var/folders/7w/fd5kdmmj5mqd5j5yjznxs5g40000gn/T/TemporaryDirectory.w4EY27/supplementaryOutputs-1 -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -I /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/ModuleCache -swift-version 5 -O -D SWIFT_PACKAGE -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -enable-experimental-feature StrictConcurrency=complete -enable-upcoming-feature ExistentialAny -enable-upcoming-feature ConciseMagicFile -enable-upcoming-feature ImplicitOpenExistentials -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Elementary -package-name elementary -disable-clang-spi -target-sdk-version 14.5 -target-sdk-name macosx14.5 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -enable-default-cmo -parse-as-library -num-threads 10 -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/AttributeStorage.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/CoreModel.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/Html+Attributes.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/Html+Elements.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/Html+Rendering.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlBuilder.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlTextRenderer.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlAttributes.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlDocument.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlElements.swift.o -o /Users/simon/dev/swift-projects/Elementary/Benchmarks/.build/arm64-apple-macosx/release/Elementary.build/HtmlTags.swift.o
1.      Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.      Compiling with the current language version
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for Elementary)
4.      While running pass #116648 SILModuleTransform "CrossModuleOptimization".
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           0x0000000109ca7f3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109ca70f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109ca8544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x0000000187b03584 _sigtramp + 56
4  swift-frontend           0x0000000104e20fb4 swift::SILCloner<(anonymous namespace)::InstructionVisitor>::doesOpTupleDisappear(swift::CanTypeWrapper<swift::TupleType>) + 300
5  swift-frontend           0x0000000104e1b89c (anonymous namespace)::InstructionVisitor::makeTypesUsableFromInline(swift::SILInstruction*, (anonymous namespace)::CrossModuleOptimization&) + 4276
6  swift-frontend           0x0000000104e18fb0 (anonymous namespace)::CrossModuleOptimization::serializeFunction(swift::SILFunction*, llvm::DenseMap<swift::SILFunction*, bool, llvm::DenseMapInfo<swift::SILFunction*, void>, llvm::detail::DenseMapPair<swift::SILFunction*, bool>> const&) + 228
7  swift-frontend           0x0000000104e187f8 (anonymous namespace)::CrossModuleOptimizationPass::run() + 468
8  swift-frontend           0x0000000104fe0978 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 16476
9  swift-frontend           0x0000000105019354 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
10 swift-frontend           0x0000000104ffd184 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 476
11 swift-frontend           0x0000000104fffe94 swift::runSILOptimizationPasses(swift::SILModule&) + 504
12 swift-frontend           0x00000001047b516c swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 1224
13 swift-frontend           0x00000001045a5f98 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1128
14 swift-frontend           0x00000001045a5a18 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2100
15 swift-frontend           0x00000001045a9694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
16 swift-frontend           0x00000001045a76d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
17 swift-frontend           0x0000000104536e8c swift::mainEntry(int, char const**) + 2612
18 dyld                     0x000000018774a0e0 start + 2360

Benchmark failed to run due to build error.
error: buildFailed
theLastOfCats commented 1 week ago

Same happened here: https://github.com/TechEmpower/FrameworkBenchmarks/actions/runs/9800239092/job/27061835854?pr=9146

Code: https://github.com/theLastOfCats/FrameworkBenchmarks/tree/master/frameworks/Swift/vapor/vapor-swifql

rsfinn commented 4 days ago

I'm experiencing a crash with an identical stack trace. In my case, the crash occurs when building an Xcode project from the command line using xcodebuild, but not when building the same project inside Xcode, and so I came here to report the bug instead of using Apple's bug reporter. I'm using Apple Swift version 5.10 (swiftlang-5.10.0.13, clang-1500.3.9.4) as provided by Xcode 15.4, running on macOS Sonoma 14.5.

The project is large and has a fair amount of proprietary code, so I haven't yet been able to reduce the problem to a smaller test case. But I hope the following information may be useful:

The crash started occurring when I updated my project in response to a recent reorganization of the SwiftSpellbook external packages. When the project initially updated packages to version 1.0.0, I got build errors from both Xcode and xcodebuild of the form error: Multiple commands produce '...SpellbookMac_67AA899B933055C8_PackageProduct.framework/Versions/A' and warning: duplicate output file '...SpellbookFoundation_-6AC965FA4921D22B_PackageProduct.framework/Versions/A' on task: Copy... (I understand Xcode issues aren't handled here, but I'm trying to explain how I arrived at the compiler crash).

I attempted to work around this by including the SpellbookLaunchctl package in a common framework already used by the targets in question, and re-exporting the package from that framework using @_exported. This seemed to fix the build problem within Xcode, but then I observed the compiler crash when building from the terminal.