Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13069

Crash when using autoclosure escaping in property wrappers

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
      Target: x86_64-apple-darwin19.5.0

      Description

      When declaring a property wrapper with an autoclosure escaping block as the wrapped value like the following:

      @propertyWrapper
      public class Stored<Value> {
          public var wrappedValue: Value {
              return value()
          }
          
          public var value: () -> Value
          
          public init(wrappedValue: @autoclosure @escaping () -> Value, _ key: String) {
              value = wrappedValue
          }
      }
      
      
      struct ValueHolder {
          @Stored("test")
          var storedProperty: String = ""
      } 

      the swift compiler included in the Xcode 12 beta 1 (Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5) Target: x86_64-apple-darwin19.5.0) crashes with the following stack trace:

       Stack dump:
      0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret crash.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -target-sdk-version 10.15.4 -module-name crash 
      1.	Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
      2.	While evaluating request SILGenWholeModuleRequest(SIL Generation for module crash)
      3.	While silgen emitPropertyWrapperBackingInitializer SIL function "@$s5crash11ValueHolderV14storedPropertySSvpfP".
       for 'storedProperty' (at crash.swift:16:9)
      4.	While emitting reabstraction thunk in SIL function "@$sS2SIegr_TR".
       for <<debugloc at "<compiler-generated>":0:0>>Stack dump:
      0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret crash.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -target-sdk-version 10.15.4 -module-name crash 
      1.	Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
      2.	While evaluating request SILGenWholeModuleRequest(SIL Generation for module crash)
      3.	While silgen emitPropertyWrapperBackingInitializer SIL function "@$s5crash11ValueHolderV14storedPropertySSvpfP".
       for 'storedProperty' (at crash.swift:16:9)
      4.	While emitting reabstraction thunk in SIL function "@$sS2SIegr_TR".
       for <<debugloc at "<compiler-generated>":0:0>>0  swift                    0x000000010b9e7f65 0  swift                    0x000000010b9e7f65 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      1  swift                    0x000000010b9e6f65 llvm::sys::RunSignalHandlers() + 85
      1  swift                    0x000000010b9e6f65 llvm::sys::RunSignalHandlers() + 85
      2  swift                    0x000000010b9e851f SignalHandler(int) + 111
      3  libsystem_platform.dylib 0x00007fff6c7335fd _sigtramp + 29
      4  libsystem_platform.dylib 0000000000000000002  swift                    0x000000010b9e851f SignalHandler(int) + 111
      3  libsystem_platform.dylib 0x00007fff6c7335fd _sigtramp + 29
      4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338696673824
       _sigtramp + 18446603338696673824
      5  swift                    0x000000010810725a swift::ApplyInst::create(swift::SILDebugLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, bool, llvm::Optional<swift::SILModuleConventions>, swift::SILFunction&, swift::SILOpenedArchetypesState&, swift::GenericSpecializationInformation const*) + 362
      5  swift                    0x000000010810725a swift::ApplyInst::create(swift::SILDebugLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, bool, llvm::Optional<swift::SILModuleConventions>, swift::SILFunction&, swift::SILOpenedArchetypesState&, swift::GenericSpecializationInformation const*) + 362
      6  swift                    0x000000010799e53d swift::SILBuilder::createApply(swift::SILLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, bool, swift::GenericSpecializationInformation const*) + 237
      6  swift                    0x000000010799e53d swift::SILBuilder::createApply(swift::SILLocation, swift::SILValue, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>, bool, swift::GenericSpecializationInformation const*) + 237
      7  swift                    0x0000000107a01145 swift::Lowering::SILGenFunction::emitApplyWithRethrow(swift::SILLocation, swift::SILValue, swift::SILType, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>) + 597
      7  swift                    0x0000000107a01145 swift::Lowering::SILGenFunction::emitApplyWithRethrow(swift::SILLocation, swift::SILValue, swift::SILType, swift::SubstitutionMap, llvm::ArrayRef<swift::SILValue>) + 597
      8  swift                    0x0000000107ae4dde createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 5454
      8  swift                    0x0000000107ae4dde createThunk(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 5454
      9  swift                    0x0000000107ad7a35 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1589
      9  swift                    0x0000000107ad7a35 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) + 1589
      10 swift                    0x0000000107a51d93 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 1315
      10 swift                    0x0000000107a51d93 swift::Lowering::Conversion::emit(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::SGFContext) const + 1315
      11 swift                    0x0000000107a52d53 swift::Lowering::ConvertingInitialization::copyOrInitValueInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool) + 131
      11 swift                    0x0000000107a52d53 swift::Lowering::ConvertingInitialization::copyOrInitValueInto(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::ManagedValue, bool) + 131
      12 swift                    0x0000000107a514ec swift::Lowering::SILGenFunction::manageOpaqueValue(swift::Lowering::ManagedValue, swift::SILLocation, swift::Lowering::SGFContext) + 220
      12 swift                    0x0000000107a514ec swift::Lowering::SILGenFunction::manageOpaqueValue(swift::Lowering::ManagedValue, swift::SILLocation, swift::Lowering::SGFContext) + 220
      13 swift                    0x0000000107a8ea88 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 696
      13 swift                    0x0000000107a8ea88 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 696
      14 swift                    0x0000000107a79ad9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext)14 swift                    0x0000000107a79ad9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 121
       + 121
      15 swift                    0x00000001079da9f0 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 928
      15 swift                    0x00000001079da9f0 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 928
      16 swift                    0x0000000107a517cc swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 492
      16 swift                    0x0000000107a517cc swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 492
      17 swift                    0x0000000107a1a86c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 4124
      17 swift                    0x0000000107a1a86c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 4124
      18 swift                    0x0000000107a01f9d (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 173
      18 swift                    0x0000000107a01f9d (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 173
      19 swift                    0x0000000107a1967e (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 238
      19 swift                    0x0000000107a1967e (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 238
      20 swift                    0x0000000107a22825 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 949
      20 swift                    0x0000000107a22825 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&) + 949
      21 swift                    0x0000000107a0856f (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3935
      21 swift                    0x0000000107a0856f (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 3935
      22 swift                    0x0000000107a0572c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2652
      22 swift                    0x0000000107a0572c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 2652
      23 swift                    0x0000000107a79aa9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 73
      23 swift                    0x0000000107a79aa9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 73
      24 swift                    0x0000000107af966f swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 447
      24 swift                    0x0000000107af966f swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 447
      25 swift                    0x0000000107a9db2d swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*, bool) + 2029
      25 swift                    0x0000000107a9db2d swift::Lowering::SILGenFunction::emitGeneratorFunction(swift::SILDeclRef, swift::Expr*, bool) + 2029
      26 swift                    0x00000001079fc2fc swift::Lowering::SILGenModule::emitPropertyWrapperBackingInitializer(swift::VarDecl*)::$_10::operator()(swift::SILFunction*) const + 636
      26 swift                    0x00000001079fc2fc swift::Lowering::SILGenModule::emitPropertyWrapperBackingInitializer(swift::VarDecl*)::$_10::operator()(swift::SILFunction*) const + 636
      27 swift                    0x00000001079f465e swift::Lowering::SILGenModule::emitPropertyWrapperBackingInitializer(swift::VarDecl*) + 398
      27 swift                    0x00000001079f465e swift::Lowering::SILGenModule::emitPropertyWrapperBackingInitializer(swift::VarDecl*) + 398
      28 swift                    0x0000000107b04f6e (anonymous namespace)::SILGenType::visitVarDecl(swift::VarDecl*) + 302
      28 swift                    0x0000000107b04f6e (anonymous namespace)::SILGenType::visitVarDecl(swift::VarDecl*) + 302
      29 swift                    0x0000000107affb0b (anonymous namespace)::SILGenType::emitType() + 427
      29 swift                    0x0000000107affb0b (anonymous namespace)::SILGenType::emitType() + 427
      30 swift                    0x00000001079f92a2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
      30 swift                    0x00000001079f92a2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
      31 swift                    0x00000001079f75c9 (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 1417
      31 swift                    0x00000001079f75c9 (anonymous namespace)::SILGenModuleRAII::emitSourceFile(swift::SourceFile*) + 1417
      32 swift                    0x00000001079f8c89 swift::SILGenWholeModuleRequest::evaluate(swift::Evaluator&, swift::SILGenDescriptor) const + 185
      32 swift                    0x00000001079f8c89 swift::SILGenWholeModuleRequest::evaluate(swift::Evaluator&, swift::SILGenDescriptor) const + 185
      33 swift                    0x0000000107af1c71 33 swift                    0x0000000107af1c71 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&) + 33
      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&) + 33
      34 swift                    0x00000001079fcd0d llvm::Expected<swift::SILGenWholeModuleRequest::OutputType> swift::Evaluator::getResultUncached<swift::SILGenWholeModuleRequest>(swift::SILGenWholeModuleRequest const&) + 973
      34 swift                    0x00000001079fcd0d llvm::Expected<swift::SILGenWholeModuleRequest::OutputType> swift::Evaluator::getResultUncached<swift::SILGenWholeModuleRequest>(swift::SILGenWholeModuleRequest const&) + 973
      35 swift                    0x000000010756b6e2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21186
      35 swift                    0x000000010756b6e2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21186
      36 swift                    0x00000001074eca97 main + 1255
      37 libdyld.dylib            0x00007fff6c53acc936 swift                    0x00000001074eca97 main + 1255
      37 libdyld.dylib            0x00007fff6c53acc9 start + 1
      38 libdyld.dylib            0x000000000000000c start + 18446603338698740548
       start + 1
      38 libdyld.dylib            0x000000000000000c start + 18446603338698740548

       

      The compiler doesn't crash if the autoclosure is not escaping, or if the second parameter in the init is removed.

       

      Attached:

      • The sample swift file
      • Stack dump when running `swift crash.swift`
      • A "reproducer" while running "swift" interactively directly from the command line

        Attachments

        1. reproducer-1f6ad0.zip
          965 kB
        2. crash.swift
          0.3 kB
        3. report.txt
          15 kB

          Issue Links

            Activity

              People

              Assignee:
              pablobart Pablo Bartolome
              Reporter:
              pablobart Pablo Bartolome
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: