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-13862] Crash on trying to use guard statement in function builder #56260

Closed
krzyzanowskim opened this issue Nov 16, 2020 · 2 comments
Closed

[SR-13862] Crash on trying to use guard statement in function builder #56260

krzyzanowskim opened this issue Nov 16, 2020 · 2 comments

Comments

@krzyzanowskim
Copy link
Contributor

@krzyzanowskim krzyzanowskim commented Nov 16, 2020

Previous ID SR-13862
Radar rdar://problem/71447054
Original Reporter @krzyzanowskim
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin20.1.0

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

md5: bb3d4d91848e0d25977be812815fd4d6

Issue Description:

The sample code below crashes the swiftc, but it should rather emit an error that the guard statement is not allowed here.

import SwiftUI

struct PositionModifier: ViewModifier {
    private var pos: CGPoint? = .zero

    @ViewBuilder
    func body(content: Content) -> some View {
        guard let position = pos else {
            content
        }
        
        content.position(x: position.x, y: position.y)
    }
}
3.  While evaluating request SILGenSourceFileRequest(SIL Generation for file "/REDACTED/PositionModifier.swift")
4.  While emitting SIL for 'body(content:)' (at /REDACTED/PositionModifier.swift:15:5)
5.  While silgen emitFunction SIL function "@$s4REDACTED16PositionModifierV4body7contentQr7SwiftUI05_ViewC8_ContentVyACG_tF".
 for 'body(content:)' (at /REDACTED/PositionModifier.swift:15:5)
0  swift                    0x0000000110a3ec15 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000110a3f332 SignalHandler(int) + 610
2  libsystem_platform.dylib 0x00007fff2037fd7d _sigtramp + 29
3  libsystem_platform.dylib 0x0000000000000009 _sigtramp + 18446603339975623337
4  swift                    0x000000010c7b215f swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 447
5  swift                    0x000000010c7b2ee0 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 3904
6  swift                    0x000000010c7b2127 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 391
7  swift                    0x000000010c75a474 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 548
8  swift                    0x000000010c6ae554 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1428
9  swift                    0x000000010c7c4276 swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 118
10 swift                    0x000000010c7bf98b (anonymous namespace)::SILGenType::emitType() + 427
11 swift                    0x000000010c6b8e02 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
12 swift                    0x000000010c6b7129 (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 1417
13 swift                    0x000000010c6b6ae9 swift::SILGenSourceFileRequest::evaluate(swift::Evaluator&, swift::SILGenDescriptor) const + 137
14 swift                    0x000000010c7b1a81 swift::SimpleRequest<swift::SILGenSourceFileRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::SILGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::SILGenSourceFileRequest const&, swift::Evaluator&) + 33
15 swift                    0x000000010c6bd89c llvm::Expected<swift::SILGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::SILGenSourceFileRequest>(swift::SILGenSourceFileRequest const&) + 988
16 swift                    0x000000010c6b897d swift::performSILGeneration(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 173
17 swift                    0x000000010c246578 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21224
18 swift                    0x000000010c1c72c1 main + 1265
19 libdyld.dylib            0x00007fff20356631 start + 1
error: Segmentation fault: 11 (in target 'macOS' from project 'REDACTED')
@typesanitizer
Copy link

@typesanitizer typesanitizer commented Nov 16, 2020

@swift-ci create

@xedin
Copy link
Member

@xedin xedin commented Nov 20, 2020

Looks like this issue has been fixed on main, compiler would produce following diagnostic:

error: closure containing control flow statement cannot be used with result builder 'ViewBuilder'
        guard let position = pos else {
        ^
SwiftUI.ViewBuilder:2:30: note: struct 'ViewBuilder' declared here
@resultBuilder public struct ViewBuilder {
                             ^

@krzyzanowskim please use the most recent toolchain of main branch from swift.org to verify and close.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants