Skip to content

swift_newtype + (Equatable & import Foundation) cause compiler crash on Linux #71086

Open
@Kyle-Ye

Description

@Kyle-Ye

Description

For a C target symbol imported as Swift struct, Equatable + import Foundation cause a compiler crash on Linux

Reproduction

Bug reproduce step:

  1. Add a C target define uint32 as a struct

    typedef uint32_t CAttribute __attribute((swift_newtype(struct)));
  2. import the C module and use the type in our Swift code. If we add Equatable to our Swift type and have import Foundation statement in the same module, we'll get a compiler crash here.

    import CDemoKit
    import Foundation
    
    public struct Demo {
        var attribute: CAttribute
    }
    extension Demo: Equatable {}

Comment on Line 2 or Line 7 will not crash the compiler.

Or you can just download DemoKit.zip here and run swift build.

DemoKit.zip

Stack dump

swift build
Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Cannot look up associated type for imported conformance:
(struct_type decl=CDemoKit.(file).CAttribute)
(associated_type_decl "_ObjectiveCType" access=public overridden=)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend -frontend -c -primary-file /home/kyle/tmp/DemoKit/Sources/DemoKit/DemoKit.swift -emit-dependencies-path /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/DemoKit.build/DemoKit.d -emit-reference-dependencies-path /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/DemoKit.build/DemoKit.swiftdeps -target aarch64-unknown-linux-gnu -Xllvm -aarch64-use-tbi -disable-objc-interop -I /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/CDemoKit.build/module.modulemap -Xcc -I -Xcc /home/kyle/tmp/DemoKit/Sources/CDemoKit/include -Xcc -fPIC -Xcc -fno-omit-frame-pointer -module-name DemoKit -package-name demokit -plugin-path /home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/lib/swift/host/plugins -plugin-path /home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/local/lib/swift/host/plugins -parse-as-library -o /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/DemoKit.build/DemoKit.swift.o -index-store-path /home/kyle/tmp/DemoKit/.build/aarch64-unknown-linux-gnu/debug/index/store -index-system-modules
1.	Swift version 5.9.2 (swift-5.9.2-RELEASE)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/home/kyle/tmp/DemoKit/Sources/DemoKit/DemoKit.swift")
4.	While generating SIL witness table protocol conformance to '_ObjectiveCBridgeable' (in module 'Swift') for type 'CAttribute'
5.	While completing import of protocol conformance to '_ObjectiveCBridgeable' (in module 'Swift') for type 'CAttribute'
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):
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x592f56c)[0xaaaaebe5f56c]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x592d748)[0xaaaaebe5d748]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x592f988)[0xaaaaebe5f988]
linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0xffff865f17a0]
/lib/aarch64-linux-gnu/libc.so.6(+0x7f200)[0xffff84cbf200]
/lib/aarch64-linux-gnu/libc.so.6(raise+0x1c)[0xffff84c7a67c]
/lib/aarch64-linux-gnu/libc.so.6(abort+0xe4)[0xffff84c67130]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x1d730a0)[0xaaaae82a30a0]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x210638c)[0xaaaae863638c]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x21061d0)[0xaaaae86361d0]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x21068d0)[0xaaaae86368d0]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x11ef9a4)[0xaaaae771f9a4]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x11ed510)[0xaaaae771d510]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x115b83c)[0xaaaae768b83c]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x11e4884)[0xaaaae7714884]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x115d924)[0xaaaae768d924]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0x115b9a8)[0xaaaae768b9a8]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0xc18d84)[0xaaaae7148d84]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0xc1b338)[0xaaaae714b338]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0xc1a4e4)[0xaaaae714a4e4]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0xa95444)[0xaaaae6fc5444]
/lib/aarch64-linux-gnu/libc.so.6(+0x273fc)[0xffff84c673fc]
/lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0x98)[0xffff84c674cc]
/home/kyle/.swiftbox/toolchain/swift-5.9.2/usr/bin/swift-frontend(+0xa94330)[0xaaaae6fc4330]

Expected behavior

Compile normally as the same on iOS and macOS.

Environment

$ swiftc --version
Swift version 5.9.2 (swift-5.9.2-RELEASE)
Target: aarch64-unknown-linux-gnu
$ uname -a
Linux ubuntu-2204 6.5.13-orbstack-00121-ge428743e4e98 #1 SMP Wed Dec 27 10:22:46 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Additional information

Forums link: https://forums.swift.org/t/69577

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions