Skip to content

[C++-Interop][Swift 5.9] Invoking a manually defaulted non-noexcept C++ constructor from Swift results in a compiler crash in IRGen #65891

Closed
@plotfi

Description

@plotfi

Invoking a manually defaulted non-noexcept C++ constructor from Swift results in a compiler crash in IRGen.

This affects Swift 5.9 but not 5.8, it is likely due to the recently added exception handling.

Repro (zip file attached as well, modify the makefile with your Swift path and run make):

// CXX.h:
struct S { S() = default; };

NOTE: The crash does not happy if S's constructor is marked noexcept (ie struct S { S() noexcept = default; };).

Swift invocation:

import CXX
public func f() -> S { S() }

Module Map is simply:

module CXX {
  header "CXX.h"
}

Compiler Invocation:

swiftc -frontend -c \
  -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
  -target x86_64-apple-ios13.4-simulator \
  -enable-experimental-cxx-interop \
  test.swift \
  -I./

Stack trace:

UNREACHABLE executed at /Users/plotfi/local/S/llvm-project/clang/lib/AST/Type.cpp:3338!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Users/plotfi/local/S/build/RelWithDebInfo/BinaryCache/toolchain/bin//swiftc -frontend -c -Xcc -DENABLE_NO_EXCEPT=0 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -target x86_64-apple-ios13.4-simulator -enable-experimental-cxx-interop test.swift -I./
1.	Swift version 5.9-dev (LLVM 3c8aa1ceab247bb, Swift 9a57840c2e121c5)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for module test)
4.	While emitting IR SIL function "@$s4test1fSo1SVyF".
 for 'f()' (at test.swift:3:8)
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           0x0000000109bcd21c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109bcc610 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109bcd864 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001976caa84 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019769bc28 pthread_kill + 288
5  libsystem_c.dylib        0x00000001975a9ae8 abort + 180
6  swift-frontend           0x0000000109b26450 llvm::install_out_of_memory_new_handler() + 0
7  swift-frontend           0x0000000108ebbaa4 clang::FunctionProtoType::canThrow() const + 288
8  swift-frontend           0x0000000104d68760 (anonymous namespace)::IRGenSILFunction::visitFunctionRefBaseInst(swift::FunctionRefBaseInst*) + 384
9  swift-frontend           0x0000000104d5773c (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 32576
10 swift-frontend           0x0000000104d4e6bc (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 6688
11 swift-frontend           0x0000000104d4c734 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 948
12 swift-frontend           0x0000000104c01384 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&) + 684
13 swift-frontend           0x0000000104cfed0c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 1628
14 swift-frontend           0x0000000104d4be58 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 208
15 swift-frontend           0x0000000104d0cf48 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 252
16 swift-frontend           0x0000000104cffe50 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::GlobalVariable**) + 844
17 swift-frontend           0x00000001048ea9f8 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>>>) + 272
18 swift-frontend           0x00000001048e744c 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*) + 1400
19 swift-frontend           0x00000001048e6b30 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1112
20 swift-frontend           0x00000001048f5dc4 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
21 swift-frontend           0x00000001048e8b14 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 624
22 swift-frontend           0x00000001048e7c60 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 1840
23 swift-frontend           0x0000000104891530 swift::mainEntry(int, char const**) + 2180
24 dyld                     0x0000000197343f28 start + 2236
make: *** [all] Abort trap: 6

Swift5.9CxxInteropNoNoExceptCompilerCrash.zip

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++triage 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