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-11590] Swift 5.1 Xcode 11.0: A segmentation fault when compiling a faulty program with #imageLiteral() #53995

Open
swift-ci opened this issue Oct 8, 2019 · 4 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

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 8, 2019

Previous ID SR-11590
Radar None
Original Reporter Fadi_Botros (JIRA User)
Type Bug

Attachment: Download

Environment

macOS Catalina 11.15.0

Swift 5.1

Xcode 11.0

MacBook Pro Early 2015

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee None
Priority Medium

md5: cecd57bf7e448e9960af83bb80f07a5d

Issue Description:

I tried it on a Swift Playground (environment stated), when I tried to compile something with

#imageLiteral()

It just stated an error (which is correct), and it didn't make a problem, but compiling it when inside a closure, like:

DispatchQueue.main.async {
    self.image = #imageLiteral()
}

A segmentation fault that stops the compiler happens

I couldn't extract any detailed problem, so I tried to make it in an Xcode project and replaced the main ViewController code with the code I tried, then I got this message

CompileSwift normal x86_64 /Users/.../.../.../.../.../ViewController.swift (in target '...' from project '...')
    cd /Users/.../.../.../...
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/.../.../.../.../.../ViewController.swift /Users/.../.../.../.../.../AppDelegate.swift /Users/.../.../.../.../.../SceneDelegate.swift -emit-module-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController\~partial.swiftmodule -emit-module-doc-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController\~partial.swiftdoc -serialize-diagnostics-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.dia -emit-dependencies-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.d -emit-reference-dependencies-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.swiftdeps -target x86_64-apple-ios13.0-simulator -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -I /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator -F /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/.../.../Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/.../.../.../... -enable-anonymous-context-mangled-names -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-generated-files.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-own-target-headers.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-all-target-headers.hmap -Xcc -iquote -Xcc /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-project-headers.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources-normal/x86_64 -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources/x86_64 -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources -Xcc -DDEBUG=1 -module-name ... -o /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.o -index-store-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Index/DataStore -index-system-modulesStack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/.../.../.../.../.../ViewController.swift /Users/.../.../.../.../.../AppDelegate.swift /Users/.../.../.../.../.../SceneDelegate.swift -emit-module-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController~partial.swiftmodule -emit-module-doc-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController~partial.swiftdoc -serialize-diagnostics-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.dia -emit-dependencies-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.d -emit-reference-dependencies-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.swiftdeps -target x86_64-apple-ios13.0-simulator -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk -I /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator -F /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/.../.../Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/.../.../.../... -enable-anonymous-context-mangled-names -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-generated-files.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-own-target-headers.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-all-target-headers.hmap -Xcc -iquote -Xcc /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/...-project-headers.hmap -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources-normal/x86_64 -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources/x86_64 -Xcc -I/Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/DerivedSources -Xcc -DDEBUG=1 -module-name ... -o /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Build/Intermediates.noindex/....build/Debug-iphonesimulator/....build/Objects-normal/x86_64/ViewController.o -index-store-path /Users/.../.../Developer/Xcode/DerivedData/...-gtqawbarstnanedinbklatsnishr/Index/DataStore -index-system-modules 
1.  While type-checking 'loadView()' (at /Users/.../.../.../.../.../ViewController.swift:14:14)
2.  While type-checking statement at [/Users/.../.../.../.../.../ViewController.swift:14:30 - line:29:5] RangeText="{
        let view = UIView()
        view.backgroundColor = .white        let label = UILabel()
        label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
        label.text = "Hello World!"
        label.textColor = .black        DispatchQueue.main.async {
            self.image = #imageLiteral()
        }        view.addSubview(label)
        self.view = view
    "
3.  While type-checking expression at [/Users/.../.../.../.../.../ViewController.swift:23:9 - line:25:9] RangeText="DispatchQueue.main.async {
            self.image = #imageLiteral()
        "
4.  While type-checking NULL expression!
0  swift                    0x000000010ae71eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010ae71686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff64a7cb1d _sigtramp + 29
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2606249216
4  swift                    0x00000001075ff303 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 339
5  swift                    0x0000000107601944 swift::TypeChecker::typeCheckParameterDefault(swift::Expr*&, swift::DeclContext*, swift::Type, bool, bool) + 228
6  swift                    0x0000000107463bb9 getCallerDefaultArg(swift::constraints::ConstraintSystem&, swift::DeclContext*, swift::SourceLoc, swift::ConcreteDeclRef&, unsigned int) + 2521
7  swift                    0x0000000107460c14 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) + 3572
8  swift                    0x000000010745e695 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder) + 5253
9  swift                    0x000000010745aa86 swift::TypeChecker::callWitness(swift::Expr*, swift::DeclContext*, swift::ProtocolDecl*, swift::ProtocolConformanceRef, swift::DeclName, llvm::ArrayRef<swift::Expr*>, swift::Diag<>) + 3062
10 swift                    0x000000010746d95e swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 27502
11 swift                    0x0000000107466b10 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 32
12 swift                    0x000000010797ae99 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2729
13 swift                    0x0000000107465ee6 (anonymous namespace)::ExprWalker::walkToExprPre(swift::Expr*) + 1478
14 swift                    0x000000010797a4bc swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 204
15 swift                    0x000000010797e363 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 211
16 swift                    0x00000001075ffd89 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 3033
17 swift                    0x00000001076b1b23 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 23939
18 swift                    0x00000001076abd41 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 129
19 swift                    0x00000001076ab840 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 5456
20 swift                    0x00000001076b39a1 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 561
21 swift                    0x00000001076d04a2 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2082
22 swift                    0x0000000106dcc58b swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t)::$_0::operator()(swift::SourceFile&) const + 91
23 swift                    0x0000000106dcb2eb swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5371
24 swift                    0x0000000106ac0b6f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 815
25 swift                    0x0000000106abd034 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
26 swift                    0x0000000106a4a5a3 main + 1219
27 libdyld.dylib            0x00007fff6487b405 start + 1
error: Segmentation fault: 11 (in target '...' from project '...')
@theblixguy
Copy link
Collaborator

Here's a smaller reproducer:

import UIKit

class Bar {
  var image: UIImage?
  func foo() {
    self.image = #imageLiteral()
  }
}
1.  While type-checking 'foo()' (at /Users/suyashsrijan/Documents/Playgrounds/Test/Test1234/Test1234/ViewController.swift:14:2)
2.  While type-checking statement at [/Users/suyashsrijan/Documents/Playgrounds/Test/Test1234/Test1234/ViewController.swift:14:13 - line:16:2] RangeText="{
        self.image = #imageLiteral()
    "
3.  While type-checking expression at [/Users/suyashsrijan/Documents/Playgrounds/Test/Test1234/Test1234/ViewController.swift:15:3 - line:15:30] RangeText="self.image = #imageLiteral("
4.  While type-checking NULL expression!
0  swift                    0x0000000112300eb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000112300686 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff69a23b1d _sigtramp + 29
3  swift                    0x0000000111bfc42d llvm::BitstreamCursor::readRecord(unsigned int, llvm::SmallVectorImpl<unsigned long long>&, llvm::StringRef*) + 2749
4  swift                    0x000000010ea8e123 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 339
5  swift                    0x000000010ea90764 swift::TypeChecker::typeCheckParameterDefault(swift::Expr*&, swift::DeclContext*, swift::Type, bool, bool) + 228
6  swift                    0x000000010e8f29d9 getCallerDefaultArg(swift::constraints::ConstraintSystem&, swift::DeclContext*, swift::SourceLoc, swift::ConcreteDeclRef&, unsigned int) + 2521
7  swift                    0x000000010e8efa34 (anonymous namespace)::ExprRewriter::coerceCallArguments(swift::Expr*, swift::AnyFunctionType*, swift::ApplyExpr*, llvm::ArrayRef<swift::Identifier>, bool, swift::constraints::ConstraintLocatorBuilder) + 3572
8  swift                    0x000000010e8ed4b5 (anonymous namespace)::ExprRewriter::finishApply(swift::ApplyExpr*, swift::Type, swift::constraints::ConstraintLocatorBuilder) + 5253
9  swift                    0x000000010e8e98a6 swift::TypeChecker::callWitness(swift::Expr*, swift::DeclContext*, swift::ProtocolDecl*, swift::ProtocolConformanceRef, swift::DeclName, llvm::ArrayRef<swift::Expr*>, swift::Diag<>) + 3062
10 swift                    0x000000010e8fc77e swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 27502
11 swift                    0x000000010e8f5930 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 32
12 swift                    0x000000010ee09cb9 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 2729
13 swift                    0x000000010ea8eba9 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 3033
14 swift                    0x000000010eb40943 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 23939
15 swift                    0x000000010eb3ab61 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 129
16 swift                    0x000000010eb3a660 swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*, swift::SourceLoc) + 5456
17 swift                    0x000000010eb427c1 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 561
18 swift                    0x000000010eb5f2c2 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 2082
19 swift                    0x000000010e25b3ab swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t)::$_0::operator()(swift::SourceFile&) const + 91
20 swift                    0x000000010e25a10b swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5371
21 swift                    0x000000010df4f98f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 815
22 swift                    0x000000010df4be54 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
23 swift                    0x000000010ded93c3 main + 1219
24 libdyld.dylib            0x00007fff69822405 start + 1
25 libdyld.dylib            0x000000000000004a start + 2524830790

This was with a Swift 5.1 toolchain, however on master this does not crash and I get an error:

cannot convert value of type '()' to expected argument type '(resourceName: String)'

@belkadan
Copy link
Contributor

belkadan commented Oct 9, 2019

@xedin, @hborla, do you know if anything was fixed here recently?

@xedin
Copy link
Member

xedin commented Oct 9, 2019

It looks like it has been fixed by #27063 because it used to crash in CSApply and now it produces an error instead.

@LucianoPAlmeida
Copy link
Collaborator

Hey @xedin 🙂

There is a slight variant of this that causes a bad diagnostic

![](Screen Shot 2020-06-20 at 19.53.51.png)

Should we open a new issue with this to improve the diagnostics?

Edit: 2020-06-17 master snapshot

@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
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

6 participants