[clang] [Cygwin] Cygwin macro (PR #74973)

εΎζŒζ’ Xu Chiheng via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 9 22:13:21 PST 2023


https://github.com/xu-chiheng updated https://github.com/llvm/llvm-project/pull/74973

>From 376c504e6a559be2b538291e066b1a67c05e5a82 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 14:04:36 +0800
Subject: [PATCH 1/2] 1

---
 clang/lib/Basic/Targets/ARM.cpp | 2 --
 clang/lib/Basic/Targets/X86.cpp | 9 +++++++--
 clang/lib/Basic/Targets/X86.h   | 4 ----
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index ce7e4d4639cea..c99c247924f99 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1402,8 +1402,6 @@ void CygwinARMTargetInfo::getTargetDefines(const LangOptions &Opts,
   Builder.defineMacro("__CYGWIN__");
   Builder.defineMacro("__CYGWIN32__");
   DefineStd(Builder, "unix", Opts);
-  if (Opts.CPlusPlus)
-    Builder.defineMacro("_GNU_SOURCE");
 }
 
 DarwinARMTargetInfo::DarwinARMTargetInfo(const llvm::Triple &Triple,
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49..29a7b089bc0db 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -508,8 +508,13 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
   Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
 
   std::string CodeModel = getTargetOpts().CodeModel;
-  if (CodeModel == "default")
-    CodeModel = "small";
+  if (CodeModel == "default") {
+    if (getTriple().isWindowsCygwinEnvironment() && getTriple().getArch() == llvm::Triple::x86_64) {
+      CodeModel = "medium";
+    } else {
+      CodeModel = "small";
+    }
+  }
   Builder.defineMacro("__code_model_" + CodeModel + "__");
 
   // Target identification.
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 0ab1c10833db2..1664fcc417b14 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -643,8 +643,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_32TargetInfo : public X86_32TargetInfo {
     Builder.defineMacro("__CYGWIN32__");
     addCygMingDefines(Opts, Builder);
     DefineStd(Builder, "unix", Opts);
-    if (Opts.CPlusPlus)
-      Builder.defineMacro("_GNU_SOURCE");
   }
 };
 
@@ -916,8 +914,6 @@ class LLVM_LIBRARY_VISIBILITY CygwinX86_64TargetInfo : public X86_64TargetInfo {
     Builder.defineMacro("__CYGWIN64__");
     addCygMingDefines(Opts, Builder);
     DefineStd(Builder, "unix", Opts);
-    if (Opts.CPlusPlus)
-      Builder.defineMacro("_GNU_SOURCE");
   }
 };
 

>From 582e0bf8fa69c1df436248100e9dc7938cc14b72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BE=90=E6=8C=81=E6=81=92=20Xu=20Chiheng?=
 <chiheng.xu at gmail.com>
Date: Sun, 10 Dec 2023 14:13:02 +0800
Subject: [PATCH 2/2] 1

---
 clang/lib/Basic/Targets/X86.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 29a7b089bc0db..6d62d795403aa 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -509,7 +509,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default") {
-    if (getTriple().isWindowsCygwinEnvironment() && getTriple().getArch() == llvm::Triple::x86_64) {
+    if (getTriple().isWindowsCygwinEnvironment() &&
+        getTriple().getArch() == llvm::Triple::x86_64) {
       CodeModel = "medium";
     } else {
       CodeModel = "small";



More information about the cfe-commits mailing list