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-12590] SILGen crash on existential callAsFunction #55035

Closed
dabrahams opened this issue Apr 15, 2020 · 1 comment
Closed

[SR-12590] SILGen crash on existential callAsFunction #55035

dabrahams opened this issue Apr 15, 2020 · 1 comment
Assignees
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

@dabrahams
Copy link
Collaborator

Previous ID SR-12590
Radar None
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @hamishknight
Priority Medium

md5: 965f2486fddad02a60d4c9d0354cf9a7

Issue Description:

This is intended to be test/SILGen/call_as_function_existential.swift. When the test runs, the compiler crashes as shown below. If you replace f() with f.callAsFunction() the test passes.

// RUN: %target-swift-emit-silgen -module-name call_as_function_existential %s | %FileCheck %s
protocol P4 {
  func callAsFunction()
}

// CHECK-LABEL: sil hidden [ossa] @$s4main1QV1g1fyAA2P4_p_tF : $@convention(method) (@in_guaranteed P4, Q) -> () {
// CHECK: [[_4:%[0-9]+]] = open_existential_addr immutable_access [[_0:%[0-9]+]] : $*P4 to $*[[OPENED:@opened(.*) P4]]
// CHECK-NEXT: [[_5:%[0-9]+]] = witness_method $[[OPENED]], #P4.callAsFunction : <Self where Self : P4> (Self) -> () -> (), [[_4]] : $*[[OPENED]] : $@convention(witness_method: P4) <τ_0_0 where τ_0_0 : P4> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT: [[_6:%[0-9]+]] = apply [[_5]]<[[OPENED]]>(%4) : $@convention(witness_method: P4) <τ_0_0 where τ_0_0 : P4> (@in_guaranteed τ_0_0) -> ()
// CHECK-NEXT: [[_7:%[0-9]+]] = tuple ()
// CHECK-NEXT: return [[_7]] : $()
struct Q {
  func g(f: P4)  {
    f()
  }
}
0.  Program arguments: /Users/dabrahams/src/s/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swiftc -frontend -target x86_64-apple-macosx10.9 -module-cache-path /Users/dabrahams/src/s/build/Ninja-DebugAssert/swift-macosx-x86_64/swift-test-results/x86_64-apple-macosx10.9/clang-module-cache -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -swift-version 4 -ignore-module-source-info -typo-correction-limit 10 -emit-silgen -verify-syntax-tree -module-name call_as_function_existential /Users/dabrahams/src/s/swift/test/SILGen/call_as_function_existential.swift 
1.  Swift version 5.3-dev (LLVM ef37f13443, Swift 802aaefba4)
2.  While evaluating request SILGenWholeModuleRequest(SIL Generation for module call_as_function_existential)
3.  While emitting SIL for 'g(f:)' (at /Users/dabrahams/src/s/swift/test/SILGen/call_as_function_existential.swift:13:3)
4.  While silgen emitFunction SIL function "@$s28call_as_function_existential1QV1g1fyAA2P4_p_tF".
 for 'g(f:)' (at /Users/dabrahams/src/s/swift/test/SILGen/call_as_function_existential.swift:13:3)
0  swiftc                   0x000000011592f02a llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 58
1  swiftc                   0x000000011592f569 PrintStackTraceSignalHandler(void*) + 25
2  swiftc                   0x000000011592d64b llvm::sys::RunSignalHandlers() + 123
3  swiftc                   0x0000000115932789 SignalHandler(int) + 249
4  libsystem_platform.dylib 0x00007fff6da6f5fd _sigtramp + 29
5  libsystem_platform.dylib 0x00007ffee46eaff8 _sigtramp + 18446744071407385112
6  swiftc                   0x000000010e297bce swift::ApplyExpr::getArg() const + 30
7  swiftc                   0x000000010c16a64f (anonymous namespace)::SILGenApply::processProtocolMethod(swift::DeclRefExpr*, swift::AbstractFunctionDecl*, swift::ProtocolDecl*) + 79
8  swiftc                   0x000000010c16833b (anonymous namespace)::SILGenApply::visitDeclRefExpr(swift::DeclRefExpr*) + 683
9  swiftc                   0x000000010c165049 swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(swift::Expr*) + 329
10 swiftc                   0x000000010c163044 (anonymous namespace)::SILGenApply::decompose(swift::ApplyExpr*) + 244
11 swiftc                   0x000000010c146884 (anonymous namespace)::CallEmission::forApplyExpr(swift::Lowering::SILGenFunction&, swift::ApplyExpr*) + 116
12 swiftc                   0x000000010c1467cf swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 63
13 swiftc                   0x000000010c227b47 (anonymous namespace)::RValueEmitter::visitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 55
14 swiftc                   0x000000010c227bb7 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitSelfApplyExpr(swift::SelfApplyExpr*, swift::Lowering::SGFContext) + 87
15 swiftc                   0x000000010c211e47 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitDotSyntaxCallExpr(swift::DotSyntaxCallExpr*, swift::Lowering::SGFContext) + 87
16 swiftc                   0x000000010c1f94b9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4665
17 swiftc                   0x000000010c227851 (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16::operator()(swift::Expr*) const + 65
18 swiftc                   0x000000010c22779f swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16)::'lambda'(swift::Expr*)::operator()(swift::Expr*) const + 47
19 swiftc                   0x000000010c227760 void llvm::function_ref<void (swift::Expr*)>::callback_fn<swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16)::'lambda'(swift::Expr*)>(long, swift::Expr*) + 48
20 swiftc                   0x000000010c1f671c llvm::function_ref<void (swift::Expr*)>::operator()(swift::Expr*) const + 60
21 swiftc                   0x000000010c1f661c swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 716
22 swiftc                   0x000000010c2275d9 swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16) + 137
23 swiftc                   0x000000010c21169d (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext) + 269
24 swiftc                   0x000000010c1f92cd swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4173
25 swiftc                   0x000000010c1e9954 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 196
26 swiftc                   0x000000010c1ee3b2 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 66
27 swiftc                   0x000000010c169e29 (anonymous namespace)::SILGenApply::visitExpr(swift::Expr*) + 121
28 swiftc                   0x000000010c1692d3 swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visitOpenExistentialExpr(swift::OpenExistentialExpr*) + 35
29 swiftc                   0x000000010c165447 swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(swift::Expr*) + 1351
30 swiftc                   0x000000010c163044 (anonymous namespace)::SILGenApply::decompose(swift::ApplyExpr*) + 244
31 swiftc                   0x000000010c146884 (anonymous namespace)::CallEmission::forApplyExpr(swift::Lowering::SILGenFunction&, swift::ApplyExpr*) + 116
32 swiftc                   0x000000010c1467cf swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 63
33 swiftc                   0x000000010c227b47 (anonymous namespace)::RValueEmitter::visitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 55
34 swiftc                   0x000000010c211c87 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visitCallExpr(swift::CallExpr*, swift::Lowering::SGFContext) + 87
35 swiftc                   0x000000010c1f9371 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 4337
36 swiftc                   0x000000010c1e9954 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 196
37 swiftc                   0x000000010c1ef1e0 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 2144
38 swiftc                   0x000000010c31559d (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 1581
39 swiftc                   0x000000010c3119e9 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 89
40 swiftc                   0x000000010c31194d swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 45
41 swiftc                   0x000000010c244b09 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 729
42 swiftc                   0x000000010c11f8f4 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_3::operator()(swift::SILFunction*) const + 516
43 swiftc                   0x000000010c103525 void emitOrDelayFunction<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_3>(swift::Lowering::SILGenModule&, swift::SILDeclRef, swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_3&&, bool) + 885
44 swiftc                   0x000000010c100510 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 672
45 swiftc                   0x000000010c3372f4 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) + 36
46 swiftc                   0x000000010c3365ac swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 1180
47 swiftc                   0x000000010c32d738 (anonymous namespace)::SILGenType::emitType() + 456
48 swiftc                   0x000000010c32d53a swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 42
49 swiftc                   0x000000010c1168d3 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visitStructDecl(swift::StructDecl*) + 35
50 swiftc                   0x000000010c115372 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 226
51 swiftc                   0x000000010c10b4c7 (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 231
52 swiftc                   0x000000010c10b822 swift::SILGenWholeModuleRequest::evaluate(swift::Evaluator&, swift::SILGenDescriptor) const + 370
53 swiftc                   0x000000010c310d55 std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > swift::SimpleRequest<swift::SILGenWholeModuleRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::SILGenDescriptor), (swift::RequestFlags)1>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 133
54 swiftc                   0x000000010c310c27 swift::SimpleRequest<swift::SILGenWholeModuleRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> > (swift::SILGenDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::SILGenWholeModuleRequest const&, swift::Evaluator&) + 39
55 swiftc                   0x000000010c131446 llvm::Expected<swift::SILGenWholeModuleRequest::OutputType> swift::Evaluator::getResultUncached<swift::SILGenWholeModuleRequest>(swift::SILGenWholeModuleRequest const&) + 406
56 swiftc                   0x000000010c10bca7 llvm::Expected<swift::SILGenWholeModuleRequest::OutputType> swift::Evaluator::operator()<swift::SILGenWholeModuleRequest, (void*)0>(swift::SILGenWholeModuleRequest const&) + 71
57 swiftc                   0x000000010c10bab2 swift::performSILGeneration(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&) + 130
58 swiftc                   0x000000010b66fdf1 performCompileStepsPostSema(swift::CompilerInvocation const&, swift::CompilerInstance&, bool, int&, swift::FrontendObserver*) + 465
59 swiftc                   0x000000010b6651b4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 1668
60 swiftc                   0x000000010b663cb2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2226
61 swiftc                   0x000000010b50de77 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 263
62 swiftc                   0x000000010b50d139 main + 2009
63 libdyld.dylib            0x00007fff6d876cc9 start + 1
64 libdyld.dylib            0x0000000000000012 start + 18446603338678571850
FileCheck error: '-' is empty.
FileCheck command line:  /Users/dabrahams/src/s/build/Ninja-DebugAssert/llvm-macosx-x86_64/bin/FileCheck /Users/dabrahams/src/s/swift/test/SILGen/call_as_function_existential.swift
@hamishknight
Copy link
Collaborator

Fixed by #31107 and cherry-picked to 5.3 #31211

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

No branches or pull requests

3 participants