Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
conradev opened this issue Nov 4, 2023 · 1 comment · Fixed by #73510
Closed

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

conradev opened this issue Nov 4, 2023 · 1 comment · Fixed by #73510
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++

Comments

@conradev
Copy link

conradev commented Nov 4, 2023

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

@conradev conradev added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Nov 4, 2023
@conradev conradev changed the title Crash when emitting C++ header for two macros that share a name Crash when emitting C++ header for two overloaded macros Nov 4, 2023
@conradev conradev changed the title Crash when emitting C++ header for two overloaded macros Crash when emitting C++ header for overloaded macros Nov 4, 2023
@hyp hyp added the c++ interop Feature: Interoperability with C++ label Nov 5, 2023
@egorzhdan egorzhdan self-assigned this Nov 17, 2023
@egorzhdan egorzhdan removed the triage needed This issue needs more specific labels label Nov 17, 2023
egorzhdan added a commit that referenced this issue May 8, 2024
… to C++

This fixes a compiler crash that happened when emitting a Clang header for a Swift module that declares multiple macros with the same base name and different argument names.

Swift macros are not currently designed to be exposed to C++. This teaches the compiler to explicitly mark them as unavailable in C++.

rdar://117969472 / resolves #69656
@egorzhdan
Copy link
Contributor

Thank you @conradev for a small reproducer!

egorzhdan added a commit that referenced this issue May 10, 2024
… to C++

This fixes a compiler crash that happened when emitting a Clang header for a Swift module that declares multiple macros with the same base name and different argument names.

Swift macros are not currently designed to be exposed to C++. This teaches the compiler to explicitly mark them as unavailable in C++.

rdar://117969472 / resolves #69656
(cherry picked from commit f42609b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants