Skip to content

Commit

Permalink
[clang][darwin] An OS version preprocessor define is added for any da…
Browse files Browse the repository at this point in the history
…rwin OS

This change generalizes the OS version macro for all darwin OSes. The OS-specific OS version macros are still defined to preserve compatibility.
  • Loading branch information
hyp committed Mar 12, 2023
1 parent daf0b27 commit c8e2dd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions clang/lib/Basic/Targets/OSTargets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion clang/test/Frontend/darwin-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c8e2dd8

Please sign in to comment.