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-12436] Xcode 11.4 regression: Segfault with coverage and a ternary in a default init argument #54875

Closed
ZevEisenberg opened this issue Mar 27, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@ZevEisenberg
Copy link
Contributor

Previous ID SR-12436
Radar rdar://problem/62200998
Original Reporter @ZevEisenberg
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 11.3.1 (11C505) and Xcode 11.4 (11E146) on macOS 10.15.4 (19E266)

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 2ca56ae0633ba678a44236ae721150b2

Issue Description:

I've isolated this down as much as I can. I don't understand what all the Terminal command parameters do; I found them by grabbing the swift invocation from an Xcode project and removing as many parameters as I could while still reproducing the issue.

crash.swift:

enum DemoEnum {
    case foo
}

struct NewThing {
    init(foo: Double = DemoEnum.foo == .foo ? 1 : 2) {}
}

With Xcode 11.4 selected, this segfaults:

swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping

Stack dump:
0.  Program arguments: /Applications/Xcode_11.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping 
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While silgen emitConstructor SIL function "@$s5crash8NewThingV3fooACSd_tcfC".
 for 'init(foo:)' (at /Users/211518/Desktop/crash.swift:7:5)
0  swift                    0x0000000112cc94ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000112cc8cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee12884e0 _sigtramp + 2043719424
4  swift                    0x000000010f9f5f50 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 272
5  swift                    0x000000010f9f90e7 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 487
6  swift                    0x000000010f9f5e03 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 275
7  swift                    0x000000010f3ed538 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode, swift::SILDeclRef) + 2824
8  swift                    0x000000010ee306ca swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 778
9  swift                    0x000000010ef2a3b1 swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 145
10 swift                    0x000000010ef2853b (anonymous namespace)::SILGenType::emitType() + 1163
11 swift                    0x000000010ee3a5e2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
12 swift                    0x000000010ee397ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
13 swift                    0x000000010ee3b82e swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438
14 swift                    0x000000010ea1b657 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48055
15 swift                    0x000000010e9934d3 main + 1283
16 libdyld.dylib            0x00007fff67384cc9 start + 1
[1]    59651 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk   

With Xcode 11.3.1 selected, this slightly modified command does not:

swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping
# [nothing printed after that, because there is no error or crash]

I noticed that this slightly modified version of the code, with a global function instead of an initializer, crashes both Xcode 11.4 and 11.3.1's toolchains, but I'm not sure if it's related or separate, so please let me know if I should file a separate bug:

enum DemoEnum {
    case foo
}

func foo(foo: Double = DemoEnum.foo == .foo ? 1 : 2) {}

Xcode 11.4:

swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping

Stack dump:
0.  Program arguments: /Applications/Xcode_11.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping 
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While emitting SIL for 'foo(foo:)' (at /Users/211518/Desktop/crash.swift:5:1)
0  swift                    0x00000001104df4ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001104decc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee3a72f40 _sigtramp + 2085575008
4  swift                    0x000000010d20bf50 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 272
5  swift                    0x000000010d20f0e7 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 487
6  swift                    0x000000010d20be03 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 275
7  swift                    0x000000010cc03538 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode, swift::SILDeclRef) + 2824
8  swift                    0x000000010c645b57 setUpForProfiling(swift::SILDeclRef, swift::SILFunction*, swift::ForDefinition_t) + 119
9  swift                    0x000000010c644a6b swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 475
10 swift                    0x000000010c6460e7 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 743
11 swift                    0x000000010c64f7ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
12 swift                    0x000000010c65182e swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438
13 swift                    0x000000010c231657 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48055
14 swift                    0x000000010c1a94d3 main + 1283
15 libdyld.dylib            0x00007fff67384cc9 start + 1
[1]    59995 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk

Xcode 11.3.1:

swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping
Stack dump:
0.  Program arguments: /Applications/Xcode_11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping 
1.  While emitting SIL for 'foo(foo:)' (at /Users/211518/Desktop/crash.swift:5:1)
0  swift                    0x000000010758ca63 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010758c236 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
3  libsystem_platform.dylib 0x0000000111d124dc _sigtramp + 2860076796
4  swift                    0x0000000104095ea8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 296
5  swift                    0x0000000104098c5a (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 426
6  swift                    0x0000000104095d3c (anonymous namespace)::Traversal::doIt(swift::Decl*) + 284
7  swift                    0x0000000103b1b800 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode) + 2688
8  swift                    0x00000001035c5fd3 setUpForProfiling(swift::SILDeclRef, swift::SILFunction*, swift::ForDefinition_t) + 115
9  swift                    0x00000001035c50e3 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 467
10 swift                    0x00000001035c66de swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 766
11 swift                    0x00000001035d1296 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
12 swift                    0x00000001035d2cf6 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1238
13 swift                    0x00000001031d48f4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 28340
14 swift                    0x00000001031ca234 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
15 swift                    0x0000000103157733 main + 1219
16 libdyld.dylib            0x00007fff67384cc9 start + 1
[1]    60047 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk

I haven't tested on the nightly toolchain.

@beccadax
Copy link
Contributor

@swift-ci create

@beccadax
Copy link
Contributor

@ZevEisenberg Thanks for filing. Can you try one of the nightlies? I reproduced this with Swift 5.2, but I don't think it's happening in Swift 5.3.

(Setting to "Invalid" because I think it's already fixed; it's otherwise a perfectly valid report.)

@ZevEisenberg
Copy link
Contributor Author

Confirmed! It took me a minute to learn about the magic export TOOLCHAINS=swift to get my Terminal to pick up the custom toolchain, but once it had, it compiled without incident ��‍♂️

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

2 participants