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-6794] Segmentation fault invoking super.init() inside autoreleasepool{} after initializing property #49343

Closed
swift-ci opened this issue Jan 19, 2018 · 2 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-6794
Radar rdar://problem/36737102
Original Reporter lithium3141 (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

I'm using the release version of Xcode 9.2 (9C40b) with accompanying Swift toolchain:

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9

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

md5: d49805e9bb6222bc800c7286f2f55aab

Issue Description:

In the process of transliterating some ObjC into Swift, I misplaced the close curly brace of an autoreleasepool block inside an init() override, accidentally including the call to super.init(). The autorelease pool also included the initialization of some properties of the object, an NSObject subclass.

Rather than throw an appropriate error, the Swift compiler encountered a segmentation fault upon trying to compile this code. I've attached a small sample that reproduces the error, along with a log of the error message itself.

@belkadan
Copy link
Contributor

Still happens on master:

Assertion failed: (SGF.SelfInitDelegationState == SILGenFunction::DidExclusiveBorrowSelf), function applySuper, file /Volumes/Data/swift-public/swift/lib/SILGen/SILGenApply.cpp, line 1087.

7  swift                    0x000000010575d107 (anonymous namespace)::SILGenApply::visitApplyExpr(swift::ApplyExpr*) + 6375
8  swift                    0x000000010575c238 (anonymous namespace)::SILGenApply::visitApplyExpr(swift::ApplyExpr*) + 2584
9  swift                    0x0000000105749bb5 prepareApplyExpr(swift::Lowering::SILGenFunction&, swift::Expr*) + 133
10 swift                    0x0000000105749b05 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 37
11 swift                    0x00000001057a8a2d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 93
12 swift                    0x00000001057a3a99 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
13 swift                    0x00000001057b682d computeNewSelfForRebindSelfInConstructorExpr(swift::Lowering::SILGenFunction&, swift::RebindSelfInConstructorExpr*) + 45
14 swift                    0x00000001057aa0bb swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5867
15 swift                    0x00000001057a3d74 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 516
16 swift                    0x0000000105809725 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 581
17 swift                    0x00000001058094d5 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
18 swift                    0x00000001057c5b7a swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 330
19 swift                    0x000000010573e28f swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 287
20 swift                    0x00000001057b66ac (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 44
21 swift                    0x00000001057a8a4e swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 126
22 swift                    0x00000001057a3a99 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
23 swift                    0x00000001057af3a0 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 27088
24 swift                    0x00000001057aa92a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 8026
25 swift                    0x00000001057a3a99 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 57
26 swift                    0x0000000105728e27 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 631
27 swift                    0x0000000105788bf8 swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 376
28 swift                    0x0000000105729031 swift::Lowering::ArgumentSource::getConverted(swift::Lowering::SILGenFunction&, swift::Lowering::Conversion const&, swift::Lowering::SGFContext) && + 129
29 swift                    0x000000010576029c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 3692
30 swift                    0x000000010576257e (anonymous namespace)::ArgEmitter::emitShuffle(swift::TupleShuffleExpr*, swift::Lowering::AbstractionPattern) + 5054
31 swift                    0x0000000105760dfa (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1530
32 swift                    0x000000010575f4e1 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 177
33 swift                    0x000000010575e97d (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 445
34 swift                    0x000000010575e277 (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>&) + 1927
35 swift                    0x000000010574aeb4 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3204
36 swift                    0x0000000105749b13 swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 51
37 swift                    0x00000001057a8a2d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 93
38 swift                    0x00000001057a3d74 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 516
39 swift                    0x0000000105809725 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 581
40 swift                    0x00000001058094d5 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
41 swift                    0x0000000105782623 swift::Lowering::SILGenFunction::emitClassConstructorInitializer(swift::ConstructorDecl*) + 2499
42 swift                    0x00000001057453c7 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*)::$_3::operator()(swift::SILFunction*) const + 231
43 swift                    0x000000010573ddd8 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 2136
44 swift                    0x0000000105813861 (anonymous namespace)::SILGenType::emitType() + 673
45 swift                    0x00000001058135b9 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
46 swift                    0x000000010574174b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 763
47 swift                    0x00000001057423e1 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 353
48 swift                    0x00000001057429da swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>) + 122
49 swift                    0x000000010509dace performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 9822
50 swift                    0x000000010509a461 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3185
51 swift                    0x000000010505b360 main + 3328
52 libdyld.dylib            0x00007fff77d29115 start + 1
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file /Users/jrose/Downloads/AutoreleaseSuperInitSegfault.swift -target x86_64-apple-darwin17.4.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name AutoreleaseSuperInitSegfault -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/AutoreleaseSuperInitSegfault-7f38f0.o 
1.  While silgen constructor initializer SIL function "@$S28AutoreleaseSuperInitSegfault4TestCACycfc".
 for 'init()' at /Users/jrose/Downloads/AutoreleaseSuperInitSegfault.swift:6:11
2.  While silgen closureexpr SIL function "@$S28AutoreleaseSuperInitSegfault4TestCACycfcyycfU_".
 for expression at [/Users/jrose/Downloads/AutoreleaseSuperInitSegfault.swift:7:19 - line:10:3] RangeText="{
            self.foo = "foo"
            super.init()
        }"

@swift-ci create

@slavapestov
Copy link
Member

#15028

@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