Skip to content

Crash when emitting C++ header for overloaded macros #69656

Closed
@conradev

Description

@conradev

The Swift compiler crashes when compiling this code with .interoperabilityMode(.Cxx):

@freestanding(expression)
public macro log(error: String) = #externalMacro(module: "CompilerPlugin", type: "LogMacro")

@freestanding(expression)
public macro log(fault: String) = #externalMacro(module: "CompilerPlugin", type: "LogMacro")
1.	Apple Swift version 5.11-dev (LLVM e22c96610989bdb, Swift bd372c2d6861ce3)
2.	Compiling with the current language version
3.	While generating Clang header
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           0x000000010959ce08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010959b564 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010959d458 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x0000000183878a24 _sigtramp + 56
4  libsystem_pthread.dylib  0x0000000183848cc0 pthread_kill + 288
5  libsystem_c.dylib        0x0000000183754a40 abort + 180
6  libsystem_c.dylib        0x0000000183753d30 err + 0
7  swift-frontend           0x00000001095d2c24 (anonymous namespace)::ModuleWriter::write()::'lambda'(swift::Decl* const*, swift::Decl* const*)::__invoke(swift::Decl* const*, swift::Decl* const*) (.cold.9) + 0
8  swift-frontend           0x00000001043b7700 (anonymous namespace)::ModuleWriter::write()::'lambda'(swift::Decl* const*, swift::Decl* const*)::__invoke(swift::Decl* const*, swift::Decl* const*) + 484
9  libsystem_c.dylib        0x00000001836ea4c4 _isort + 136
10 swift-frontend           0x00000001043b4260 (anonymous namespace)::ModuleWriter::write() + 1168
11 swift-frontend           0x00000001043b5da4 swift::printModuleContentsAsCxx(llvm::raw_ostream&, swift::ModuleDecl&, swift::SwiftToClangInteropContext&, bool, llvm::StringSet<llvm::MallocAllocator>&) + 1408
…

It is crashing because the two macros share a name. This is happening on the latest snapshot, and I attached a sample project to reproduce the issue
CompilerCrash.zip

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions