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-3479] Segmentation fault and other error for closure with inout parameter #46067

Closed
swift-ci opened this issue Dec 23, 2016 · 6 comments
Closed
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-3479
Radar None
Original Reporter ingoem (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

swiftc 3.0.2

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

md5: 9ecb7420a0cb4bea9dccbd3411386b03

is duplicated by:

  • SR-892 Closure type inference does not work with inout arguments
  • SR-1811 Swift 3 regression related to inout closure params and protocols

relates to:

  • SR-3520 Generic function taking closure with inout parameter can result in a variety of compiler errors or EXC_BAD_ACCESS

Issue Description:

The following gives a segmentation fault in swiftc:

func f() {
  let _ = unfold((0, 0)) { s in 0 }
}

func unfold<A, B>(_ a0: A, next: (inout A)->B) {}

It compiles when I write an explicit type for the closure or if I pass 0 instead of (0,0) for a0. Now, if I change unfold to use a single type parameter:

func f() {
  let _ = unfold((0,0)) { s in 0 }  // incompatible types
}

func unfold<A>(_ a0: A, next: (inout A)->A) {}

instead of giving a type error swiftc just prints

<unknown>:0: error: parameters may not have the 'var' specifier

If I change the closure to return (0,0) instead of 0, it segfaults again.

0  swift                    0x0000000105f6b3ad PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x0000000105f6ab56 SignalHandler(int) + 790
2  libsystem_platform.dylib 0x00007fff8783e52a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000106dda000 _sigtramp + 2136586992
4  swift                    0x00000001031e4250 (anonymous namespace)::TranslateArguments::translate(swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType) + 1472
5  swift                    0x00000001031e3028 createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 1784
6  swift                    0x00000001031e0515 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::SGFContext) + 1909
7  swift                    0x00000001031a5c19 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 58313
8  swift                    0x000000010314c264 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1332
9  swift                    0x000000010314e557 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 263
10 swift                    0x000000010314be29 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 249
11 swift                    0x0000000103150d1d (anonymous namespace)::ArgEmitter::emitShuffle(swift::Expr*, swift::Expr*, llvm::ArrayRef<swift::TupleTypeElt>, swift::ConcreteDeclRef, llvm::ArrayRef<swift::Expr*>, llvm::ArrayRef<int>, llvm::ArrayRef<unsigned int>, swift::Type, swift::Lowering::AbstractionPattern) + 3885
12 swift                    0x000000010314eca3 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2131
13 swift                    0x000000010314be29 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 249
14 swift                    0x000000010314b407 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<std::__1::pair<swift::Lowering::LValue, swift::SILLocation> >&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus const&) && + 519
15 swift                    0x000000010314809b (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 5339
16 swift                    0x00000001031978c5 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 117
17 swift                    0x00000001031976e3 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 195
18 swift                    0x0000000103184dd3 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 195
19 swift                    0x000000010313c09d swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 125
20 swift                    0x00000001031f5769 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4169
21 swift                    0x00000001031b5e1a swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 314
22 swift                    0x0000000103132055 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 1877
23 swift                    0x0000000103130c02 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 626
24 swift                    0x000000010313db03 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 2195
25 swift                    0x000000010313f62d swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1629
26 swift                    0x0000000102f77e86 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 19510
27 swift                    0x0000000102f712b3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17859
28 swift                    0x0000000102f2d5cf main + 8239
29 libdyld.dylib            0x00007fff892545ad start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file crash.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name crash -o /var/folders/.../crash-9f8735.o 
1.  While emitting SIL for 'f' at crash.swift:1:1
2.  While emitting reabstraction thunk in SIL function @_TTRXFo_dSidSi_dSidSi_XFo_lTSiSi__dSidSi_<unknown>:0: error: unable to execute command: Segmentation fault: 11
@belkadan
Copy link
Contributor

belkadan commented Jan 6, 2017

   Unhandled conversion to exploded tuple
UNREACHABLE executed at /Volumes/Data/swift-public/swift/lib/SILGen/SILGenPoly.cpp:962!

1.  While emitting SIL for 'f' at <stdin>:1:1
2.  While emitting reabstraction thunk in SIL function @_TTRXFo_dSidSi_dSi_XFo_lTSiSi__dSi_

@slavapestov, you've been looking at things like this...

@slavapestov
Copy link
Member

I believe in this case it's actually Sema producing invalid AST, which blows up SILGen.

@belkadan
Copy link
Contributor

belkadan commented Jan 6, 2017

Oh, yeah, sorry, I didn't mean it was SILGen's fault, just general things around tuples in closures.

@slavapestov
Copy link
Member

Tentatively assigning to @xedin since he's looking at some related issues. Feel free to re-assign 🙂

@xedin
Copy link
Member

xedin commented Jan 6, 2017

@slavapestov Thanks! 🙂

@rudkx
Copy link
Member

rudkx commented Jan 9, 2017

Fixed on master with this merge: c04c6c9

Please confirm with a build that has this fix in it and close the issue if you agree the issue is fixed.

@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

6 participants