aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp186
1 files changed, 121 insertions, 65 deletions
diff --git a/contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp b/contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp
index 15e475a31d64..899aefa6173a 100644
--- a/contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/contrib/llvm-project/clang/lib/Basic/Targets/OSTargets.cpp
@@ -48,91 +48,78 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
Builder.defineMacro("_REENTRANT");
// Get the platform type and version number from the triple.
- unsigned Maj, Min, Rev;
+ VersionTuple OsVersion;
if (Triple.isMacOSX()) {
- Triple.getMacOSXVersion(Maj, Min, Rev);
+ Triple.getMacOSXVersion(OsVersion);
PlatformName = "macos";
} else {
- Triple.getOSVersion(Maj, Min, Rev);
+ OsVersion = Triple.getOSVersion();
PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
+ if (PlatformName == "ios" && Triple.isMacCatalystEnvironment())
+ PlatformName = "maccatalyst";
}
// If -target arch-pc-win32-macho option specified, we're
// generating code for Win32 ABI. No need to emit
// __ENVIRONMENT_XX_OS_VERSION_MIN_REQUIRED__.
if (PlatformName == "win32") {
- PlatformMinVersion = VersionTuple(Maj, Min, Rev);
+ PlatformMinVersion = OsVersion;
return;
}
- // Set the appropriate OS version define.
- if (Triple.isiOS()) {
- assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
- char Str[7];
- if (Maj < 10) {
- Str[0] = '0' + Maj;
- Str[1] = '0' + (Min / 10);
- Str[2] = '0' + (Min % 10);
- Str[3] = '0' + (Rev / 10);
- Str[4] = '0' + (Rev % 10);
- Str[5] = '\0';
- } else {
- // Handle versions >= 10.
- Str[0] = '0' + (Maj / 10);
- Str[1] = '0' + (Maj % 10);
- Str[2] = '0' + (Min / 10);
- Str[3] = '0' + (Min % 10);
- Str[4] = '0' + (Rev / 10);
- Str[5] = '0' + (Rev % 10);
- Str[6] = '\0';
- }
- if (Triple.isTvOS())
- Builder.defineMacro("__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__", Str);
- else
- Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__",
- Str);
+ assert(OsVersion < VersionTuple(100) && "Invalid version!");
+ char Str[7];
+ if (Triple.isMacOSX() && OsVersion < VersionTuple(10, 10)) {
+ Str[0] = '0' + (OsVersion.getMajor() / 10);
+ Str[1] = '0' + (OsVersion.getMajor() % 10);
+ Str[2] = '0' + std::min(OsVersion.getMinor().value_or(0), 9U);
+ Str[3] = '0' + std::min(OsVersion.getSubminor().value_or(0), 9U);
+ Str[4] = '\0';
+ } else if (!Triple.isMacOSX() && OsVersion.getMajor() < 10) {
+ Str[0] = '0' + OsVersion.getMajor();
+ Str[1] = '0' + (OsVersion.getMinor().value_or(0) / 10);
+ Str[2] = '0' + (OsVersion.getMinor().value_or(0) % 10);
+ Str[3] = '0' + (OsVersion.getSubminor().value_or(0) / 10);
+ Str[4] = '0' + (OsVersion.getSubminor().value_or(0) % 10);
+ Str[5] = '\0';
+ } else {
+ // Handle versions >= 10.
+ Str[0] = '0' + (OsVersion.getMajor() / 10);
+ Str[1] = '0' + (OsVersion.getMajor() % 10);
+ Str[2] = '0' + (OsVersion.getMinor().value_or(0) / 10);
+ Str[3] = '0' + (OsVersion.getMinor().value_or(0) % 10);
+ Str[4] = '0' + (OsVersion.getSubminor().value_or(0) / 10);
+ Str[5] = '0' + (OsVersion.getSubminor().value_or(0) % 10);
+ Str[6] = '\0';
+ }
+ // Set the appropriate OS version define.
+ if (Triple.isTvOS()) {
+ Builder.defineMacro("__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__", Str);
+ } else if (Triple.isiOS()) {
+ Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
} else if (Triple.isWatchOS()) {
- assert(Maj < 10 && Min < 100 && Rev < 100 && "Invalid version!");
- char Str[6];
- Str[0] = '0' + Maj;
- Str[1] = '0' + (Min / 10);
- Str[2] = '0' + (Min % 10);
- Str[3] = '0' + (Rev / 10);
- Str[4] = '0' + (Rev % 10);
- Str[5] = '\0';
Builder.defineMacro("__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__", Str);
+ } else if (Triple.isDriverKit()) {
+ assert(OsVersion.getMinor().value_or(0) < 100 &&
+ OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
+ Builder.defineMacro("__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__", Str);
} else if (Triple.isMacOSX()) {
- // Note that the Driver allows versions which aren't representable in the
- // define (because we only get a single digit for the minor and micro
- // revision numbers). So, we limit them to the maximum representable
- // version.
- assert(Maj < 100 && Min < 100 && Rev < 100 && "Invalid version!");
- char Str[7];
- if (Maj < 10 || (Maj == 10 && Min < 10)) {
- Str[0] = '0' + (Maj / 10);
- Str[1] = '0' + (Maj % 10);
- Str[2] = '0' + std::min(Min, 9U);
- Str[3] = '0' + std::min(Rev, 9U);
- Str[4] = '\0';
- } else {
- // Handle versions > 10.9.
- Str[0] = '0' + (Maj / 10);
- Str[1] = '0' + (Maj % 10);
- Str[2] = '0' + (Min / 10);
- Str[3] = '0' + (Min % 10);
- Str[4] = '0' + (Rev / 10);
- Str[5] = '0' + (Rev % 10);
- Str[6] = '\0';
- }
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 = VersionTuple(Maj, Min, Rev);
+ PlatformMinVersion = OsVersion;
}
static void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts,
@@ -163,6 +150,54 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
if (!Opts.CharIsSigned)
Builder.defineMacro("_CHAR_UNSIGNED");
+ // "The /fp:contract option allows the compiler to generate floating-point
+ // contractions [...]"
+ if (Opts.getDefaultFPContractMode() != LangOptions::FPModeKind::FPM_Off)
+ Builder.defineMacro("_M_FP_CONTRACT");
+
+ // "The /fp:except option generates code to ensures that any unmasked
+ // floating-point exceptions are raised at the exact point at which they
+ // occur, and that no other floating-point exceptions are raised."
+ if (Opts.getDefaultExceptionMode() ==
+ LangOptions::FPExceptionModeKind::FPE_Strict)
+ Builder.defineMacro("_M_FP_EXCEPT");
+
+ // "The /fp:fast option allows the compiler to reorder, combine, or simplify
+ // floating-point operations to optimize floating-point code for speed and
+ // space. The compiler may omit rounding at assignment statements,
+ // typecasts, or function calls. It may reorder operations or make algebraic
+ // transforms, for example, by use of associative and distributive laws. It
+ // may reorder code even if such transformations result in observably
+ // different rounding behavior."
+ //
+ // "Under /fp:precise and /fp:strict, the compiler doesn't do any mathematical
+ // transformation unless the transformation is guaranteed to produce a bitwise
+ // identical result."
+ const bool any_imprecise_flags =
+ Opts.FastMath || Opts.FiniteMathOnly || Opts.UnsafeFPMath ||
+ Opts.AllowFPReassoc || Opts.NoHonorNaNs || Opts.NoHonorInfs ||
+ Opts.NoSignedZero || Opts.AllowRecip || Opts.ApproxFunc;
+
+ // "Under both /fp:precise and /fp:fast, the compiler generates code intended
+ // to run in the default floating-point environment."
+ //
+ // "[The] default floating point environment [...] sets the rounding mode
+ // to round to nearest."
+ if (Opts.getDefaultRoundingMode() ==
+ LangOptions::RoundingMode::NearestTiesToEven) {
+ if (any_imprecise_flags) {
+ Builder.defineMacro("_M_FP_FAST");
+ } else {
+ Builder.defineMacro("_M_FP_PRECISE");
+ }
+ } else if (!any_imprecise_flags && Opts.getDefaultRoundingMode() ==
+ LangOptions::RoundingMode::Dynamic) {
+ // "Under /fp:strict, the compiler generates code that allows the
+ // program to safely unmask floating-point exceptions, read or write
+ // floating-point status registers, or change rounding modes."
+ Builder.defineMacro("_M_FP_STRICT");
+ }
+
// FIXME: POSIXThreads isn't exactly the option this should be defined for,
// but it works for now.
if (Opts.POSIXThreads)
@@ -179,13 +214,19 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2015)) {
- if (Opts.CPlusPlus20)
- Builder.defineMacro("_MSVC_LANG", "201705L");
+ if (Opts.CPlusPlus23)
+ // TODO update to the proper value.
+ Builder.defineMacro("_MSVC_LANG", "202004L");
+ else if (Opts.CPlusPlus20)
+ Builder.defineMacro("_MSVC_LANG", "202002L");
else if (Opts.CPlusPlus17)
Builder.defineMacro("_MSVC_LANG", "201703L");
else if (Opts.CPlusPlus14)
Builder.defineMacro("_MSVC_LANG", "201402L");
}
+
+ if (Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_3))
+ Builder.defineMacro("_MSVC_CONSTEXPR_ATTRIBUTE");
}
if (Opts.MicrosoftExt) {
@@ -198,7 +239,22 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
}
}
+ if (!Opts.MSVolatile)
+ Builder.defineMacro("_ISO_VOLATILE");
+
+ if (Opts.Kernel)
+ Builder.defineMacro("_KERNEL_MODE");
+
Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
+ Builder.defineMacro("__STDC_NO_THREADS__");
+
+ // Starting with VS 2022 17.1, MSVC predefines the below macro to inform
+ // users of the execution character set defined at compile time.
+ // The value given is the Windows Code Page Identifier:
+ // https://docs.microsoft.com/en-us/windows/win32/intl/code-page-identifiers
+ //
+ // Clang currently only supports UTF-8, so we'll use 65001
+ Builder.defineMacro("_MSVC_EXECUTION_CHARACTER_SET", "65001");
}
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,