swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

[SR-12443] Xcode 11.4 regression: Segfault when overriding property with property wrapper #54882

Closed swift-ci closed 4 years ago

swift-ci commented 4 years ago
Previous ID SR-12443
Radar rdar://problem/61090634
Original Reporter ekazakov (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment Xcode 11.3.1 (11C505) and Xcode 11.4 (11E146) on macOS 10.15.4 (19E266)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, PropertyWrappers, TypeChecker | |Assignee | @hamishknight | |Priority | Medium | md5: 448e4682aa0e24d560d0b263ae860229

is duplicated by:

Issue Description:

Compiler crashes when trying to compile our project using release version of Xcode 11.4.
This is a Swift 5.2 regression. It does not happen on Swift 5.1.3
Reduced code that's causing crash to this:
crash.swift

@propertyWrapper
struct Wrapper {
    var wrappedValue: Int
}

class Someclass {
    @Wrapper var property: Int = 0
}

class Somesubclass: Someclass {
    override var property: Int {
        didSet {
            print("Subclass")
        }
    }
}

With Xcode 11.3.1 selected compiles successfully:

➜  swift --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.4.0
➜  swiftc crash.swift
➜ 

With Xcode 11.4 selected does not:

➜  swiftc --version
Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0
➜  swiftc crash.swift
(derived_to_base_expr implicit type='@lvalue Someclass'
  (super_ref_expr implicit type='Someclass'))
Stack dump:
0.  Program arguments: /Applications/Xcode11.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file crash.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode11.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name crash -o /var/folders/xb/j6xtpswj69d7v90r28yrk1j40000gn/T/crash-7b085d.o
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While emitting SIL for setter for property (at crash.swift:12:18)
3.  While silgen emitFunction SIL function "@$s5crash12SomesubclassC8propertySivs".
 for setter for property (at crash.swift:12:18)
0  swift                    0x0000000110d224ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000110d21cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6e9605fd _sigtramp + 29
3  libsystem_malloc.dylib   0x00007fff6e921385 szone_size + 45
4  swift                    0x000000010cf3ee2e 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) + 13006
5  swift                    0x000000010cf3f114 SILGenLValue::visitRec(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions, swift::Lowering::AbstractionPattern) + 260
6  swift                    0x000000010cf3e56c 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) + 10764
7  swift                    0x000000010cf3ba52 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 34
8  swift                    0x000000010cef32de swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 318
9  swift                    0x000000010cee70a8 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 280
10 swift                    0x000000010ce920ed swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 109
11 swift                    0x000000010cf7038b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 443
12 swift                    0x000000010cf22fdf swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 799
13 swift                    0x000000010ce891b9 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 953
14 swift                    0x000000010cf84a18 void llvm::function_ref<void (swift::AccessorDecl*)>::callback_fn<(anonymous namespace)::SILGenType::visitAccessors(swift::AbstractStorageDecl*)::'lambda'(swift::AccessorDecl*)>(long, swift::AccessorDecl*) + 24
15 swift                    0x000000010da8f1a5 swift::AbstractStorageDecl::visitExpectedOpaqueAccessors(llvm::function_ref<void (swift::AccessorKind)>) const + 741
16 swift                    0x000000010cf849c6 (anonymous namespace)::SILGenType::visitVarDecl(swift::VarDecl*) + 2022
17 swift                    0x000000010cf8145b (anonymous namespace)::SILGenType::emitType() + 939
18 swift                    0x000000010ce935e2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
19 swift                    0x000000010ce927ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
20 swift                    0x000000010ce9482e swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438
21 swift                    0x000000010ca74657 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48055
22 swift                    0x000000010c9ec4d3 main + 1283
23 libdyld.dylib            0x00007fff6e767cc9 start + 1
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: compile command failed due to signal 4 (use -v to see invocation)
➜ 
slavapestov commented 4 years ago

@swift-ci create

theblixguy commented 4 years ago

On master:

Assertion failed: (!isLValue), function buildSelfReference, file /Users/suyashsrijan/Documents/swift-src/swift/lib/Sema/CodeSynthesis.cpp, line 55.
Stack dump:
0.  Program arguments: ./swiftc -frontend -typecheck -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk /Users/suyashsrijan/Desktop/test.swift
1.  Swift version 5.3-dev (LLVM 223e844e4d, Swift af9b7ce902)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/suyashsrijan/Desktop/test.swift")
3.  While evaluating request TypeCheckFunctionBodyUntilRequest(test.(file).Somesubclass._@/Users/suyashsrijan/Desktop/test.swift:12:18, )
4.  While evaluating request ParseAbstractFunctionBodyRequest(test.(file).Somesubclass._@/Users/suyashsrijan/Desktop/test.swift:12:18)
0  swiftc                   0x000000010e0b7ba5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swiftc                   0x000000010e0b6de5 llvm::sys::RunSignalHandlers() + 85
2  swiftc                   0x000000010e0b818c SignalHandler(int) + 268
3  libsystem_platform.dylib 0x00007fff6431542d _sigtramp + 29
4  swiftc                   0x00000001109a1520 cmark_strbuf__initbuf + 170864
5  libsystem_c.dylib        0x00007fff641eaa1c abort + 120
6  libsystem_c.dylib        0x00007fff641e9cd6 err + 0
7  swiftc                   0x000000010e4aeb81 swift::buildSelfReference(swift::VarDecl*, swift::SelfAccessorKind, bool, swift::ASTContext&) (.cold.1) + 33
8  swiftc                   0x000000010ab56840 swift::buildArgumentForwardingExpr(llvm::ArrayRef<swift::ParamDecl*>, swift::ASTContext&) + 0
9  swiftc                   0x000000010acbb8a7 buildStorageReference(swift::AccessorDecl*, swift::AbstractStorageDecl*, (anonymous namespace)::TargetImpl, bool, swift::ASTContext&) + 1255
10 swiftc                   0x000000010acbcbf0 synthesizeObservedSetterBody(swift::AccessorDecl*, (anonymous namespace)::TargetImpl, swift::ASTContext&) + 304
11 swiftc                   0x000000010acba75e synthesizeAccessorBody(swift::AbstractFunctionDecl*, void*) + 3118
12 swiftc                   0x000000010ae0ab56 swift::ParseAbstractFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 86
13 swiftc                   0x000000010ae0b5d1 swift::SimpleRequest<swift::ParseAbstractFunctionBodyRequest, swift::BraceStmt* (swift::AbstractFunctionDecl*), (swift::CacheKind)2>::evaluateRequest(swift::ParseAbstractFunctionBodyRequest const&, swift::Evaluator&) + 17
14 swiftc                   0x000000010af8953a llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::ParseAbstractFunctionBodyRequest>(swift::ParseAbstractFunctionBodyRequest const&) + 458
15 swiftc                   0x000000010af89250 llvm::Expected<swift::ParseAbstractFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::ParseAbstractFunctionBodyRequest, (void*)0>(swift::ParseAbstractFunctionBodyRequest const&) + 64
16 swiftc                   0x000000010af35db5 swift::ParseAbstractFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::ParseAbstractFunctionBodyRequest>(swift::Evaluator&, swift::ParseAbstractFunctionBodyRequest, swift::ParseAbstractFunctionBodyRequest::OutputType) + 37
17 swiftc                   0x000000010acabf4f swift::TypeCheckFunctionBodyUntilRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*, swift::SourceLoc) const + 175
18 swiftc                   0x000000010aca9205 swift::SimpleRequest<swift::TypeCheckFunctionBodyUntilRequest, bool (swift::AbstractFunctionDecl*, swift::SourceLoc), (swift::CacheKind)1>::evaluateRequest(swift::TypeCheckFunctionBodyUntilRequest const&, swift::Evaluator&) + 21
19 swiftc                   0x000000010acb3151 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyUntilRequest>(swift::TypeCheckFunctionBodyUntilRequest const&) + 497
20 swiftc                   0x000000010acb2ce1 llvm::Expected<swift::TypeCheckFunctionBodyUntilRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyUntilRequest, (void*)0>(swift::TypeCheckFunctionBodyUntilRequest const&) + 129
21 swiftc                   0x000000010acacb09 swift::TypeCheckFunctionBodyUntilRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyUntilRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyUntilRequest, swift::TypeCheckFunctionBodyUntilRequest::OutputType) + 41
22 swiftc                   0x000000010acabe32 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 66
23 swiftc                   0x000000010acdb568 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 520
24 swiftc                   0x000000010aca9441 swift::SimpleRequest<swift::TypeCheckSourceFileRequest, bool (swift::SourceFile*), (swift::CacheKind)2>::evaluateRequest(swift::TypeCheckSourceFileRequest const&, swift::Evaluator&) + 17
25 swiftc                   0x000000010acdd456 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 454
26 swiftc                   0x000000010acdd1b8 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 56
27 swiftc                   0x000000010acdb265 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 37
28 swiftc                   0x000000010a0adc0e swift::CompilerInstance::parseAndTypeCheckMainFileUpTo(swift::SourceFile::ASTStage_t) + 286
29 swiftc                   0x000000010a0accf7 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 359
30 swiftc                   0x000000010a0ac738 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 520
31 swiftc                   0x0000000109fb95dd performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 1933
32 swiftc                   0x0000000109fb7e71 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3553
33 swiftc                   0x0000000109f50a4d main + 861
34 libdyld.dylib            0x00007fff6411c7fd start + 1
hamishknight commented 4 years ago

Resolved by https://github.com/apple/swift/pull/30792, please verify using the next available development snapshot from https://swift.org/download/#snapshots.

swift-ci commented 4 years ago

Comment by Evgeny Kazakov (JIRA)

Checked on swift-DEVELOPMENT-SNAPSHOT-2020-04-07-a-osx. It appears to be fixed. Thank you.