https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/96062

… 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.

From a0dc374a76d68179c2b7475a7d1e0e55f1622401 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <mar...@martin.st>
Date: Wed, 19 Jun 2024 14:34:12 +0300
Subject: [PATCH] [clang] [MinGW] Set a predefined
 __GXX_TYPEINFO_EQUALITY_INLINE=0 for 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.
---
 clang/lib/Frontend/InitPreprocessor.cpp         |  6 ++++++
 clang/test/Preprocessor/predefined-win-macros.c | 10 ++++++++++
 2 files changed, 16 insertions(+)

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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to