Skip to content

Compiler crash on parenthesized try expression #73244

@sarahcantohyatt

Description

@sarahcantohyatt

Description

Compiler crashes on certain cases of parenthesized try expressions.

Reproduction

class Class {
  var num: Int = 1

  init() throws {}
}

_ = (try Class().num)

Stack dump

error: compile command failed due to signal 5 (use -v to see invocation)
(load_expr implicit type='Int' location=test.swift:7:18 range=[test.swift:7:10 - line:7:18]
  (member_ref_expr type='@lvalue Int' location=test.swift:7:18 range=[test.swift:7:10 - line:7:18] decl=test.(file).Class.num@test.swift:2:7
    (call_expr type='Class' location=test.swift:7:10 range=[test.swift:7:10 - line:7:16] throws isolationCrossing=none
      (constructor_ref_call_expr type='() throws -> Class' location=test.swift:7:10 range=[test.swift:7:10 - line:7:10] nothrow isolationCrossing=none
        (declref_expr implicit type='(Class.Type) -> () throws -> Class' location=test.swift:7:10 range=[test.swift:7:10 - line:7:10] decl=test.(file).Class.init()@test.swift:4:3 function_ref=single)
        (argument_list implicit
          (argument
            (type_expr type='Class.Type' location=test.swift:7:10 range=[test.swift:7:10 - line:7:10] typerepr='Class'))))
      (argument_list))))
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file test.swift -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name test -disable-clang-spi -target-sdk-version 14.4 -target-sdk-name macosx14.4 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/84/w44jd9vd3vq_16ltrkkzrbz40000gn/T/TemporaryDirectory.yWXiJY/test-1.o
1.	Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "test.swift")
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000107d83f3c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107d830f8 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107d84544 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x00000001804f3a24 _sigtramp + 56
4  swift-frontend           0x0000000102d6be58 swift::ASTVisitor<SILGenLValue, swift::Lowering::LValue, void, void, void, void, void, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions>::visitLoadExpr(swift::LoadExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 52
5  swift-frontend           0x0000000102d61c84 swift::ASTVisitor<SILGenLValue, swift::Lowering::LValue, void, void, void, void, void, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions>::visit(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 11936
6  swift-frontend           0x0000000102d5ecf4 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 48
7  swift-frontend           0x0000000102d35944 (anonymous namespace)::RValueEmitter::visitLoadExpr(swift::LoadExpr*, swift::Lowering::SGFContext) + 120
8  swift-frontend           0x0000000102d1f618 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
9  swift-frontend           0x0000000102d3ee44 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 568
10 swift-frontend           0x0000000102d1f618 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
11 swift-frontend           0x0000000102dc3970 swift::ASTVisitor<swift::Lowering::SILGenTopLevel, void, void, void, void, void, void>::visit(swift::Decl*) + 1860
12 swift-frontend           0x0000000102dc25e0 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 1180
13 swift-frontend           0x0000000102ca6a48 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1400
14 swift-frontend           0x0000000102db5f1c swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 196
15 swift-frontend           0x0000000102ca9f44 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
16 swift-frontend           0x0000000102681408 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 548
17 swift-frontend           0x0000000102685694 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1448
18 swift-frontend           0x00000001026836d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4968
19 swift-frontend           0x0000000102612e8c swift::mainEntry(int, char const**) + 2612
20 dyld                     0x00000001801490e0 start + 2360
error: fatalError

Expected behavior

Compiler should compile the code or provide a meaningful error message if the usage is not allowed.

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareerror handlingexpressionsFeature: expressionsgood first issueGood for newcomersneeds testsFlag: Issue is fixed but needs tests / PR needs testsswift 5.10

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions