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-11689] Segmentation fault referring to Self in class extension #54098

Closed
swift-ci opened this issue Oct 31, 2019 · 5 comments
Closed

[SR-11689] Segmentation fault referring to Self in class extension #54098

swift-ci opened this issue Oct 31, 2019 · 5 comments
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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11689
Radar None
Original Reporter mlex (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 11 GM Seed 2, Version 11.0 (11A420a)

macOS Mojave Version 10.14.6

MacBook Pro (Retina, 15-inch, Mid 2015) 2.8 GHz Intel Core i7

Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
Target: x86_64-apple-darwin18.7.0

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

md5: f77639cad06f6074facf5d8fca7ac215

duplicates:

  • SR-11636 Accessing covariant Self from stored property initializer in extension segfaults

Issue Description:

I get a compiler segfault trying to compile this snippet:

final class Class {
    // This would correctly give the compiler error:
    // /Users/limalex/workspace/SwiftCompilerCrashExample/SwiftCompilerCrashExample/main.swift:12:28: Covariant 'Self' type cannot be referenced from a stored property initializer
    // static let something = Self.self
}

extension Class {
    // This could be any reference to `Self` and it would crash (i.e. I could try to call some static method on `Class`).
    static let something = Self.self
}

Stack trace:

Stack dump:
0.  Program arguments: /Applications/Xcode 11 GM Seed 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/limalex/workspace/SwiftCompilerCrashExample/SwiftCompilerCrashExample/main.swift -emit-module-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.14 -enable-objc-interop -sdk /Applications/Xcode 11 GM Seed 2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Products/Debug -F /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Products/Debug -enable-testing -g -module-cache-path /Users/limalex/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/limalex/workspace/SwiftCompilerCrashExample -enable-anonymous-context-mangled-names -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/SwiftCompilerCrashExample-generated-files.hmap -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/SwiftCompilerCrashExample-own-target-headers.hmap -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/SwiftCompilerCrashExample-all-target-headers.hmap -Xcc -iquote -Xcc /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/SwiftCompilerCrashExample-project-headers.hmap -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Products/Debug/include -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/DerivedSources-normal/x86_64 -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/DerivedSources/x86_64 -Xcc -I/Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/DerivedSources -Xcc -DDEBUG=1 -module-name SwiftCompilerCrashExample -o /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Build/Intermediates.noindex/SwiftCompilerCrashExample.build/Debug/SwiftCompilerCrashExample.build/Objects-normal/x86_64/main.o -index-store-path /Users/limalex/Library/Developer/Xcode/DerivedData/SwiftCompilerCrashExample-axiqrddcnxfrqjfzcxfibwavdplt/Index/DataStore -index-system-modules 
0  swift                    0x000000010b8a1eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010b8a1686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff7a1c8b5d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee879eae0 _sigtramp + 1851613088
4  swift                    0x0000000107e07438 swift::MetatypeInst::create(swift::SILDebugLocation, swift::SILType, swift::SILFunction*, swift::SILOpenedArchetypesState&) + 72
5  swift                    0x00000001078b8a74 swift::SILBuilder::createMetatype(swift::SILLocation, swift::SILType) + 148
6  swift                    0x000000010792845b swift::Lowering::SILGenBuilder::createMetatype(swift::SILLocation, swift::SILType) + 187
7  swift                    0x000000010795b008 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 18552
8  swift                    0x00000001079565b3 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 131
9  swift                    0x00000001079499ac swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 268
10 swift                    0x00000001079869a1 swift::Lowering::SILGenModule::emitGlobalInitialization(swift::PatternBindingDecl*, unsigned int) + 2417
11 swift                    0x00000001079dda22 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 370
12 swift                    0x00000001078f1e96 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
13 swift                    0x00000001078f38f6 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1238
14 swift                    0x00000001074f76f9 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 28345
15 swift                    0x00000001074ed034 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
16 swift                    0x000000010747a5a3 main + 1219
17 libdyld.dylib            0x00007fff79fdd3d5 start + 1
error: Segmentation fault: 11 (in target 'SwiftCompilerCrashExample' from project 'SwiftCompilerCrashExample')

Expected: I get a compiler error for trying to refer to `Self` in a stored property initializer.

Actual: The compiler segfaults.

@theblixguy
Copy link
Collaborator

On master, I get:

/Users/suyashsrijan/Desktop/test.swift:9:16: error: unexpected error produced: covariant 'Self' can only appear at the top level of property type
    static let something = Self.self
               ^
/Users/suyashsrijan/Desktop/test.swift:9:16: error: unexpected error produced: stored property cannot have covariant 'Self' type
    static let something = Self.self
               ^
/Users/suyashsrijan/Desktop/test.swift:9:16: error: unexpected error produced: covariant 'Self' can only appear at the top level of method result type

@swift-ci
Copy link
Collaborator Author

Comment by Alexander Lim (JIRA)

I can retry this using the latest Xcode (11.1), I mentioned in the "Environment" section that I'm running 11 GM Seed 2 right now.

@swift-ci
Copy link
Collaborator Author

Comment by Alexander Lim (JIRA)

I can confirm I still run into this issue after I tried it on Xcode 11.1, Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)

@theblixguy
Copy link
Collaborator

Yeah, it's not fixed on 5.1 but it's fixed on master, so this should get diagnosed as expected in Swift 5.2. You can verify using a development snapshot from swift.org.

@belkadan
Copy link
Contributor

belkadan commented Nov 1, 2019

Dup of SR-11636…but if it's already fixed that one should be closed too!

@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
Projects
None yet
Development

No branches or pull requests

4 participants