Skip to content

Commit c8e2dd8

Browse files
committed
[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.
1 parent daf0b27 commit c8e2dd8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

clang/lib/Basic/Targets/OSTargets.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,16 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
108108
Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
109109
}
110110

111-
// Tell users about the kernel if there is one.
112-
if (Triple.isOSDarwin())
111+
if (Triple.isOSDarwin()) {
112+
// Any darwin OS defines a general darwin OS version macro in addition
113+
// to the other OS specific macros.
114+
assert(OsVersion.getMinor().value_or(0) < 100 &&
115+
OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
116+
Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
117+
118+
// Tell users about the kernel if there is one.
113119
Builder.defineMacro("__MACH__");
120+
}
114121

115122
PlatformMinVersion = OsVersion;
116123
}

clang/test/Frontend/darwin-version.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959

6060
// RUN: %clang_cc1 -triple arm64-apple-ios99.99.99 -dM -E %s | FileCheck --check-prefix=IOS99 %s
6161
// IOS99: __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ 999999
62+
// IOS99-NEXT: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 999999
6263

6364
// RUN: %clang_cc1 -triple arm64-apple-watchos99.9 -dM -E %s | FileCheck --check-prefix=WATCHOS99 %s
64-
// WATCHOS99: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
65+
// WATCHOS99: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 990900
66+
// WATCHOS99-NEXT: __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ 990900
67+
68+
// RUN: %clang_cc1 -triple arm64-apple-macos12.4 -dM -E %s | FileCheck --check-prefix=MACOS124 %s
69+
// MACOS124: __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ 120400

0 commit comments

Comments
 (0)