[PATCH] D157334: [clang] Define _MSC_EXTENSIONS on -gnu if -fms-extensions is set
Aiden Grossman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 14:47:27 PDT 2023
aidengrossman created this revision.
Herald added subscribers: pengfei, mstorsjo.
Herald added a project: All.
aidengrossman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch makes sure _MSC_EXTENSIONS is defined if -fms-extensions is set by hosting the logic for setting the -fms-extensions related macros out of some conditional checks related to the target triple. Otherwise we would end up in situations where Windows builtins added by -fms-extensions would be defined but _MSC_EXTENSIONS wouldn't be defined like on MinGW with the triple x86_64-windows-gnu.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157334
Files:
clang/lib/Basic/Targets/OSTargets.cpp
clang/test/Preprocessor/predefined-win-macros.c
Index: clang/test/Preprocessor/predefined-win-macros.c
===================================================================
--- clang/test/Preprocessor/predefined-win-macros.c
+++ clang/test/Preprocessor/predefined-win-macros.c
@@ -120,9 +120,14 @@
// CHECK-AMD64-MINGW: #define _WIN32 1
// CHECK-AMD64-MINGW: #define _WIN64 1
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - -fms-extensions \
+// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-AMD64-MINGW-MSE
+
+// CHECK-AMD64-MINGW-MSE: #define _MSC_EXTENSIONS 1
+
// RUN: %clang_cc1 -triple aarch64-windows-gnu %s -E -dM -o - \
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-MINGW
// CHECK-ARM64-MINGW-NOT: #define _M_ARM64 1
// CHECK-ARM64-MINGW: #define WIN32 1
// CHECK-ARM64-MINGW: #define WIN64 1
Index: clang/lib/Basic/Targets/OSTargets.cpp
===================================================================
--- clang/lib/Basic/Targets/OSTargets.cpp
+++ clang/lib/Basic/Targets/OSTargets.cpp
@@ -226,25 +226,15 @@
}
}
- if (Opts.MicrosoftExt) {
- Builder.defineMacro("_MSC_EXTENSIONS");
-
- if (Opts.CPlusPlus11) {
- Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
- Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
- Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
- }
- }
-
if (!Opts.MSVolatile)
Builder.defineMacro("_ISO_VOLATILE");
if (Opts.Kernel)
Builder.defineMacro("_KERNEL_MODE");
Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
Builder.defineMacro("__STDC_NO_THREADS__");
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
// users of the execution character set defined at compile time.
// The value given is the Windows Code Page Identifier:
@@ -264,7 +254,17 @@
else if (Triple.isKnownWindowsMSVCEnvironment() ||
(Triple.isWindowsItaniumEnvironment() && Opts.MSVCCompat))
addVisualCDefines(Opts, Builder);
+
+ if (Opts.MicrosoftExt) {
+ Builder.defineMacro("_MSC_EXTENSIONS");
+
+ if (Opts.CPlusPlus11) {
+ Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
+ Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
+ Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
+ }
+ }
}
} // namespace targets
} // namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157334.547956.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230807/694f646f/attachment.bin>
More information about the cfe-commits
mailing list