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-6506] misusing withoutActuallyEscaping crashes the compiler #49056

Closed
ahti opened this issue Nov 30, 2017 · 5 comments
Closed

[SR-6506] misusing withoutActuallyEscaping crashes the compiler #49056

ahti opened this issue Nov 30, 2017 · 5 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

@ahti
Copy link
Contributor

ahti commented Nov 30, 2017

Previous ID SR-6506
Radar rdar://problem/35773761
Original Reporter @ahti
Type Bug
Status Closed
Resolution Done
Environment
$ swift --version
Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee None
Priority Medium

md5: 168d8f67664f90698b3bdbdcff87bbe3

Issue Description:

I misunderstood how to use withoutActuallyEscaping at first, and thus discovered that the following line crashes the compiler/sourcekit:

let b: () -> Void = withoutActuallyEscaping({ print("hello crash") }, do: { $0() })

This is the crash stack trace:

0  swift                    0x00000001106f758a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001106f69c6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff7e531f5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007f9fb2804740 _sigtramp + 875374592
4  swift                    0x000000010e279d5b swift::GenericSignature::enumeratePairedRequirements(llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>) const::$_4::operator()(swift::CanType) const + 315
5  swift                    0x000000010e279a9e swift::GenericSignature::enumeratePairedRequirements(llvm::function_ref<bool (swift::Type, llvm::ArrayRef<swift::Requirement>)>) const + 974
6  swift                    0x000000010e2df1e6 swift::GenericFunctionType::substGenericArgs(llvm::ArrayRef<swift::Substitution>) + 150
7  swift                    0x000000010d8d7925 swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(swift::Expr*) + 6021
8  swift                    0x000000010d8da8d4 (anonymous namespace)::SILGenApply::visitApplyExpr(swift::ApplyExpr*) + 2644
9  swift                    0x000000010d8c84fb prepareApplyExpr(swift::Lowering::SILGenFunction&, swift::Expr*) + 219
10 swift                    0x000000010d920e0b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 91
11 swift                    0x000000010d920a44 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 148
12 swift                    0x000000010d910bc6 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 198
13 swift                    0x000000010d8c233f swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 559
14 swift                    0x000000010d8c141b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1115
15 swift                    0x000000010d8c2df2 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 914
16 swift                    0x000000010d053a94 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13044
17 swift                    0x000000010d04ef34 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
18 swift                    0x000000010d003bb8 main + 12248
19 libdyld.dylib            0x00007fff7e2b1145 start + 1
20 libdyld.dylib            0x000000000000000a start + 2178215622
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret crash.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name crash
fish: 'swift crash.swift' terminated by signal SIGSEGV (Address boundary error)
@belkadan
Copy link
Contributor

With assertions:

Assertion failed: (value != OpenExistentials.end() && "didn't see this OVE in a containing OpenExistentialExpr?"), function walkToExprPre, file /Volumes/Data/swift-public/swift/lib/Sema/CSDiag.cpp, line 2113.
0  swift                    0x000000010c17e9b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010c17d906 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010c17ef7e SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff62e77f5a _sigtramp + 26
4  swift                    0x0000000109e6ff7f swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 8351
5  libsystem_c.dylib        0x00007fff62ca2312 abort + 127
6  libsystem_c.dylib        0x00007fff62c6a368 basename_r + 0
7  swift                    0x0000000109acb336 eraseOpenedExistentials(swift::Expr*&, swift::constraints::ConstraintSystem&)::ExistentialEraser::walkToExprPre(swift::Expr*) + 406
8  swift                    0x0000000109e71ee1 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 161
9  swift                    0x0000000109e6f99b swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 6843
10 swift                    0x0000000109e6d1b4 swift::Expr::walk(swift::ASTWalker&) + 84
11 swift                    0x0000000109ac7e1e eraseOpenedExistentials(swift::Expr*&, swift::constraints::ConstraintSystem&) + 110
12 swift                    0x0000000109ac76d5 (anonymous namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, swift::Type, swift::ContextualTypePurpose, swift::OptionSet<TCCFlags, unsigned int>, swift::ExprTypeCheckListener*, bool) + 1365
13 swift                    0x0000000109abe542 (anonymous namespace)::FailureDiagnosis::diagnoseContextualConversionError(swift::Expr*, swift::Type, swift::ContextualTypePurpose) + 98
14 swift                    0x0000000109ad9115 (anonymous namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 1333
15 swift                    0x0000000109abd1b3 swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 83
16 swift                    0x0000000109ac2492 swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::Expr*) + 3986
17 swift                    0x0000000109ba06e8 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>) + 120
18 swift                    0x0000000109ba3a46 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 678
19 swift                    0x0000000109ba796d swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*, bool) + 429
20 swift                    0x0000000109ba7c97 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) + 263
21 swift                    0x0000000109bbae18 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 472
22 swift                    0x0000000109bbac34 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 100
23 swift                    0x0000000109c28aec swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 444
24 swift                    0x0000000109c2852c swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 140
25 swift                    0x0000000109c4899f swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int) + 1567
26 swift                    0x00000001098dba43 swift::CompilerInstance::parseAndTypeCheckMainFile(swift::PersistentParserState&, swift::DelayedParsingCallbacks*, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>) + 435
27 swift                    0x00000001098da91e swift::CompilerInstance::parseAndCheckTypes(swift::CompilerInstance::ImplicitImports const&) + 702
28 swift                    0x00000001098da0e8 swift::CompilerInstance::performSema() + 520
29 swift                    0x0000000108e31455 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1781
30 swift                    0x0000000108e2fe2a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3290
31 swift                    0x0000000108df0680 main + 3328
32 libdyld.dylib            0x00007fff62bf6115 start + 1
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin17.3.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--c13637.o 
1.  While type-checking declaration 0x7fab158839b0 at <stdin>:1:1
2.  While type-checking expression at [<stdin>:1:21 - line:1:83] RangeText="withoutActuallyEscaping({ print("hello crash") }, do: { $0() })"

@belkadan
Copy link
Contributor

@swift-ci create

@belkadan
Copy link
Contributor

Pavel fixed this in Swift 4.2: #15462

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Aug 4, 2018

@ahti, Could you verify if the problem is fixed and if so move the JIRA to "Closed"?
Thanks!
Anna

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Sep 13, 2018

Lukas Stabe, Could you verify if the problem is fixed and/or move the JIRA to "Closed"?
Thanks!
Anna

@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