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

[SR-11517] Compiler crash in Xcode 11 with struct containing tuple of optionals #53918

Closed
swift-ci opened this issue Sep 25, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software regression swift 5.1

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11517
Radar None
Original Reporter erikstrottmann (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11.0 (11A420a)
Swift toolchain bundled with Xcode 11
macOS Mojave 10.14.5 (18F203)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.1Regression, CompilerCrash
Assignee None
Priority Medium

md5: 07df1ca2e9800f95151b84a0aa1c3b67

Issue Description:

In Xcode 11, the Swift compiler crashes with a segmentation fault when I try to compile the following struct:

struct BadStruct {
    var badTuple: (Int?, Int?)
}

Some observations:

  • Adding an explicit initializer to the struct resolves the issue, so this might have something to do with SE-0242

  • Adding an explicit default value to the tuple resolves the issue: var badTuple: (Int?, Int?) = (nil, nil)

  • The enclosing type has to be a struct—classes don’t have the same issue, and neither do tuple values in the global scope

  • The tuple has to be a var property, not a let one

  • The types and quantity of the values in the tuple do not seem to matter, as long as they are all optional

  • The struct has to be built by Xcode 11 in an Xcode project—Xcode 10, Playgrounds, and the Swift CLI does not have the issue, but Xcode projects created by Xcode or generated with swift package generate-xcodeproj do

This is the segmentation fault error message:

CompileSwift normal x86_64 /Users/erikstrottmann/Desktop/Test/BadTuple/Sources/BadTuple/main.swift (in target 'BadTuple' from project 'BadTuple')
    cd /Users/erikstrottmann/Desktop/Test/BadTuple
    /Applications/Xcode\ 11.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/erikstrottmann/Desktop/Test/BadTuple/Sources/BadTuple/main.swift -emit-module-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main\~partial.swiftmodule -emit-module-doc-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main\~partial.swiftdoc -serialize-diagnostics-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.10 -enable-objc-interop -sdk /Applications/Xcode\ 11.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug -F /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug -F /Applications/Xcode\ 11.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -g -module-cache-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/erikstrottmann/Desktop/Test/BadTuple -enable-anonymous-context-mangled-names -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/swift-overrides.hmap -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug/include -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources-normal/x86_64 -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources/x86_64 -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources -Xcc -DSWIFT_PACKAGE=1 -Xcc -DDEBUG=1 -module-name BadTuple -o /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.o -index-store-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Index/DataStore -index-system-modules
Stack dump:
0.  Program arguments: /Applications/Xcode 11.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/erikstrottmann/Desktop/Test/BadTuple/Sources/BadTuple/main.swift -emit-module-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.10 -enable-objc-interop -sdk /Applications/Xcode 11.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug -F /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug -F /Applications/Xcode 11.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -g -module-cache-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/erikstrottmann/Desktop/Test/BadTuple -enable-anonymous-context-mangled-names -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/swift-overrides.hmap -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Products/Debug/include -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources-normal/x86_64 -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources/x86_64 -Xcc -I/Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/DerivedSources -Xcc -DSWIFT_PACKAGE=1 -Xcc -DDEBUG=1 -module-name BadTuple -o /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Build/Intermediates.noindex/BadTuple.build/Debug/BadTuple.build/Objects-normal/x86_64/main.o -index-store-path /Users/erikstrottmann/Library/Developer/Xcode/DerivedData/BadTuple-bdkrzottxorsrzgqdvhqcpjlqnkj/Index/DataStore -index-system-modules 
1.  While running pass #​0 SILModuleTransform "SerializeSILPass".
2.  While serializing 'badTuple' (at /Users/erikstrottmann/Desktop/Test/BadTuple/Sources/BadTuple/main.swift:1:8)
0  swift                    0x0000000109e37eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000109e37686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff5f0f1b5d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000210 _sigtramp + 2700142288
4  swift                    0x00000001069842e1 swift::ParamDecl::getDefaultValueStringRepresentation(llvm::SmallVectorImpl<char>&) const + 1201
5  swift                    0x000000010670c09a swift::serialization::Serializer::writeDecl(swift::Decl const*) + 5946
6  swift                    0x0000000106731b3f swift::serialization::Serializer::writeAllDeclsAndTypes() + 62287
7  swift                    0x000000010673eb04 swift::serialization::Serializer::writeAST(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, bool) + 5364
8  swift                    0x000000010674ba30 swift::serialization::Serializer::writeToStream(llvm::raw_ostream&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SILModule const*, swift::SerializationOptions const&) + 6000
9  swift                    0x000000010674d30b bool llvm::function_ref<bool (llvm::raw_pwrite_stream&)>::callback_fn<swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*)::$_8>(long, llvm::raw_pwrite_stream&) + 139
10 swift                    0x0000000105a5d079 swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 2569
11 swift                    0x000000010674d167 swift::serialize(llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*) + 311
12 swift                    0x0000000105a98aab std::__1::__function::__func<performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_12, std::__1::allocator<performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*)::$_12>, void ()>::operator()() + 603
13 swift                    0x0000000106240391 SerializeSILPass::run() + 49
14 swift                    0x0000000106136a29 swift::SILPassManager::execute() + 7305
15 swift                    0x0000000105d935bb swift::CompilerInstance::performSILProcessing(swift::SILModule*, swift::UnifiedStatsReporter*) + 1563
16 swift                    0x0000000105a8ecc5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 33925
17 swift                    0x0000000105a83034 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
18 swift                    0x0000000105a105a3 main + 1219
19 libdyld.dylib            0x00007fff5ef063d5 start + 1
20 libdyld.dylib            0x0000000000000042 start + 2702154862
error: Segmentation fault: 11 (in target 'BadTuple' from project 'BadTuple')
@theblixguy
Copy link
Collaborator

No longer crashes on master. I think this was fixed by @harlanhaskins's PR: #26506

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software regression swift 5.1
Projects
None yet
Development

No branches or pull requests

3 participants