swiftlang / swift

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

[SR-15744] Aborts with msg "IntToPtr source must be an integral" and trap 6 when compiler encounters attached file #58021

Open swift-ci opened 2 years ago

swift-ci commented 2 years ago
Previous ID SR-15744
Radar None
Original Reporter mrckhld (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: ec9518df9a8b9b81fc51f1ab1c989a5a

Issue Description:

Given file main.swift (attached), and the command, "% swiftc main.swift",

encounter error message:

IntToPtr source must be an integral

%3 = inttoptr i8* %0 to %swift.bridge*, dbg 863

in function $s4main11TableHeaderV13columnHeadersACSayAA06ColumnC0VGyXE_tcfC

:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project :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.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/mr/Projects/termcalendar/termcalendar/main.swift -emit-module-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main~partial.swiftdoc -emit-module-source-info-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main~partial.swiftsourceinfo -emit-dependencies-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main.swiftdeps -serialize-diagnostics-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main.dia -target x86_64-apple-macos12.1 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -I /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Products/Debug -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Products/Debug/PackageFrameworks -F /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Products/Debug/PackageFrameworks -F /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Products/Debug -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/mr/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -Xcc -working-directory -Xcc /Users/mr/Projects/termcalendar -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/-generated-files.hmap -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/-own-target-headers.hmap -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/-project-headers.hmap -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Products/Debug/include -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/DerivedSources/x86_64 -Xcc -I/Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/DerivedSources -Xcc -DDEBUG=1 -module-name main -target-sdk-version 12.1.0 -o /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Build/Intermediates.noindex/termcalendar.build/Debug/termcalendar.build/Objects-normal/x86_64/main.o -index-store-path /Users/mr/Library/Developer/Xcode/DerivedData/termcalendar-hjkkfyckmzpnniciqmmkqbzhrgzx/Index/DataStore -index-system-modules 1. Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 2. 3. Running pass 'Module Verifier' on function '@"$s4main11TableHeaderV13columnHeadersACSayAA06ColumnC0VGyXE_tcfC"' Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 swift-frontend 0x0000000111403c27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39 1 swift-frontend 0x0000000111402bb8 llvm::sys::RunSignalHandlers() + 248 2 swift-frontend 0x0000000111404236 SignalHandler(int) + 278 3 libsystem_platform.dylib 0x00007ff801a30e2d _sigtramp + 29 4 libsystem_platform.dylib 0x0000000000000003 _sigtramp + 18446603370553471475 5 libsystem_c.dylib 0x00007ff801967d10 abort + 123 6 swift-frontend 0x000000010c515502 swift::performFrontend(llvm::ArrayRef, char const\*, void\*, swift::FrontendObserver\*)::$_2::__invoke(void\*, std::__1::basic_string, std::__1::allocator > const&, bool) + 978 7 swift-frontend 0x000000011134d69e llvm::report_fatal_error(llvm::Twine const&, bool) + 286 8 swift-frontend 0x000000011134d57b llvm::report_fatal_error(char const\*, bool) + 43 9 swift-frontend 0x00000001112e415f (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 111 10 swift-frontend 0x000000011127e36a llvm::FPPassManager::runOnFunction(llvm::Function&) + 1354 11 swift-frontend 0x000000011127d651 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 113 12 swift-frontend 0x0000000111284b75 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 341 13 swift-frontend 0x000000010ca0ab61 swift::performLLVMOptimizations(swift::IRGenOptions const&, llvm::Module\*, llvm::TargetMachine\*) + 1585 14 swift-frontend 0x000000010ca0b9c7 swift::performLLVM(swift::IRGenOptions const&, swift::DiagnosticEngine&, llvm::sys::SmartMutex**, llvm::GlobalVariable**, llvm::Module\*, llvm::TargetMachine\*, llvm::StringRef, swift::UnifiedStatsReporter\*) + 2055 15 swift-frontend 0x000000010c520a9d performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr >, llvm::PointerUnion, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver\*) + 3581 16 swift-frontend 0x000000010c512346 swift::performFrontend(llvm::ArrayRef, char const\*, void\*, swift::FrontendObserver\*) + 13830 17 swift-frontend 0x000000010c452b08 main + 1032 18 dyld 0x00000001158e94fe start + 462 error: Abort trap: 6 (in target 'termcalendar' from project 'termcalendar')
swift-ci commented 2 years ago

Comment by Michael Rockhold (JIRA)

Same crash is caused by this much smaller file:

// SmallerMain.swift

import Foundation

protocol Component {
    func emit() -> String
}

struct EmptyElement: Component {
    func emit() -> String { "" }
}

struct FinalResult: Component {
    let contents: [Component]
    func emit() -> String { "" }
}

@resultBuilder
struct BodyBuilder {
    static func buildOptional(_ component: Component?) -> Component {
        guard let component = component else { return EmptyElement() }
        return component
    }
    static func buildEither(first component: Component) -> Component {
        return component
    }
    static func buildEither(second component: Component) -> Component {
        return component
    }
    static func buildArray(_ components: [Component]) -> Component {
        return FinalResult(contents: components)
    }
    static func buildBlock(_ components: Component...) -> Component {
        return FinalResult(contents: components)
    }

    static func buildFinalResult(_ component: Component) -> FinalResult {
        return FinalResult(contents: [component])
    }
}

struct TableCell: Component {
    @BodyBuilder let contents: FinalResult
    func emit() -> String { "" }
}