[clang] c8e2dd8 - [clang][darwin] An OS version preprocessor define is added for any darwin OS

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 12 10:58:45 PDT 2023


Author: Alex Lorenz
Date: 2023-03-12T10:58:33-07:00
New Revision: c8e2dd8c6f490b68e41fe663b44535a8a21dfeab

URL: https://github.com/llvm/llvm-project/commit/c8e2dd8c6f490b68e41fe663b44535a8a21dfeab
DIFF: https://github.com/llvm/llvm-project/commit/c8e2dd8c6f490b68e41fe663b44535a8a21dfeab.diff

LOG: [clang][darwin] An OS version preprocessor define is added for any darwin OS

This change generalizes the OS version macro for all darwin OSes. The OS-specific OS version macros are still defined to preserve compatibility.

Added: 
    

Modified: 
    clang/lib/Basic/Targets/OSTargets.cpp
    clang/test/Frontend/darwin-version.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index 33a5b500e2d1c..763235fb10a52 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -108,9 +108,16 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
     Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
   }
 
-  // Tell users about the kernel if there is one.
-  if (Triple.isOSDarwin())
+  if (Triple.isOSDarwin()) {
+    // Any darwin OS defines a general darwin OS version macro in addition
+    // to the other OS specific macros.
+    assert(OsVersion.getMinor().value_or(0) < 100 &&
+           OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
+    Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
+
+    // Tell users about the kernel if there is one.
     Builder.defineMacro("__MACH__");
+  }
 
   PlatformMinVersion = OsVersion;
 }

diff  --git a/clang/test/Frontend/darwin-version.c b/clang/test/Frontend/darwin-version.c
index 67f087feafe25..28826014e39f1 100644
--- a/clang/test/Frontend/darwin-version.c
+++ b/clang/test/Frontend/darwin-version.c
@@ -59,6 +59,11 @@
 
 // RUN: %clang_cc1 -triple arm64-apple-ios99.99.99 -dM -E %s | FileCheck --check-prefix=IOS99 %s
 // IOS99: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 999999
+// IOS99-NEXT: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 999999
 
 // RUN: %clang_cc1 -triple arm64-apple-watchos99.9 -dM -E %s | FileCheck --check-prefix=WATCHOS99 %s
-// WATCHOS99: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
+// WATCHOS99: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 990900
+// WATCHOS99-NEXT: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
+
+// RUN: %clang_cc1 -triple arm64-apple-macos12.4 -dM -E %s | FileCheck --check-prefix=MACOS124 %s
+// MACOS124: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 120400


        


More information about the cfe-commits mailing list