Skip to content

[clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for… #96062

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

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

mstorsjo
Copy link
Member

… MinGW targets

libstdc++ requires this define to match what is predefined in GCC for the ABI of this platform; GCC hardcodes this define for all mingw configurations in gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to match the defaults in libstdc++ headers, so there's no similar need to define it in Clang.)

This fixes a Clang/libstdc++ interop issue discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.

@mstorsjo mstorsjo added the clang Clang issues not falling into any other category label Jun 19, 2024
@mstorsjo mstorsjo requested review from MaskRay and alvinhochun June 19, 2024 11:38
@llvmbot
Copy link
Member

llvmbot commented Jun 19, 2024

@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)

Changes

… MinGW targets

libstdc++ requires this define to match what is predefined in GCC for the ABI of this platform; GCC hardcodes this define for all mingw configurations in gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to match the defaults in libstdc++ headers, so there's no similar need to define it in Clang.)

This fixes a Clang/libstdc++ interop issue discussed at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.


Full diff: https://github.com/llvm/llvm-project/pull/96062.diff

2 Files Affected:

  • (modified) clang/lib/Frontend/InitPreprocessor.cpp (+6)
  • (modified) clang/test/Preprocessor/predefined-win-macros.c (+10)
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index e8c8a5175f8f4..2d20b56966186 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -926,6 +926,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
     Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
 
+  if (TI.getTriple().isWindowsGNUEnvironment() && LangOpts.CPlusPlus) {
+    // Set ABI defining macros for libstdc++ for MinGW, where the
+    // default in libstdc++ differs from the defaults for this target.
+    Builder.defineMacro("__GXX_TYPEINFO_EQUALITY_INLINE", "0");
+  }
+
   if (LangOpts.ObjC) {
     if (LangOpts.ObjCRuntime.isNonFragile()) {
       Builder.defineMacro("__OBJC2__");
diff --git a/clang/test/Preprocessor/predefined-win-macros.c b/clang/test/Preprocessor/predefined-win-macros.c
index 14e2f584bd093..12e705875b123 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -163,3 +163,13 @@
 // CHECK-ARM64EC-MINGW: #define __arm64ec__ 1
 // CHECK-ARM64EC-MINGW: #define __x86_64 1
 // CHECK-ARM64EC-MINGW: #define __x86_64__ 1
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-C
+
+// CHECK-MINGW-C-NOT: #define __GXX_TYPEINFO_EQUALITY_INLINE
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -x c++ %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-CXX
+
+// CHECK-MINGW-CXX: #define __GXX_TYPEINFO_EQUALITY_INLINE 0

@mstorsjo
Copy link
Member Author

CC @jwakely

@@ -926,6 +926,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");

if (TI.getTriple().isWindowsGNUEnvironment() && LangOpts.CPlusPlus) {
Copy link
Member

@MaskRay MaskRay Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CPlusPlus condition should probably be removed.

% x86_64-w64-mingw32-gcc -dM -xc -E /dev/null | grep TYPEINFO
#define __GXX_TYPEINFO_EQUALITY_INLINE 0
#define __GXX_MERGED_TYPEINFO_NAMES 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. Yeah while it doesn't serve much purpose in non-c++ mode, it doesn't hurt either and simplifies things a little bit.

… MinGW targets

libstdc++ requires this define to match what is predefined in
GCC for the ABI of this platform; GCC hardcodes this define
for all mingw configurations in gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens
to match the defaults in libstdc++ headers, so there's no similar
need to define it in Clang.)

This fixes a Clang/libstdc++ interop issue discussed at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.
@mstorsjo mstorsjo force-pushed the clang-mingw-gxx-defines branch from a0dc374 to 7e6050d Compare June 20, 2024 08:12
@mstorsjo mstorsjo merged commit 4e6c8f1 into llvm:main Jun 24, 2024
7 checks passed
@mstorsjo mstorsjo deleted the clang-mingw-gxx-defines branch June 24, 2024 11:02
@silverqx
Copy link

silverqx commented Jun 24, 2024

Do you already know in which Clang versions this will be fixed? Also thx for fixing this 👍

@mstorsjo
Copy link
Member Author

Do you already know in which Clang versions this will be fixed? Also thx for fixing this 👍

The fix will be in the upcoming 19.x which is going to release candidates in August and might be released in September/October. (Although, downstreams may pick it up and backport the patch to earlier releases - msys2 does this if the fix is relevant to them.)

@silverqx
Copy link

Thx

AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
… MinGW targets (llvm#96062)

libstdc++ requires this define to match what is predefined in GCC for
the ABI of this platform; GCC hardcodes this define for all mingw
configurations in gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to
match the defaults in libstdc++ headers, so there's no similar need to
define it in Clang.)

This fixes a Clang/libstdc++ interop issue discussed at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants