14#include "llvm/ADT/StringRef.h"
23 const llvm::Triple &Triple) {
24 Builder.defineMacro(
"__APPLE_CC__",
"6000");
25 Builder.defineMacro(
"__APPLE__");
30 Builder.defineMacro(
"_FORTIFY_SOURCE",
"0");
35 Builder.defineMacro(
"__weak",
"__attribute__((objc_gc(weak)))");
36 Builder.defineMacro(
"__strong",
"");
37 Builder.defineMacro(
"__unsafe_unretained",
"");
41 Builder.defineMacro(
"__STATIC__");
43 Builder.defineMacro(
"__DYNAMIC__");
45 if (Opts.POSIXThreads)
46 Builder.defineMacro(
"_REENTRANT");
52 if (Triple.isAppleMachO() || Triple.isOSDarwin())
53 Builder.defineMacro(
"__MACH__");
57 const llvm::Triple &Triple, StringRef &PlatformName,
58 VersionTuple &PlatformMinVersion) {
62 Builder.defineMacro(
"__STDC_NO_THREADS__");
65 VersionTuple OsVersion;
66 if (Triple.isMacOSX()) {
67 Triple.getMacOSXVersion(OsVersion);
68 PlatformName =
"macos";
70 OsVersion = Triple.getOSVersion();
71 PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
72 if (PlatformName ==
"ios" && Triple.isMacCatalystEnvironment())
73 PlatformName =
"maccatalyst";
79 if (PlatformName ==
"win32") {
80 PlatformMinVersion = OsVersion;
84 assert(OsVersion < VersionTuple(100) &&
"Invalid version!");
86 if (Triple.isMacOSX() && OsVersion < VersionTuple(10, 10)) {
87 Str[0] =
'0' + (OsVersion.getMajor() / 10);
88 Str[1] =
'0' + (OsVersion.getMajor() % 10);
89 Str[2] =
'0' + std::min(OsVersion.getMinor().value_or(0), 9U);
90 Str[3] =
'0' + std::min(OsVersion.getSubminor().value_or(0), 9U);
92 }
else if (!Triple.isMacOSX() && OsVersion.getMajor() < 10) {
93 Str[0] =
'0' + OsVersion.getMajor();
94 Str[1] =
'0' + (OsVersion.getMinor().value_or(0) / 10);
95 Str[2] =
'0' + (OsVersion.getMinor().value_or(0) % 10);
96 Str[3] =
'0' + (OsVersion.getSubminor().value_or(0) / 10);
97 Str[4] =
'0' + (OsVersion.getSubminor().value_or(0) % 10);
101 Str[0] =
'0' + (OsVersion.getMajor() / 10);
102 Str[1] =
'0' + (OsVersion.getMajor() % 10);
103 Str[2] =
'0' + (OsVersion.getMinor().value_or(0) / 10);
104 Str[3] =
'0' + (OsVersion.getMinor().value_or(0) % 10);
105 Str[4] =
'0' + (OsVersion.getSubminor().value_or(0) / 10);
106 Str[5] =
'0' + (OsVersion.getSubminor().value_or(0) % 10);
111 if (Triple.isTvOS()) {
112 Builder.defineMacro(
"__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__", Str);
113 }
else if (Triple.isiOS()) {
114 Builder.defineMacro(
"__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str);
115 }
else if (Triple.isWatchOS()) {
116 Builder.defineMacro(
"__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__", Str);
117 }
else if (Triple.isDriverKit()) {
118 assert(OsVersion.getMinor().value_or(0) < 100 &&
119 OsVersion.getSubminor().value_or(0) < 100 &&
"Invalid version!");
120 Builder.defineMacro(
"__ENVIRONMENT_DRIVERKIT_VERSION_MIN_REQUIRED__", Str);
121 }
else if (Triple.isMacOSX()) {
122 Builder.defineMacro(
"__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str);
125 if (Triple.isOSDarwin()) {
128 assert(OsVersion.getMinor().value_or(0) < 100 &&
129 OsVersion.getSubminor().value_or(0) < 100 &&
"Invalid version!");
130 Builder.defineMacro(
"__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
133 PlatformMinVersion = OsVersion;
140 if (Triple.isArch64Bit()) {
142 Builder.defineMacro(
"__MINGW64__");
144 Builder.defineMacro(
"__MSVCRT__");
145 Builder.defineMacro(
"__MINGW32__");
150 if (Opts.CPlusPlus) {
152 Builder.defineMacro(
"_CPPRTTI");
154 if (Opts.CXXExceptions)
155 Builder.defineMacro(
"_CPPUNWIND");
159 Builder.defineMacro(
"__BOOL_DEFINED");
161 if (!Opts.CharIsSigned)
162 Builder.defineMacro(
"_CHAR_UNSIGNED");
167 Builder.defineMacro(
"_M_FP_CONTRACT");
174 Builder.defineMacro(
"_M_FP_EXCEPT");
187 const bool any_imprecise_flags = Opts.FastMath || Opts.UnsafeFPMath ||
188 Opts.AllowFPReassoc || Opts.NoHonorNaNs ||
189 Opts.NoHonorInfs || Opts.NoSignedZero ||
190 Opts.AllowRecip || Opts.ApproxFunc;
198 LangOptions::RoundingMode::NearestTiesToEven) {
199 if (any_imprecise_flags) {
200 Builder.defineMacro(
"_M_FP_FAST");
202 Builder.defineMacro(
"_M_FP_PRECISE");
205 LangOptions::RoundingMode::Dynamic) {
209 Builder.defineMacro(
"_M_FP_STRICT");
214 if (Opts.POSIXThreads)
215 Builder.defineMacro(
"_MT");
217 if (Opts.MSCompatibilityVersion) {
218 Builder.defineMacro(
"_MSC_VER",
219 Twine(Opts.MSCompatibilityVersion / 100000));
220 Builder.defineMacro(
"_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
222 Builder.defineMacro(
"_MSC_BUILD", Twine(1));
225 Builder.defineMacro(
"_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
228 if (Opts.CPlusPlus26)
230 Builder.defineMacro(
"_MSVC_LANG",
"202400L");
231 else if (Opts.CPlusPlus23)
232 Builder.defineMacro(
"_MSVC_LANG",
"202302L");
233 else if (Opts.CPlusPlus20)
234 Builder.defineMacro(
"_MSVC_LANG",
"202002L");
235 else if (Opts.CPlusPlus17)
236 Builder.defineMacro(
"_MSVC_LANG",
"201703L");
237 else if (Opts.CPlusPlus14)
238 Builder.defineMacro(
"_MSVC_LANG",
"201402L");
242 Builder.defineMacro(
"_MSVC_CONSTEXPR_ATTRIBUTE");
245 if (Opts.MicrosoftExt) {
246 Builder.defineMacro(
"_MSC_EXTENSIONS");
248 if (Opts.CPlusPlus11) {
249 Builder.defineMacro(
"_RVALUE_REFERENCES_V2_SUPPORTED");
250 Builder.defineMacro(
"_RVALUE_REFERENCES_SUPPORTED");
251 Builder.defineMacro(
"_NATIVE_NULLPTR_SUPPORTED");
255 if (!Opts.MSVolatile)
256 Builder.defineMacro(
"_ISO_VOLATILE");
259 Builder.defineMacro(
"_KERNEL_MODE");
261 Builder.defineMacro(
"_INTEGRAL_MAX_BITS",
"64");
262 Builder.defineMacro(
"__STDC_NO_THREADS__");
270 Builder.defineMacro(
"_MSVC_EXECUTION_CHARACTER_SET",
"65001");
275 Builder.defineMacro(
"_WIN32");
276 if (Triple.isArch64Bit())
277 Builder.defineMacro(
"_WIN64");
278 if (Triple.isWindowsGNUEnvironment())
280 else if (Triple.isKnownWindowsMSVCEnvironment() ||
281 (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)
LLVM_LIBRARY_VISIBILITY void addCygMingDefines(const clang::LangOptions &Opts, clang::MacroBuilder &Builder)
static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder)
void getAppleMachODefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple)
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
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.