14#include "llvm/ADT/StringRef.h"
23 const llvm::Triple &Triple, StringRef &PlatformName,
24 VersionTuple &PlatformMinVersion) {
25 Builder.defineMacro(
"__APPLE_CC__",
"6000");
26 Builder.defineMacro(
"__APPLE__");
27 Builder.defineMacro(
"__STDC_NO_THREADS__");
32 Builder.defineMacro(
"_FORTIFY_SOURCE",
"0");
37 Builder.defineMacro(
"__weak",
"__attribute__((objc_gc(weak)))");
38 Builder.defineMacro(
"__strong",
"");
39 Builder.defineMacro(
"__unsafe_unretained",
"");
43 Builder.defineMacro(
"__STATIC__");
45 Builder.defineMacro(
"__DYNAMIC__");
47 if (Opts.POSIXThreads)
48 Builder.defineMacro(
"_REENTRANT");
51 VersionTuple OsVersion;
52 if (Triple.isMacOSX()) {
53 Triple.getMacOSXVersion(OsVersion);
54 PlatformName =
"macos";
56 OsVersion = Triple.getOSVersion();
57 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
58 if (PlatformName ==
"ios" && Triple.isMacCatalystEnvironment())
59 PlatformName =
"maccatalyst";
65 if (PlatformName ==
"win32") {
66 PlatformMinVersion = OsVersion;
70 assert(OsVersion < VersionTuple(100) &&
"Invalid version!");
72 if (Triple.isMacOSX() && OsVersion < VersionTuple(10, 10)) {
73 Str[0] =
'0' + (OsVersion.getMajor() / 10);
74 Str[1] =
'0' + (OsVersion.getMajor() % 10);
75 Str[2] =
'0' + std::min(OsVersion.getMinor().value_or(0), 9U);
76 Str[3] =
'0' + std::min(OsVersion.getSubminor().value_or(0), 9U);
78 }
else if (!Triple.isMacOSX() && OsVersion.getMajor() < 10) {
79 Str[0] =
'0' + OsVersion.getMajor();
80 Str[1] =
'0' + (OsVersion.getMinor().value_or(0) / 10);
81 Str[2] =
'0' + (OsVersion.getMinor().value_or(0) % 10);
82 Str[3] =
'0' + (OsVersion.getSubminor().value_or(0) / 10);
83 Str[4] =
'0' + (OsVersion.getSubminor().value_or(0) % 10);
87 Str[0] =
'0' + (OsVersion.getMajor() / 10);
88 Str[1] =
'0' + (OsVersion.getMajor() % 10);
89 Str[2] =
'0' + (OsVersion.getMinor().value_or(0) / 10);
90 Str[3] =
'0' + (OsVersion.getMinor().value_or(0) % 10);
91 Str[4] =
'0' + (OsVersion.getSubminor().value_or(0) / 10);
92 Str[5] =
'0' + (OsVersion.getSubminor().value_or(0) % 10);
97 if (Triple.isTvOS()) {
98 Builder.defineMacro(
"__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__", Str);
99 }
else if (Triple.isiOS()) {
100 Builder.defineMacro(
"__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
101 }
else if (Triple.isWatchOS()) {
102 Builder.defineMacro(
"__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__", Str);
103 }
else if (Triple.isDriverKit()) {
104 assert(OsVersion.getMinor().value_or(0) < 100 &&
105 OsVersion.getSubminor().value_or(0) < 100 &&
"Invalid version!");
106 Builder.defineMacro(
"__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__", Str);
107 }
else if (Triple.isMacOSX()) {
108 Builder.defineMacro(
"__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
111 if (Triple.isOSDarwin()) {
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);
119 Builder.defineMacro(
"__MACH__");
122 PlatformMinVersion = OsVersion;
129 if (Triple.isArch64Bit()) {
131 Builder.defineMacro(
"__MINGW64__");
133 Builder.defineMacro(
"__MSVCRT__");
134 Builder.defineMacro(
"__MINGW32__");
139 if (Opts.CPlusPlus) {
141 Builder.defineMacro(
"_CPPRTTI");
143 if (Opts.CXXExceptions)
144 Builder.defineMacro(
"_CPPUNWIND");
148 Builder.defineMacro(
"__BOOL_DEFINED");
150 if (!Opts.CharIsSigned)
151 Builder.defineMacro(
"_CHAR_UNSIGNED");
156 Builder.defineMacro(
"_M_FP_CONTRACT");
163 Builder.defineMacro(
"_M_FP_EXCEPT");
176 const bool any_imprecise_flags = Opts.FastMath || Opts.UnsafeFPMath ||
177 Opts.AllowFPReassoc || Opts.NoHonorNaNs ||
178 Opts.NoHonorInfs || Opts.NoSignedZero ||
179 Opts.AllowRecip || Opts.ApproxFunc;
187 LangOptions::RoundingMode::NearestTiesToEven) {
188 if (any_imprecise_flags) {
189 Builder.defineMacro(
"_M_FP_FAST");
191 Builder.defineMacro(
"_M_FP_PRECISE");
194 LangOptions::RoundingMode::Dynamic) {
198 Builder.defineMacro(
"_M_FP_STRICT");
203 if (Opts.POSIXThreads)
204 Builder.defineMacro(
"_MT");
206 if (Opts.MSCompatibilityVersion) {
207 Builder.defineMacro(
"_MSC_VER",
208 Twine(Opts.MSCompatibilityVersion / 100000));
209 Builder.defineMacro(
"_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
211 Builder.defineMacro(
"_MSC_BUILD", Twine(1));
214 Builder.defineMacro(
"_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
217 if (Opts.CPlusPlus23)
219 Builder.defineMacro(
"_MSVC_LANG",
"202004L");
220 else if (Opts.CPlusPlus20)
221 Builder.defineMacro(
"_MSVC_LANG",
"202002L");
222 else if (Opts.CPlusPlus17)
223 Builder.defineMacro(
"_MSVC_LANG",
"201703L");
224 else if (Opts.CPlusPlus14)
225 Builder.defineMacro(
"_MSVC_LANG",
"201402L");
229 Builder.defineMacro(
"_MSVC_CONSTEXPR_ATTRIBUTE");
232 if (Opts.MicrosoftExt) {
233 Builder.defineMacro(
"_MSC_EXTENSIONS");
235 if (Opts.CPlusPlus11) {
236 Builder.defineMacro(
"_RVALUE_REFERENCES_V2_SUPPORTED");
237 Builder.defineMacro(
"_RVALUE_REFERENCES_SUPPORTED");
238 Builder.defineMacro(
"_NATIVE_NULLPTR_SUPPORTED");
242 if (!Opts.MSVolatile)
243 Builder.defineMacro(
"_ISO_VOLATILE");
246 Builder.defineMacro(
"_KERNEL_MODE");
248 Builder.defineMacro(
"_INTEGRAL_MAX_BITS",
"64");
249 Builder.defineMacro(
"__STDC_NO_THREADS__");
257 Builder.defineMacro(
"_MSVC_EXECUTION_CHARACTER_SET",
"65001");
262 Builder.defineMacro(
"_WIN32");
263 if (Triple.isArch64Bit())
264 Builder.defineMacro(
"_WIN64");
265 if (Triple.isWindowsGNUEnvironment())
267 else if (Triple.isKnownWindowsMSVCEnvironment() ||
268 (Triple.isWindowsItaniumEnvironment() && Opts.MSVCCompat))
Defines the clang::MacroBuilder utility class.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
FPExceptionModeKind getDefaultExceptionMode() const
SanitizerSet Sanitize
Set of enabled sanitizers.
RoundingMode getDefaultRoundingMode() const
static void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder)
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
void addCygMingDefines(const LangOptions &Opts, MacroBuilder &Builder)
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
The JSON file list parser is used to communicate input to InstallAPI.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.