Compiler crashes when some closure parameters have equal names and different types
Description Compiler crashes when some closure parameters have equal names and different types
Stored value type does not match pointer operand type!
store %T7Combine18PassthroughSubjectCySis5NeverOG* %51, %T7Combine18PassthroughSubjectCy10Foundation4DataVs5NeverOG** %4, align 8, !dbg !288
%T7Combine18PassthroughSubjectCySis5NeverOG*<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: Broken module found, compilation aborted!
Stack dump:
0. Program arguments: /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret /Users/Documents/proj/test/TestPointerCrash.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -color-diagnostics -new-driver-path /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -plugin-path /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -resource-dir /Applications/Xcode-15.0.0-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name TestPointerCrash -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0
1. Apple Swift version 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1)
2. Compiling with the current language version
3. While running user code "/Users/Documents/proj/test/TestPointerCrash.swift"
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 0x0000000105d2391c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x0000000105d22ae0 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x0000000105d23f1c SignalHandler(int) + 352
3 libsystem_platform.dylib 0x000000018f93ea84 _sigtramp + 56
4 libsystem_pthread.dylib 0x000000018f90fc28 pthread_kill + 288
5 libsystem_c.dylib 0x000000018f81dae8 abort + 180
6 swift-frontend 0x000000010075cb14 PrettyStackTraceFrontend::~PrettyStackTraceFrontend() + 0
7 swift-frontend 0x0000000105c706fc llvm::report_fatal_error(llvm::Twine const&, bool) + 280
8 swift-frontend 0x0000000105c705e4 llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9 swift-frontend 0x0000000100cc9670 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::printPipeline(llvm::raw_ostream&, llvm::function_ref<llvm::StringRef (llvm::StringRef)>) + 0
10 swift-frontend 0x0000000105a2b064 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 224
11 swift-frontend 0x0000000100cb8114 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*, llvm::raw_pwrite_stream*) + 4252
12 swift-frontend 0x0000000100cb9934 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, swift::UnifiedStatsReporter*) + 2244
13 swift-frontend 0x000000010079d3a0 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>&&) + 352
14 swift-frontend 0x000000010075740c processCommandLineAndRunImmediately(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>&&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::FrontendObserver*, int&) + 484
15 swift-frontend 0x0000000100752014 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*) + 1464
16 swift-frontend 0x000000010075523c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 3016
17 swift-frontend 0x00000001007531e0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4216
18 swift-frontend 0x0000000100718a58 swift::mainEntry(int, char const**) + 4112
19 dyld 0x000000018f5b7f28 start + 2236
Steps to reproduce
Run next code in console (swift FileToTest.swift) to reproduce crash
Uncomment code to fix crash (just rename closure parameter)
import Foundation
import Combine
struct Box {
var serverMessages = PassthroughSubject<Data, Never>()
var dataMessages = PassthroughSubject<Int, Never>()
}
class Test {
private let dependency = Box()
var task1: Task<Void, Never>?
var task2: Task<Void, Never>?
func subscribe() {
task1 = Task { [messages = dependency.serverMessages] in
print(messages)
}
task2 = Task { [messages = dependency.dataMessages] in
print(messages)
}
/*task2 = Task { [messages2 = dependency.dataMessages] in
print(messages2)
}
}*/
print("SUCCESS")
}
}
let test = Test()
test.subscribe()
Expected behavior Compiler not crashed
Environment
- Swift 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1)
- Xcode 15.0 Build version 15A5160n
P.S. Code perfectly works on Swift 5.7
In my project (quite large), i have 50 Abort trap: 6 with the same error message like:
Stored value type does not match pointer operand type!
store %swift.bridge* %106, %TSa** %6, align 8, !dbg !3649
I'm adding this message just to specify that if, for Optimization Level, Debug, I change -Onone to -O, it compiles correctly.
This code snippet also seems to trigger this:
import Foundation
import Combine
extension AnyPublisher {
func async() async throws -> Output {
var myCancellable: AnyCancellable?
return try await withTaskCancellationHandler(operation: {
try await withCheckedThrowingContinuation { continuation in
myCancellable = first()
.sink { result in
switch result {
case .finished:
break
case let .failure(error):
continuation.resume(throwing: error)
}
myCancellable?.cancel()
} receiveValue: { value in
continuation.resume(with: .success(value))
}
}
}, onCancel: { [myCancellable] in
myCancellable?.cancel()
})
}
}
Logs:
Stored value type does not match pointer operand type!
store i64 %46, %T7Combine14AnyCancellableCSg** %9, align 8, !dbg !416
i64Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
And the solution is to convert the onCancel to:
}, onCancel: { [weak cancellable = myCancellable] in
cancellable?.cancel()
})
Still got crash with Xcode 15 b2 (but i now have 25 Abort trap: 6 instead of 50 with b1)
Both examples crash in IRGen with 23e2f345b51ca0c. Reduced test case for the original snippet:
class C {
func test(x: Int, y: Bool) {
var clos: () -> Void
clos = { [cap = x] in }
clos = { [cap = y] in }
}
}
Invalid shadow copy:
Value : i1 %1
Alloca: %cap.debug = alloca i64, align 8
---
Previous shadow copy into cap in the same scope!
Scope:
{
parent: {
/Users/mac/Desktop/test.swift:139:8
parent: @$s4test1CCAA1x1yySi_SbtF
}
}
Assertion failed: (canAllocaStoreValue(Address, Storage, VarInfo, Scope) && "bad scope?"), function emitShadowCopy, file IRGenSIL.cpp, line 960.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0. Program arguments: bin/swift-frontend /Users/mac/Desktop/test.swift -emit-ir
1. Swift version 5.9-dev (LLVM d638e0929fa87b0, Swift 23e2f345b51ca0c)
2. Compiling with the current language version
3. While evaluating request IRGenRequest(IR Generation for module test)
4. While emitting IR SIL function "@$s4test1CCAA1x1yySi_SbtF".
for 'test(x:y:)' (at /Users/mac/Desktop/test.swift:139:3)
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 0x0000000105e1ae57 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1 swift-frontend 0x0000000105e1a135 llvm::sys::RunSignalHandlers() + 85
2 swift-frontend 0x0000000105e1b4a0 SignalHandler(int) + 288
3 libsystem_platform.dylib 0x00007ff815a94dfd _sigtramp + 29
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370217517600
5 libsystem_c.dylib 0x00007ff8159cad24 abort + 123
6 libsystem_c.dylib 0x00007ff8159ca0cb err + 0
7 swift-frontend 0x0000000105f6e5f3 (anonymous namespace)::IRGenSILFunction::emitShadowCopy(llvm::Value*, swift::SILDebugScope const*, swift::SILDebugVariable, llvm::Optional<swift::irgen::Alignment>, bool, bool) (.cold.5) + 35
8 swift-frontend 0x000000010085a680 (anonymous namespace)::IRGenSILFunction::emitShadowCopy(llvm::Value*, swift::SILDebugScope const*, swift::SILDebugVariable, llvm::Optional<swift::irgen::Alignment>, bool, bool) + 992
9 swift-frontend 0x000000010085b8d2 (anonymous namespace)::IRGenSILFunction::emitShadowCopyIfNeeded(llvm::Value*, swift::SILDebugScope const*, swift::SILDebugVariable, bool, bool, llvm::Optional<swift::irgen::Alignment>) + 722
10 swift-frontend 0x0000000100855d2b swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 92219
11 swift-frontend 0x000000010083a59a (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 11210
12 swift-frontend 0x0000000100837371 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1905
13 swift-frontend 0x00000001006a82de swift::irgen::IRGenerator::emitLazyDefinitions() + 1966
14 swift-frontend 0x00000001007bfdf6 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2102
15 swift-frontend 0x000000010083672c swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 204
16 swift-frontend 0x000000010083661e swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 14
17 swift-frontend 0x00000001007ceee3 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 371
18 swift-frontend 0x00000001007c11b1 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 1281
19 swift-frontend 0x00000001002bb326 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*) + 2166
20 swift-frontend 0x00000001002ba92a swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2362
21 swift-frontend 0x00000001002bd756 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 950
22 swift-frontend 0x00000001002bc4a9 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3321
23 swift-frontend 0x0000000100256bea swift::mainEntry(int, char const**) + 2282
24 dyld 0x000000011f5b752e start + 462
Abort trap: 6
cc @gottesmm
Potential duplicate: #59572
It's ok for me since Xcode 15 b3