swiftlang / swift

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

[SR-14819] Abort trap 6. For Result builders implicit memberwise initializer #57167

Open swift-ci opened 3 years ago

swift-ci commented 3 years ago
Previous ID SR-14819
Radar rdar://problem/79747173
Original Reporter Egor Mihnevich (JIRA User)
Type Bug
Environment macOS 11.4 (20F71) Xcode Version 12.5 (12E262) Xcode Version 13.0 beta (13A5154h)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: d6a82dc581684f2e27d3e2719c342af5

Issue Description:

Using not structurally resemble function type in with an implicit memberwise initializer leads to a compilation crash:

struct Setting {}

struct SettingsGroup {
    @SettingsBuilder var settings: [Setting]
    // Instead of var settings: () -> Settings
}

@resultBuilder
enum SettingsBuilder {
    static func buildBlock(_ children: [Setting]...) -> [Setting] {
        children.flatMap { $0 }
    }

    static func buildExpression(_ expression: Setting) -> [Setting] {
        [expression]
    }

    static func buildExpression(_ expression: SettingsGroup) -> [Setting] {
        expression.settings
    }
}

func makeSettings(@SettingsBuilder _ content: () -> [Setting]) -> [Setting] {
    content()
}

makeSettings {
    SettingsGroup {
        Setting()
    }
}
IntToPtr source must be an integral
  %5 = inttoptr i8* %2 to %swift.bridge*, !dbg !317
in function $s10StarRating13SettingsGroupV4name8settingsACSS_SayAA7SettingVGyXEtcfC
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
<unknown>:0: note: Broken function found, compilation aborted!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode-12.5.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c /Users/elfenlaid/Code/temp/StarRating/StarRating/ViewController.swift -primary-file /Users/elfenlaid/Code/temp/StarRating/StarRating/AppDelegate.swift /Users/elfenlaid/Code/temp/StarRating/StarRating/SceneDelegate.swift -emit-module-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate~partial.swiftmodule -emit-module-doc-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate~partial.swiftdoc -emit-module-source-info-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate~partial.swiftsourceinfo -serialize-diagnostics-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate.dia -emit-dependencies-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate.d -emit-reference-dependencies-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate.swiftdeps -target arm64-apple-ios14.5-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-12.5.0-Release.Candidate.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk -I /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Products/Debug-iphonesimulator -F /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Products/Debug-iphonesimulator -enable-testing -g -module-cache-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/elfenlaid/Code/temp/StarRating -enable-anonymous-context-mangled-names -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/StarRating-generated-files.hmap -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/StarRating-own-target-headers.hmap -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/StarRating-all-target-headers.hmap -Xcc -iquote -Xcc /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/StarRating-project-headers.hmap -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/DerivedSources-normal/arm64 -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/DerivedSources/arm64 -Xcc -I/Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/DerivedSources -Xcc -DDEBUG=1 -target-sdk-version 14.5 -module-name StarRating -o /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Build/Intermediates.noindex/StarRating.build/Debug-iphonesimulator/StarRating.build/Objects-normal/arm64/AppDelegate.o -index-store-path /Users/elfenlaid/Library/Developer/Xcode/DerivedData/StarRating-ahspitinqdinvibqszarakkqdfxs/Index/DataStore -index-system-modules 
1.  Apple Swift version 5.4 (swiftlang-1205.0.26.9 clang-1205.0.19.55)
2.  Running pass 'Module Verifier' on function '@"$s10StarRating13SettingsGroupV4name8settingsACSS_SayAA7SettingVGyXEtcfC"'
0  swift-frontend           0x00000001090605f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 52
1  swift-frontend           0x000000010905f768 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x0000000109060bc0 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001a276ec44 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a272343c pthread_kill + 292
5  libsystem_c.dylib        0x00000001a266b460 abort + 104
6  swift-frontend           0x0000000104fa285c std::__1::__throw_length_error(char const*) + 0
7  swift-frontend           0x0000000108fcd7d8 llvm::report_fatal_error(llvm::Twine const&, bool) + 252
8  swift-frontend           0x0000000108fcd6dc llvm::report_fatal_error(llvm::Twine const&, bool) + 0
9  swift-frontend           0x0000000108f77e00 void llvm::VerifierSupport::CheckFailed<llvm::Instruction*, llvm::MDNode const*>(llvm::Twine const&, llvm::Instruction* const&, llvm::MDNode const* const&) + 0
10 swift-frontend           0x0000000108f1c7d8 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1136
11 swift-frontend           0x0000000108f1bd90 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 96
12 swift-frontend           0x0000000108f22408 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 336
13 swift-frontend           0x00000001052b6db0 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module*, llvm::TargetMachine*) + 1484
14 swift-frontend           0x00000001052b7cc8 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef, swift::UnifiedStatsReporter*) + 2460
15 swift-frontend           0x0000000104fae080 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3084
16 swift-frontend           0x0000000104fa00c8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5548
17 swift-frontend           0x0000000104f35100 main + 1136
18 libdyld.dylib            0x00000001a2741450 start + 4
error: Abort trap: 6 (in target 'StarRating' from project 'StarRating')
typesanitizer commented 3 years ago

Triggers an assertion failure on main

Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h, line 269.
<snip>
1.      Swift version 5.5-dev (LLVM 071fc2d8d3e9985, Swift 3bb294521f6c68f)
<snip>
4.      While silgen emitConstructor SIL function "@$s3tmp13SettingsGroupV8settingsACSayAA7SettingVGyXE_tcfC".
 for 'init(settings:)' (at tmp.swift:3:8)
<snip>
5  libsystem_c.dylib        0x00007fff20284f10 abort + 123
6  libsystem_c.dylib        0x00007fff202842e3 err + 0
7  swift-frontend           0x000000010ce7a6b3 swift::CanTypeWrapperTraits<swift::ReferenceStorageType>::type swift::SILType::castTo<swift::ReferenceStorageType>() const (.cold.3) + 35
8  swift-frontend           0x00000001087c775b swift::CanTypeWrapperTraits<swift::ReferenceStorageType>::type swift::SILType::castTo<swift::ReferenceStorageType>() const + 91
9  swift-frontend           0x00000001087c84b4 swift::Lowering::SILGenFunction::emitConversionFromSemanticValue(swift::SILLocation, swift::SILValue, swift::SILType) + 68
10 swift-frontend           0x000000010872f1f5 swift::Lowering::RValue::forwardAsSingleStorageValue(swift::Lowering::SILGenFunction&, swift::SILType, swift::SILLocation) && + 165
typesanitizer commented 3 years ago

Thanks for the reduced example.

@swift-ci create