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

Xcode 11.4 regression: Segfault with coverage and a ternary in a default init argument

    XMLWordPrintable

    Details

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

      Xcode 11.3.1 (11C505) and Xcode 11.4 (11E146) on macOS 10.15.4 (19E266)

      Description

      I've isolated this down as much as I can. I don't understand what all the Terminal command parameters do; I found them by grabbing the swift invocation from an Xcode project and removing as many parameters as I could while still reproducing the issue.

      crash.swift:

      enum DemoEnum {
          case foo
      }
      
      struct NewThing {
          init(foo: Double = DemoEnum.foo == .foo ? 1 : 2) {}
      }
      

      With Xcode 11.4 selected, this segfaults:

      swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping
      
      Stack dump:
      0.	Program arguments: /Applications/Xcode_11.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping 
      1.	Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
      2.	While silgen emitConstructor SIL function "@$s5crash8NewThingV3fooACSd_tcfC".
       for 'init(foo:)' (at /Users/211518/Desktop/crash.swift:7:5)
      0  swift                    0x0000000112cc94ea PrintStackTraceSignalHandler(void*) + 42
      1  swift                    0x0000000112cc8cc0 SignalHandler(int) + 352
      2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
      3  libsystem_platform.dylib 0x00007ffee12884e0 _sigtramp + 2043719424
      4  swift                    0x000000010f9f5f50 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 272
      5  swift                    0x000000010f9f90e7 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 487
      6  swift                    0x000000010f9f5e03 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 275
      7  swift                    0x000000010f3ed538 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode, swift::SILDeclRef) + 2824
      8  swift                    0x000000010ee306ca swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 778
      9  swift                    0x000000010ef2a3b1 swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 145
      10 swift                    0x000000010ef2853b (anonymous namespace)::SILGenType::emitType() + 1163
      11 swift                    0x000000010ee3a5e2 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 82
      12 swift                    0x000000010ee397ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
      13 swift                    0x000000010ee3b82e swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438
      14 swift                    0x000000010ea1b657 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48055
      15 swift                    0x000000010e9934d3 main + 1283
      16 libdyld.dylib            0x00007fff67384cc9 start + 1
      [1]    59651 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk   
      

      With Xcode 11.3.1 selected, this slightly modified command does not:

      swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping
      # [nothing printed after that, because there is no error or crash]
      

      I noticed that this slightly modified version of the code, with a global function instead of an initializer, crashes both Xcode 11.4 and 11.3.1's toolchains, but I'm not sure if it's related or separate, so please let me know if I should file a separate bug:

      enum DemoEnum {
          case foo
      }
      
      func foo(foo: Double = DemoEnum.foo == .foo ? 1 : 2) {}
      

      Xcode 11.4:

      swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping
      
      Stack dump:
      0.	Program arguments: /Applications/Xcode_11.4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk -profile-generate -profile-coverage-mapping 
      1.	Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
      2.	While emitting SIL for 'foo(foo:)' (at /Users/211518/Desktop/crash.swift:5:1)
      0  swift                    0x00000001104df4ea PrintStackTraceSignalHandler(void*) + 42
      1  swift                    0x00000001104decc0 SignalHandler(int) + 352
      2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
      3  libsystem_platform.dylib 0x00007ffee3a72f40 _sigtramp + 2085575008
      4  swift                    0x000000010d20bf50 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 272
      5  swift                    0x000000010d20f0e7 (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 487
      6  swift                    0x000000010d20be03 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 275
      7  swift                    0x000000010cc03538 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode, swift::SILDeclRef) + 2824
      8  swift                    0x000000010c645b57 setUpForProfiling(swift::SILDeclRef, swift::SILFunction*, swift::ForDefinition_t) + 119
      9  swift                    0x000000010c644a6b swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 475
      10 swift                    0x000000010c6460e7 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 743
      11 swift                    0x000000010c64f7ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
      12 swift                    0x000000010c65182e swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1438
      13 swift                    0x000000010c231657 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48055
      14 swift                    0x000000010c1a94d3 main + 1283
      15 libdyld.dylib            0x00007fff67384cc9 start + 1
      [1]    59995 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk
      

      Xcode 11.3.1:

      swift -frontend -c -primary-file ~/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping
      Stack dump:
      0.	Program arguments: /Applications/Xcode_11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/211518/Desktop/crash.swift -target x86_64-apple-ios12.0-simulator -sdk /Applications/Xcode_11.3.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -profile-generate -profile-coverage-mapping 
      1.	While emitting SIL for 'foo(foo:)' (at /Users/211518/Desktop/crash.swift:5:1)
      0  swift                    0x000000010758ca63 PrintStackTraceSignalHandler(void*) + 51
      1  swift                    0x000000010758c236 SignalHandler(int) + 358
      2  libsystem_platform.dylib 0x00007fff6757d5fd _sigtramp + 29
      3  libsystem_platform.dylib 0x0000000111d124dc _sigtramp + 2860076796
      4  swift                    0x0000000104095ea8 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::ParameterList*) + 296
      5  swift                    0x0000000104098c5a (anonymous namespace)::Traversal::visitAbstractFunctionDecl(swift::AbstractFunctionDecl*) + 426
      6  swift                    0x0000000104095d3c (anonymous namespace)::Traversal::doIt(swift::Decl*) + 284
      7  swift                    0x0000000103b1b800 swift::SILProfiler::create(swift::SILModule&, swift::ForDefinition_t, swift::ASTNode) + 2688
      8  swift                    0x00000001035c5fd3 setUpForProfiling(swift::SILDeclRef, swift::SILFunction*, swift::ForDefinition_t) + 115
      9  swift                    0x00000001035c50e3 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 467
      10 swift                    0x00000001035c66de swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 766
      11 swift                    0x00000001035d1296 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
      12 swift                    0x00000001035d2cf6 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1238
      13 swift                    0x00000001031d48f4 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 28340
      14 swift                    0x00000001031ca234 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
      15 swift                    0x0000000103157733 main + 1219
      16 libdyld.dylib            0x00007fff67384cc9 start + 1
      [1]    60047 segmentation fault  swift -frontend -c -primary-file ~/Desktop/crash.swift -target  -sdk
      

      I haven't tested on the nightly toolchain.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            igeek1@gmail.com Zev Eisenberg
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: