Description
Description
The test case here works fine:
swift/test/Sema/bitwse_copyable_import.swift
Lines 56 to 60 in 55189ba
... but removing that int is[]
flexible array member leads to a crash. Oddly, the compiler only crashes if you instantiate a value of the type, not if you declare it as a param, declare it as a return value, or pass it as an argument.
Reproduction
In an imported C library:
struct demo_c_struct {
int i;
int ints[]; // Compiler crashes without this.
} __attribute__((__swift_attr__("BitwiseCopyable")));
Swift code that uses it:
import DemoCModule
let crasher = demo_c_struct()
func doesntCrash1(_ takeItAsAParam: demo_c_struct) {}
func doesntCrash2() -> demo_c_struct {
fatalError("not implemented")
}
func doesntCrash3() {
// pass it as an argument
doesntCrash1(doesntCrash2())
}
Here is a minimal SPM project I made that reproduces it, that takes care of setting up the main Swift executable target, with a C library as a dependency. https://github.com/amomchilov/BitwiseCopyableUnions/tree/compiler-crasher
Stack dump
swift package clean; swift run
Building for debugging...
error: compile command failed due to signal 11 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include 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/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/Sources/BitwiseCopyableUnions/main.swift -emit-dependencies-path /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/BitwiseCopyableUnions.build/main.d -emit-reference-dependencies-path /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/BitwiseCopyableUnions.build/main.swiftdeps -target arm64-apple-macosx10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -I /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/Modules -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -entry-point-function-name BitwiseCopyableUnions_main -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions -Xcc -fmodule-map-file=/Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/DemoCModule.build/module.modulemap -Xcc -I -Xcc /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/Sources/DemoCModule/include -Xcc -isysroot -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -Xcc -F -Xcc /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name BitwiseCopyableUnions -package-name bitwisecopyableunions -disable-clang-spi -target-sdk-version 15.2 -target-sdk-name macosx15.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/BitwiseCopyableUnions.build/main.swift.o -index-store-path /Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1. Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
2. Compiling with the current language version
3. While evaluating request IRGenRequest(IR Generation for file "/Users/Alex/Sync/Dev/Swift/Experiments/BitwiseCopyableUnions/Sources/BitwiseCopyableUnions/main.swift")
4. While emitting IR SIL function "@BitwiseCopyableUnions_main".
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 0x00000001081eea9c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 swift-frontend 0x00000001081eccf0 llvm::sys::RunSignalHandlers() + 112
2 swift-frontend 0x00000001081ef068 SignalHandler(int) + 292
3 libsystem_platform.dylib 0x0000000182266e04 _sigtramp + 56
4 swift-frontend 0x0000000103175344 (anonymous namespace)::OpaqueStorageTypeInfo::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 392
5 swift-frontend 0x0000000103175344 (anonymous namespace)::OpaqueStorageTypeInfo::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 392
6 swift-frontend 0x00000001031465cc swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableClangRecordTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::ClangFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 208
7 swift-frontend 0x00000001031e8980 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 71616
8 swift-frontend 0x00000001031d5ea4 (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 13220
9 swift-frontend 0x00000001031d265c swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 2088
10 swift-frontend 0x000000010301d834 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&) + 3364
11 swift-frontend 0x00000001031895a8 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 4700
12 swift-frontend 0x00000001031d1ba8 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 176
13 swift-frontend 0x0000000103192394 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 784
14 swift-frontend 0x000000010318be90 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 180
15 swift-frontend 0x0000000102b9b4bc generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
16 swift-frontend 0x0000000102b96ce4 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*) + 2176
17 swift-frontend 0x0000000102b95bd0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 984
18 swift-frontend 0x0000000102b98e88 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1684
19 swift-frontend 0x0000000102b97bb4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3572
20 swift-frontend 0x0000000102b1ea5c swift::mainEntry(int, char const**) + 3680
21 dyld 0x0000000181eb0274 start + 2840
Expected behavior
Not crash.
Environment
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Additional information
No response