Skip to content

Commit 4e6c8f1

Browse files
authored
[clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for MinGW targets (#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.
1 parent 3d80792 commit 4e6c8f1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,12 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
934934
if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
935935
Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
936936

937+
if (TI.getTriple().isWindowsGNUEnvironment()) {
938+
// Set ABI defining macros for libstdc++ for MinGW, where the
939+
// default in libstdc++ differs from the defaults for this target.
940+
Builder.defineMacro("__GXX_TYPEINFO_EQUALITY_INLINE", "0");
941+
}
942+
937943
if (LangOpts.ObjC) {
938944
if (LangOpts.ObjCRuntime.isNonFragile()) {
939945
Builder.defineMacro("__OBJC2__");

clang/test/Preprocessor/predefined-win-macros.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
// CHECK-X86-MINGW: #define WINNT 1
117117
// CHECK-X86-MINGW: #define _WIN32 1
118118
// CHECK-X86-MINGW-NOT: #define _WIN64 1
119+
// CHECK-X86-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0
119120

120121
// RUN: %clang_cc1 -triple thumbv7-windows-gnu %s -E -dM -o - \
121122
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM-MINGW
@@ -125,6 +126,7 @@
125126
// CHECK-ARM-MINGW: #define WINNT 1
126127
// CHECK-ARM-MINGW: #define _WIN32 1
127128
// CHECK-ARM-MINGW-NOT: #define _WIN64 1
129+
// CHECK-ARM-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0
128130

129131
// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
130132
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW
@@ -134,6 +136,7 @@
134136
// CHECK-AMD64-MINGW: #define WINNT 1
135137
// CHECK-AMD64-MINGW: #define _WIN32 1
136138
// CHECK-AMD64-MINGW: #define _WIN64 1
139+
// CHECK-AMD64-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0
137140

138141
// RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
139142
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
@@ -145,6 +148,7 @@
145148
// CHECK-ARM64-MINGW: #define _WIN32 1
146149
// CHECK-ARM64-MINGW: #define _WIN64 1
147150
// CHECK-ARM64-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
151+
// CHECK-ARM64-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0
148152
// CHECK-ARM64-MINGW: #define __aarch64__ 1
149153

150154
// RUN: %clang_cc1 -triple arm64ec-windows-gnu %s -E -dM -o - \
@@ -157,6 +161,7 @@
157161
// CHECK-ARM64EC-MINGW: #define _WIN32 1
158162
// CHECK-ARM64EC-MINGW: #define _WIN64 1
159163
// CHECK-ARM64EC-MINGW: #define __GCC_ASM_FLAG_OUTPUTS__ 1
164+
// CHECK-ARM64EC-MINGW: #define __GXX_TYPEINFO_EQUALITY_INLINE 0
160165
// CHECK-ARM64EC-MINGW-NOT: #define __aarch64__ 1
161166
// CHECK-ARM64EC-MINGW: #define __amd64 1
162167
// CHECK-ARM64EC-MINGW: #define __amd64__ 1

0 commit comments

Comments
 (0)