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-10969] Segfault when using Self as generic argument #53358

Closed
swift-ci opened this issue Jun 19, 2019 · 6 comments
Closed

[SR-10969] Segfault when using Self as generic argument #53358

swift-ci opened this issue Jun 19, 2019 · 6 comments
Assignees
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-10969
Radar rdar://problem/51561208
Original Reporter aasimk (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

MacOS 10.14.5

Apple Swift version 5.1 (swiftlang-1100.0.43.3 clang-1100.0.26.3)

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

md5: 155e0e962fe3a544887bad1ed0bc39b2

is duplicated by:

  • SR-10996 Compiler crash on use of "Self" in class.

Issue Description:

Swift compiler crashes when using Self as a generic argument.

Sample code that produces crash

final public class TestGeneric<Output> {}

class Test {
    let testProperty = TestGeneric<Self>()
}

Stack dump

Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret generic.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name generic 
1.  While silgen emitStoredPropertyInitialization SIL function "@$s7generic4TestC12testPropertyAA0B7GenericCyACXDGvpfi".
 for expression at [generic.swift:7:24 - line:7:42] RangeText="TestGeneric<Self>("
0  swift                    0x000000010ca01963 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010ca01136 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff64c4db5d _sigtramp + 29
3  libsystem_platform.dylib 0x00007f995e80fde0 _sigtramp + 4189856416
4  swift                    0x0000000108f74868 swift::MetatypeInst::create(swift::SILDebugLocation, swift::SILType, swift::SILFunction*, swift::SILOpenedArchetypesState&) + 72
5  swift                    0x0000000108a26104 swift::SILBuilder::createMetatype(swift::SILLocation, swift::SILType) + 148
6  swift                    0x0000000108a98e9b swift::Lowering::SILGenBuilder::createMetatype(swift::SILLocation, swift::SILType) + 187
7  swift                    0x0000000108acb44c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 17964
8  swift                    0x0000000108a694db (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 4475
9  swift                    0x0000000108a7a487 (anonymous namespace)::ArgEmitter::emitTopLevel(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 935
10 swift                    0x0000000108a79e8d (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 701
11 swift                    0x0000000108a7700b (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1451
12 swift                    0x0000000108a74ac3 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3059
13 swift                    0x0000000108a70dab swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 2331
14 swift                    0x0000000108b41b47 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 439
15 swift                    0x0000000108af4615 swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*) + 581
16 swift                    0x0000000108a5fb95 swift::Lowering::SILGenModule::emitStoredPropertyInitialization(swift::PatternBindingDecl*, unsigned int)::$_6::operator()(swift::SILFunction*) const + 245
17 swift                    0x0000000108a5f858 swift::Lowering::SILGenModule::emitStoredPropertyInitialization(swift::PatternBindingDecl*, unsigned int) + 1000
18 swift                    0x0000000108b4b42b (anonymous namespace)::SILGenType::emitType() + 1115
19 swift                    0x0000000108a638ed swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 77
20 swift                    0x0000000108a62b36 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
21 swift                    0x0000000108a64611 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1329
22 swift                    0x000000010866f3f5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 31317
23 swift                    0x00000001086640a4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
24 swift                    0x00000001085f3333 main + 1219
25 libdyld.dylib            0x00007fff64a623d5 start + 1
fish: 'swift generic.swift' terminated by signal SIGSEGV (Address boundary error)
@belkadan
Copy link
Contributor

With asserts:

Assertion failed: (hasSelfMetadataParam() && "This method can only be called if the " "SILFunction has a self-metadata parameter"), function getSelfMetadataArgument, file /Volumes/Data/swift-public/swift/include/swift/SIL/SILFunction.h, line 955.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode10.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--8a31fb.o 
1.  Swift version 5.0-dev (LLVM f0b886e419, Swift 96b7bb015e)
2.  While silgen emitStoredPropertyInitialization SIL function "@$s4main4TestC12testPropertyAA0B7GenericCyACXDGvpfi".
 for expression at [<stdin>:4:24 - line:4:42] RangeText="TestGeneric<Self>("

@belkadan
Copy link
Contributor

I guess we'd want to reject this in Sema.

@theblixguy
Copy link
Collaborator

@belkadan Is it reasonable to ban this in `validateInitializerRef()`? Seems like a logical place for this check as its related to calling an initializer. There's already a check for CallExpr and we can build on that to detect if DynamicSelfType was passed as a generic argument to an initializer that's within a generic context.

@belkadan
Copy link
Contributor

No, it's not really about the initializer. You shouldn't be able to construct that type at all, and then you shouldn't be able to give that type to a property. (Slava would probably know better than me where the right place is.)

@slavapestov
Copy link
Member

I agree it should be banned. I'm working on a fix right now.

@slavapestov
Copy link
Member

#25877

@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

5 participants