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-12819] Bundle(for: type(of: self)) Segfaults swift if self is a struct #55265

Open
swift-ci opened this issue May 14, 2020 · 1 comment
Open
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

Previous ID SR-12819
Radar None
Original Reporter frankus (JIRA User)
Type Bug
Environment

Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)

Target: x86_64-apple-darwin19.4.0

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

md5: dd33f0356817ca47cc66d8f079c436ed

Issue Description:

Attempting to compile the following will cause the swift compiler to segfault. Obviously the code is invalid but it seems like this should be an error and not a crash.

```
import Foundation

struct Test {
func crashSwiftCompiler() {
let foo = Bundle(for: type(of: self))
}
}
```
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test

  1. Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
  2. While evaluating request TypeCheckSourceFileRequest(source_file "test.swift", 0)
  3. While evaluating request TypeCheckFunctionBodyUntilRequest(test.(file).Test.crashSwiftCompiler()@test.swift:4:10, )
  4. While type-checking 'crashSwiftCompiler()' (at test.swift:4:5)
  5. While type-checking statement at [test.swift:4:31 - line:6:5] RangeText="{
    let foo = Bundle(for: type(of: self))
    "
  6. While type-checking declaration 0x7fb029099198 (at test.swift:5:9)
  7. While evaluating request PatternBindingEntryRequest((unknown decl), 0)
  8. While type-checking expression at [test.swift:5:19 - line:5:45] RangeText="Bundle(for: type(of: self)"
    0 swift 0x000000010f8d74ea PrintStackTraceSignalHandler(void*) + 42
    1 swift 0x000000010f8d6cc0 SignalHandler(int) + 352
    2 libsystem_platform.dylib 0x00007fff701f15fd _sigtramp + 29
    3 libsystem_platform.dylib 000000000000000000 _sigtramp + 2413881888
    4 swift 0x000000010c0fe6ee swift::constraints::MissingConformance::diagnose(bool) const + 382
    5 swift 0x000000010c0450c9 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::Expr*, swift::Type, bool, bool) + 5849
    6 swift 0x000000010c2085c9 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 1033
    7 swift 0x000000010c20b3b5 swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 1029
    8 swift 0x000000010c20c3d2 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 210
    9 swift 0x000000010c2c3eea swift::SimpleRequest<swift::PatternBindingEntryRequest, swift::PatternBindingEntry const* (swift::PatternBindingDecl*, unsigned int), (swift::CacheKind)2>::evaluateRequest(swift::PatternBindingEntryRequest const&, swift::Evaluator&) + 698
    10 swift 0x000000010c21d4ac llvm::Expected<swift::PatternBindingEntryRequest::OutputType> swift::Evaluator::getResultUncached<swift::PatternBindingEntryRequest>(swift::PatternBindingEntryRequest const&) + 524
    11 swift 0x000000010c21d207 swift::PatternBindingEntryRequest::OutputType swift::evaluateOrDefault<swift::PatternBindingEntryRequest>(swift::Evaluator&, swift::PatternBindingEntryRequest, swift::PatternBindingEntryRequest::OutputType) + 55
    12 swift 0x000000010c23a7b2 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 2930
    13 swift 0x000000010c2d7711 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 8577
    14 swift 0x000000010c2d4f29 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 121
    15 swift 0x000000010c2cce7f swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 2879
    16 swift 0x000000010c2d36ee swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 718
    17 swift 0x000000010c30224e swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*, unsigned int) const + 6270
    18 swift 0x000000010c2d16c7 swift::SimpleRequest<swift::TypeCheckSourceFileRequest, bool (swift::SourceFile*, unsigned int), (swift::CacheKind)2>::evaluateRequest(swift::TypeCheckSourceFileRequest const&, swift::Evaluator&) + 23
    19 swift 0x000000010c2ffb4e swift::performTypeChecking(swift::SourceFile&, unsigned int) + 1006
    20 swift 0x000000010b933bcb swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 5915
    21 swift 0x000000010b61fd99 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 10281
    22 swift 0x000000010b5a0f53 main + 1283
    23 libdyld.dylib 0x00007fff6fff8cc9 start + 1
    24 libdyld.dylib 0x000000000000000b start + 2415948611
    Segmentation fault: 11
@theblixguy
Copy link
Collaborator

No longer crashes on master. You get the following error:

error: cannot convert value of type 'Test.Type' to expected argument type 'AnyClass' (aka 'AnyObject.Type')
    let foo = Bundle(for: type(of: self))
                          ^

Please verify using the latest trunk snapshot and close this ticket.

@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

3 participants