[clang] Frontend: sink vendor definitions from Basic to Frontend (PR #80364)

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 3 19:32:13 PST 2024


https://github.com/compnerd updated https://github.com/llvm/llvm-project/pull/80364

>From 2bff496bd1b3c1bc5177f5072c2c7b8a4db54f14 Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool <abdulras at thebrowser.company>
Date: Thu, 1 Feb 2024 15:37:39 -0800
Subject: [PATCH] Frontend: sink vendor definitions from Basic to Frontend

The vendor specific macro definitions are based on the vendor rather
than the target specific information. This ensures that `__APPLE__` is
always defined for `*-apple-*` targets. Take the opportunity to do
likewise with the `__AMD__` vendor macro.
---
 clang/lib/Basic/Targets/AMDGPU.cpp      | 1 -
 clang/lib/Basic/Targets/OSTargets.cpp   | 1 -
 clang/lib/Frontend/InitPreprocessor.cpp | 5 +++++
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index 141501e8a4d9a..c6d68f591a5a8 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -266,7 +266,6 @@ ArrayRef<Builtin::Info> AMDGPUTargetInfo::getTargetBuiltins() const {
 
 void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
                                         MacroBuilder &Builder) const {
-  Builder.defineMacro("__AMD__");
   Builder.defineMacro("__AMDGPU__");
 
   if (isAMDGCN(getTriple()))
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index 899aefa6173ac..64b4514ba55bb 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -23,7 +23,6 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
                       const llvm::Triple &Triple, StringRef &PlatformName,
                       VersionTuple &PlatformMinVersion) {
   Builder.defineMacro("__APPLE_CC__", "6000");
-  Builder.defineMacro("__APPLE__");
   Builder.defineMacro("__STDC_NO_THREADS__");
 
   // AddressSanitizer doesn't play well with source fortification, which is on
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bf..27621ee332419 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -804,6 +804,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
     }
   }
 
+  if (TI.getTriple().getVendor() == Triple::AMD)
+    Builder.defineMacro("__AMD__");
+  if (TI.getTriple().getVendor() == Triple::Apple)
+    Builder.defineMacro("__APPLE__");
+
   // Define macros for the C11 / C++11 memory orderings
   Builder.defineMacro("__ATOMIC_RELAXED", "0");
   Builder.defineMacro("__ATOMIC_CONSUME", "1");



More information about the cfe-commits mailing list