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-9614] Segmentation fault: 11 at swift::ASTVisitor... #52060

Open
swift-ci opened this issue Jan 7, 2019 · 12 comments
Open

[SR-9614] Segmentation fault: 11 at swift::ASTVisitor... #52060

swift-ci opened this issue Jan 7, 2019 · 12 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 type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 7, 2019

Previous ID SR-9614
Radar None
Original Reporter mozeryansky (JIRA User)
Type Bug
Environment

Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)

Xcode 10.1 (10B61)

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

md5: 4eed5652c524aabc20a170c9ec341802

Issue Description:

Aftering adding an import I now get Segmentation Faults. Clearing derived data / etc doesn't work. I've imported this module before in other places throughout my app.

0 swift 0x000000010bc1959a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000010bc18d4e SignalHandler(int) + 302
2 libsystem_platform.dylib 0x00007fff7b8d2b3d _sigtramp + 29
3 libsystem_platform.dylib 0x000000010d1f4000 _sigtramp + 2442269920
4 swift 0x0000000109323e4c swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 76
5 swift 0x0000000109323f07 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 263
6 swift 0x0000000109323e85 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 133
7 swift 0x0000000108eb70db swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 827
8 swift 0x0000000108f01198 swift::constraints::ConstraintSystem::solve(swift::Expr*&, swift::Type, swift::ExprTypeCheckListener*, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 9112
9 swift 0x0000000108fb92f4 swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 52
10 swift 0x0000000108fb9a17 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1207
11 swift 0x0000000108e91d4c (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*, bool) + 1516
12 swift 0x0000000108e8f577 (anonymous namespace)::FailureDiagnosis::typeCheckArbitrarySubExprIndependently(swift::Expr*, swift::OptionSet<TCCFlags, unsigned int>) + 839
13 swift 0x0000000108e81fba swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 3850
14 swift 0x0000000108eb449f swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 6207
15 swift 0x0000000108fb933a swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem&, llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 122
16 swift 0x0000000108fb9a17 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 1207
17 swift 0x000000010905189c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 12044
18 swift 0x000000010904daae swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 1294
19 swift 0x0000000109053358 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 888
20 swift 0x0000000109079f03 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2515
21 swift 0x0000000108cb3f05 swift::CompilerInstance::performSema() + 4949
22 swift 0x0000000107e9f50b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 731
23 swift 0x0000000107e9bd35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
24 swift 0x0000000107e41965 main + 1349
25 libdyld.dylib 0x00007fff7b6e908d start + 1
error: Segmentation fault: 11

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 7, 2019

Comment by Michael Ozeryansky (JIRA)

Also, I'm getting Segmentation Faults in 2 files. One file I did not touch. Each file defines a class which is not used by each other, so they're mostly unrelated.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 7, 2019

Comment by Michael Ozeryansky (JIRA)

It seems the issue came from defining an extension on my protocol which implements a function.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 8, 2019

Comment by Michael Ozeryansky (JIRA)

I tracked it down. I had the instance variable typed to my protocol as an optional. I wasn't defaulting the nullable value, and when I added a default value everything worked.

old: self.x = myProtocolInstance?.func() <= Segment Fault
new: self.x = myProtocolInstance?.func() ?? "Default" <= Fine

@belkadan
Copy link
Contributor

belkadan commented Jan 8, 2019

Do you have a self-contained reproducer for this? Or can you share your full project in the bad state? (If not here, then at https://bugreport.apple.com.)

cc @xedin

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 8, 2019

Comment by Michael Ozeryansky (JIRA)

Unfortunately, I don't have a reproducing crashing code, after resolving the crash I've moved on. I tried creating a sample project but I can't reproduce.

My project is made up of external and local cocoapods. The issue occurred within a local pod framework. I don't believe this is an issue with Cocoapods just noting that since they setup the framework configuration. This framework is included by another framework, and that framework is included by the main app.

In general, I won't be able to share my entire project, but is there a way to enable more logging or something else I can provide in future bugs?

@xedin
Copy link
Member

xedin commented Jan 8, 2019

If you can't include your project maybe you could at least clarify what `self` and `x` are to give us some starting point?...

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jan 9, 2019

Comment by Michael Ozeryansky (JIRA)

self is referencing a class which is a subclass of a subclass of Operation. And x is an instance variable with the type [[UInt8]].

class SuperSuperTest: Operation {}
class SuperTest: SuperSuperTest {}
class Test: SuperTest {
var myInstance: MyProtocol?
{{ init(myInstance: MyProtocol? = nil)}}{
self.myInstance = myInstance
}
{{ func foo()}}{
let x: [[UInt8]] = myInstance?.function() ?? [[Uint8]]()

{{ bar(nonOptional: x)}}

}

{{ func bar(nonOptional: [[UInt8]])}}{

{{ someOtherFunction(nonOptional)}}

}

{{}}}

Although, this example (with and without the "— ") doesn't cause the crash. At the time I filed the bug I did not realize the returned value was optional and did not have the nil coalescing. Adding " [[Uint8]]()" resolved the crash. In my attempted sample project, Xcode says the value is optional as expected.

We have a fairly large project made up of frameworks including each other frameworks. My indexing seems to be fairly slow, so there must be something there with the type resolution.

@xedin
Copy link
Member

xedin commented Jan 10, 2019

mozeryansky (JIRA User) Does `function()` return `[[UInt8]]?` or is it generic?

@swift-ci
Copy link
Collaborator Author

Comment by Michael Ozeryansky (JIRA)

It returns `[[UInt8]]`, non-optional. And I think I had `let x = ...` so it must have been inferred by the return type. Sorry for not having a sample, thanks for trying to figure this out.

@xedin
Copy link
Member

xedin commented Jan 10, 2019

I wonder why would you need a `??` with default if neither `x` nor left-hand side was an optional?

@xedin
Copy link
Member

xedin commented Jan 10, 2019

Ah wait I missed that there was optional chaining going on.

@swift-ci
Copy link
Collaborator Author

Comment by Michael Ozeryansky (JIRA)

Yeah, I missed that too. Wasn't until I added "?? [[UInt8]]()" did it go away. But even removing it now doesn't cause the crash.

@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
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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants