Go to the documentation of this file.
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/DerivedTypes.h"
29 using namespace clang;
32 while (!MacroBody.empty() &&
isWhitespace(MacroBody.back()))
33 MacroBody = MacroBody.drop_back();
34 return !MacroBody.empty() && MacroBody.back() ==
'\\';
42 std::pair<StringRef, StringRef> MacroPair = Macro.split(
'=');
43 StringRef MacroName = MacroPair.first;
44 StringRef MacroBody = MacroPair.second;
45 if (MacroName.size() != Macro.size()) {
47 StringRef::size_type
End = MacroBody.find_first_of(
"\n\r");
48 if (
End != StringRef::npos)
49 Diags.
Report(diag::warn_fe_macro_contains_embedded_newline)
51 MacroBody = MacroBody.substr(0,
End);
56 Builder.defineMacro(MacroName, Twine(MacroBody) +
"\\\n");
58 Builder.defineMacro(MacroName, MacroBody);
61 Builder.defineMacro(Macro);
70 Builder.append(Twine(
"#include \"") +
File +
"\"");
74 Builder.append(Twine(
"#__include_macros \"") +
File +
"\"");
83 StringRef ImplicitIncludePCH) {
87 if (OriginalFile.empty())
96 static T
PickFP(
const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
97 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
99 if (Sem == (
const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
101 if (Sem == (
const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
102 return IEEESingleVal;
103 if (Sem == (
const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
104 return IEEEDoubleVal;
105 if (Sem == (
const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
106 return X87DoubleExtendedVal;
107 if (Sem == (
const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
108 return PPCDoubleDoubleVal;
109 assert(Sem == (
const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
114 const llvm::fltSemantics *Sem, StringRef Ext) {
115 const char *DenormMin, *Epsilon, *Max, *Min;
116 DenormMin =
PickFP(Sem,
"5.9604644775390625e-8",
"1.40129846e-45",
117 "4.9406564584124654e-324",
"3.64519953188247460253e-4951",
118 "4.94065645841246544176568792868221e-324",
119 "6.47517511943802511092443895822764655e-4966");
120 int Digits =
PickFP(Sem, 3, 6, 15, 18, 31, 33);
121 int DecimalDigits =
PickFP(Sem, 5, 9, 17, 21, 33, 36);
122 Epsilon =
PickFP(Sem,
"9.765625e-4",
"1.19209290e-7",
123 "2.2204460492503131e-16",
"1.08420217248550443401e-19",
124 "4.94065645841246544176568792868221e-324",
125 "1.92592994438723585305597794258492732e-34");
126 int MantissaDigits =
PickFP(Sem, 11, 24, 53, 64, 106, 113);
127 int Min10Exp =
PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
128 int Max10Exp =
PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
129 int MinExp =
PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
130 int MaxExp =
PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
131 Min =
PickFP(Sem,
"6.103515625e-5",
"1.17549435e-38",
"2.2250738585072014e-308",
132 "3.36210314311209350626e-4932",
133 "2.00416836000897277799610805135016e-292",
134 "3.36210314311209350626267781732175260e-4932");
135 Max =
PickFP(Sem,
"6.5504e+4",
"3.40282347e+38",
"1.7976931348623157e+308",
136 "1.18973149535723176502e+4932",
137 "1.79769313486231580793728971405301e+308",
138 "1.18973149535723176508575932662800702e+4932");
145 Builder.defineMacro(DefPrefix +
"DENORM_MIN__", Twine(DenormMin)+Ext);
146 Builder.defineMacro(DefPrefix +
"HAS_DENORM__");
147 Builder.defineMacro(DefPrefix +
"DIG__", Twine(Digits));
148 Builder.defineMacro(DefPrefix +
"DECIMAL_DIG__", Twine(DecimalDigits));
149 Builder.defineMacro(DefPrefix +
"EPSILON__", Twine(Epsilon)+Ext);
150 Builder.defineMacro(DefPrefix +
"HAS_INFINITY__");
151 Builder.defineMacro(DefPrefix +
"HAS_QUIET_NAN__");
152 Builder.defineMacro(DefPrefix +
"MANT_DIG__", Twine(MantissaDigits));
154 Builder.defineMacro(DefPrefix +
"MAX_10_EXP__", Twine(Max10Exp));
155 Builder.defineMacro(DefPrefix +
"MAX_EXP__", Twine(MaxExp));
156 Builder.defineMacro(DefPrefix +
"MAX__", Twine(Max)+Ext);
158 Builder.defineMacro(DefPrefix +
"MIN_10_EXP__",
"("+Twine(Min10Exp)+
")");
159 Builder.defineMacro(DefPrefix +
"MIN_EXP__",
"("+Twine(MinExp)+
")");
160 Builder.defineMacro(DefPrefix +
"MIN__", Twine(Min)+Ext);
168 StringRef ValSuffix,
bool isSigned,
170 llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
171 : llvm::APInt::getMaxValue(TypeWidth);
172 Builder.defineMacro(MacroName,
toString(MaxVal, 10, isSigned) + ValSuffix);
187 for (
const char *Fmt = IsSigned ?
"di" :
"ouxX"; *Fmt; ++Fmt) {
188 Builder.defineMacro(Prefix +
"_FMT" + Twine(*Fmt) +
"__",
189 Twine(
"\"") + FmtModifier + Twine(*Fmt) +
"\"");
200 Builder.defineMacro(MacroName, Twine(TI.
getTypeWidth(Ty)));
205 Builder.defineMacro(MacroName,
235 const char *Prefix = IsSigned ?
"__INT" :
"__UINT";
237 DefineType(Prefix + Twine(TypeWidth) +
"_TYPE__", Ty, Builder);
238 DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
241 Builder.defineMacro(Prefix + Twine(TypeWidth) +
"_C_SUFFIX__", ConstSuffix);
257 const char *Prefix = IsSigned ?
"__INT" :
"__UINT";
258 DefineTypeSize(Prefix + Twine(TypeWidth) +
"_MAX__", Ty, TI, Builder);
268 const char *Prefix = IsSigned ?
"__INT_LEAST" :
"__UINT_LEAST";
269 DefineType(Prefix + Twine(TypeWidth) +
"_TYPE__", Ty, Builder);
275 DefineTypeSize(Prefix + Twine(TypeWidth) +
"_MAX__", Ty, TI, Builder);
276 DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
287 const char *Prefix = IsSigned ?
"__INT_FAST" :
"__UINT_FAST";
288 DefineType(Prefix + Twine(TypeWidth) +
"_TYPE__", Ty, Builder);
294 DefineTypeSize(Prefix + Twine(TypeWidth) +
"_MAX__", Ty, TI, Builder);
295 DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
302 unsigned InlineWidth) {
305 if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
306 TypeWidth <= InlineWidth)
317 Builder.defineMacro(
"_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
326 llvm::raw_string_ostream Out(Result);
328 Out <<
"namespace std {\n"
330 <<
"struct __true_type;\n"
331 <<
"struct __false_type;\n"
334 Out <<
"template<typename _Tp> struct __is_scalar;\n"
337 if (LangOpts.ObjCAutoRefCount) {
338 Out <<
"template<typename _Tp>\n"
339 <<
"struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
340 <<
" enum { __value = 0 };\n"
341 <<
" typedef __false_type __type;\n"
346 if (LangOpts.ObjCWeak) {
347 Out <<
"template<typename _Tp>\n"
348 <<
"struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
349 <<
" enum { __value = 0 };\n"
350 <<
" typedef __false_type __type;\n"
355 if (LangOpts.ObjCAutoRefCount) {
356 Out <<
"template<typename _Tp>\n"
357 <<
"struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
359 <<
" enum { __value = 0 };\n"
360 <<
" typedef __false_type __type;\n"
367 Builder.append(Result);
375 Builder.defineMacro(
"__hlsl_clang");
377 Builder.defineMacro(
"__HLSL_VERSION",
378 Twine((
unsigned)LangOpts.getHLSLVersion()));
382 Builder.defineMacro(
"__SHADER_STAGE_VERTEX",
384 Builder.defineMacro(
"__SHADER_STAGE_PIXEL",
386 Builder.defineMacro(
"__SHADER_STAGE_GEOMETRY",
388 Builder.defineMacro(
"__SHADER_STAGE_HULL",
390 Builder.defineMacro(
"__SHADER_STAGE_DOMAIN",
392 Builder.defineMacro(
"__SHADER_STAGE_COMPUTE",
394 Builder.defineMacro(
"__SHADER_STAGE_AMPLIFICATION",
396 Builder.defineMacro(
"__SHADER_STAGE_MESH",
398 Builder.defineMacro(
"__SHADER_STAGE_LIBRARY",
401 uint32_t StageInteger = (uint32_t)TI.
getTriple().getEnvironment() -
402 (uint32_t)llvm::Triple::Pixel;
404 Builder.defineMacro(
"__SHADER_TARGET_STAGE", Twine(StageInteger));
406 if (TI.
getTriple().getOS() == llvm::Triple::ShaderModel) {
407 VersionTuple Version = TI.
getTriple().getOSVersion();
408 Builder.defineMacro(
"__SHADER_TARGET_MAJOR", Twine(Version.getMajor()));
409 unsigned Minor = Version.getMinor() ? *Version.getMinor() : 0;
410 Builder.defineMacro(
"__SHADER_TARGET_MINOR", Twine(Minor));
421 if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP)
422 Builder.defineMacro(
"__STDC__");
426 if (LangOpts.Freestanding)
427 Builder.defineMacro(
"__STDC_HOSTED__",
"0");
429 Builder.defineMacro(
"__STDC_HOSTED__");
435 if (!LangOpts.CPlusPlus) {
438 Builder.defineMacro(
"__STDC_VERSION__",
"202000L");
439 else if (LangOpts.C17)
440 Builder.defineMacro(
"__STDC_VERSION__",
"201710L");
441 else if (LangOpts.C11)
442 Builder.defineMacro(
"__STDC_VERSION__",
"201112L");
443 else if (LangOpts.C99)
444 Builder.defineMacro(
"__STDC_VERSION__",
"199901L");
445 else if (!LangOpts.GNUMode && LangOpts.Digraphs)
446 Builder.defineMacro(
"__STDC_VERSION__",
"199409L");
450 if (LangOpts.CPlusPlus2b)
451 Builder.defineMacro(
"__cplusplus",
"202101L");
453 else if (LangOpts.CPlusPlus20)
454 Builder.defineMacro(
"__cplusplus",
"202002L");
456 else if (LangOpts.CPlusPlus17)
457 Builder.defineMacro(
"__cplusplus",
"201703L");
460 else if (LangOpts.CPlusPlus14)
461 Builder.defineMacro(
"__cplusplus",
"201402L");
464 else if (LangOpts.CPlusPlus11)
465 Builder.defineMacro(
"__cplusplus",
"201103L");
469 Builder.defineMacro(
"__cplusplus",
"199711L");
476 Builder.defineMacro(
"__STDCPP_DEFAULT_NEW_ALIGNMENT__",
484 Builder.defineMacro(
"__STDCPP_THREADS__",
"1");
492 Builder.defineMacro(
"__STDC_UTF_16__",
"1");
493 Builder.defineMacro(
"__STDC_UTF_32__",
"1");
496 Builder.defineMacro(
"__OBJC__");
499 if (LangOpts.OpenCL) {
500 if (LangOpts.CPlusPlus) {
501 switch (LangOpts.OpenCLCPlusPlusVersion) {
503 Builder.defineMacro(
"__OPENCL_CPP_VERSION__",
"100");
506 Builder.defineMacro(
"__OPENCL_CPP_VERSION__",
"202100");
509 llvm_unreachable(
"Unsupported C++ version for OpenCL");
511 Builder.defineMacro(
"__CL_CPP_VERSION_1_0__",
"100");
512 Builder.defineMacro(
"__CL_CPP_VERSION_2021__",
"202100");
521 switch (LangOpts.OpenCLVersion) {
523 Builder.defineMacro(
"__OPENCL_C_VERSION__",
"100");
526 Builder.defineMacro(
"__OPENCL_C_VERSION__",
"110");
529 Builder.defineMacro(
"__OPENCL_C_VERSION__",
"120");
532 Builder.defineMacro(
"__OPENCL_C_VERSION__",
"200");
535 Builder.defineMacro(
"__OPENCL_C_VERSION__",
"300");
538 llvm_unreachable(
"Unsupported OpenCL version");
541 Builder.defineMacro(
"CL_VERSION_1_0",
"100");
542 Builder.defineMacro(
"CL_VERSION_1_1",
"110");
543 Builder.defineMacro(
"CL_VERSION_1_2",
"120");
544 Builder.defineMacro(
"CL_VERSION_2_0",
"200");
545 Builder.defineMacro(
"CL_VERSION_3_0",
"300");
548 Builder.defineMacro(
"__ENDIAN_LITTLE__");
550 if (LangOpts.FastRelaxedMath)
551 Builder.defineMacro(
"__FAST_RELAXED_MATH__");
554 if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) {
557 Builder.defineMacro(
"CL_SYCL_LANGUAGE_VERSION",
"121");
559 Builder.defineMacro(
"SYCL_LANGUAGE_VERSION",
"202001");
563 if (LangOpts.AsmPreprocessor)
564 Builder.defineMacro(
"__ASSEMBLER__");
566 if (LangOpts.GPURelocatableDeviceCode)
567 Builder.defineMacro(
"__CLANG_RDC__");
569 Builder.defineMacro(
"__CUDA__");
572 Builder.defineMacro(
"__HIP__");
573 Builder.defineMacro(
"__HIPCC__");
574 Builder.defineMacro(
"__HIP_MEMORY_SCOPE_SINGLETHREAD",
"1");
575 Builder.defineMacro(
"__HIP_MEMORY_SCOPE_WAVEFRONT",
"2");
576 Builder.defineMacro(
"__HIP_MEMORY_SCOPE_WORKGROUP",
"3");
577 Builder.defineMacro(
"__HIP_MEMORY_SCOPE_AGENT",
"4");
578 Builder.defineMacro(
"__HIP_MEMORY_SCOPE_SYSTEM",
"5");
579 if (LangOpts.CUDAIsDevice)
580 Builder.defineMacro(
"__HIP_DEVICE_COMPILE__");
583 Builder.defineMacro(
"HIP_API_PER_THREAD_DEFAULT_STREAM");
593 Builder.defineMacro(
"__cpp_rtti",
"199711L");
594 if (LangOpts.CXXExceptions)
595 Builder.defineMacro(
"__cpp_exceptions",
"199711L");
598 if (LangOpts.CPlusPlus11) {
599 Builder.defineMacro(
"__cpp_unicode_characters",
"200704L");
600 Builder.defineMacro(
"__cpp_raw_strings",
"200710L");
601 Builder.defineMacro(
"__cpp_unicode_literals",
"200710L");
602 Builder.defineMacro(
"__cpp_user_defined_literals",
"200809L");
603 Builder.defineMacro(
"__cpp_lambdas",
"200907L");
604 Builder.defineMacro(
"__cpp_constexpr", LangOpts.CPlusPlus2b ?
"202110L"
605 : LangOpts.CPlusPlus20 ?
"201907L"
606 : LangOpts.CPlusPlus17 ?
"201603L"
607 : LangOpts.CPlusPlus14 ?
"201304L"
609 Builder.defineMacro(
"__cpp_constexpr_in_decltype",
"201711L");
610 Builder.defineMacro(
"__cpp_range_based_for",
611 LangOpts.CPlusPlus17 ?
"201603L" :
"200907");
612 Builder.defineMacro(
"__cpp_static_assert",
613 LangOpts.CPlusPlus17 ?
"201411L" :
"200410");
614 Builder.defineMacro(
"__cpp_decltype",
"200707L");
615 Builder.defineMacro(
"__cpp_attributes",
"200809L");
616 Builder.defineMacro(
"__cpp_rvalue_references",
"200610L");
617 Builder.defineMacro(
"__cpp_variadic_templates",
"200704L");
618 Builder.defineMacro(
"__cpp_initializer_lists",
"200806L");
619 Builder.defineMacro(
"__cpp_delegating_constructors",
"200604L");
620 Builder.defineMacro(
"__cpp_nsdmi",
"200809L");
621 Builder.defineMacro(
"__cpp_inheriting_constructors",
"201511L");
622 Builder.defineMacro(
"__cpp_ref_qualifiers",
"200710L");
623 Builder.defineMacro(
"__cpp_alias_templates",
"200704L");
625 if (LangOpts.ThreadsafeStatics)
626 Builder.defineMacro(
"__cpp_threadsafe_static_init",
"200806L");
629 if (LangOpts.CPlusPlus14) {
630 Builder.defineMacro(
"__cpp_binary_literals",
"201304L");
631 Builder.defineMacro(
"__cpp_digit_separators",
"201309L");
632 Builder.defineMacro(
"__cpp_init_captures",
633 LangOpts.CPlusPlus20 ?
"201803L" :
"201304L");
634 Builder.defineMacro(
"__cpp_generic_lambdas",
635 LangOpts.CPlusPlus20 ?
"201707L" :
"201304L");
636 Builder.defineMacro(
"__cpp_decltype_auto",
"201304L");
637 Builder.defineMacro(
"__cpp_return_type_deduction",
"201304L");
638 Builder.defineMacro(
"__cpp_aggregate_nsdmi",
"201304L");
639 Builder.defineMacro(
"__cpp_variable_templates",
"201304L");
641 if (LangOpts.SizedDeallocation)
642 Builder.defineMacro(
"__cpp_sized_deallocation",
"201309L");
645 if (LangOpts.CPlusPlus17) {
646 Builder.defineMacro(
"__cpp_hex_float",
"201603L");
647 Builder.defineMacro(
"__cpp_inline_variables",
"201606L");
648 Builder.defineMacro(
"__cpp_noexcept_function_type",
"201510L");
649 Builder.defineMacro(
"__cpp_capture_star_this",
"201603L");
650 Builder.defineMacro(
"__cpp_if_constexpr",
"201606L");
651 Builder.defineMacro(
"__cpp_deduction_guides",
"201703L");
652 Builder.defineMacro(
"__cpp_template_auto",
"201606L");
653 Builder.defineMacro(
"__cpp_namespace_attributes",
"201411L");
654 Builder.defineMacro(
"__cpp_enumerator_attributes",
"201411L");
655 Builder.defineMacro(
"__cpp_nested_namespace_definitions",
"201411L");
656 Builder.defineMacro(
"__cpp_variadic_using",
"201611L");
657 Builder.defineMacro(
"__cpp_aggregate_bases",
"201603L");
658 Builder.defineMacro(
"__cpp_structured_bindings",
"201606L");
659 Builder.defineMacro(
"__cpp_nontype_template_args",
661 Builder.defineMacro(
"__cpp_fold_expressions",
"201603L");
662 Builder.defineMacro(
"__cpp_guaranteed_copy_elision",
"201606L");
663 Builder.defineMacro(
"__cpp_nontype_template_parameter_auto",
"201606L");
665 if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
666 Builder.defineMacro(
"__cpp_aligned_new",
"201606L");
667 if (LangOpts.RelaxedTemplateTemplateArgs)
668 Builder.defineMacro(
"__cpp_template_template_args",
"201611L");
671 if (LangOpts.CPlusPlus20) {
673 Builder.defineMacro(
"__cpp_concepts",
"201907L");
674 Builder.defineMacro(
"__cpp_conditional_explicit",
"201806L");
676 Builder.defineMacro(
"__cpp_constexpr_dynamic_alloc",
"201907L");
677 Builder.defineMacro(
"__cpp_constinit",
"201907L");
678 Builder.defineMacro(
"__cpp_impl_coroutine",
"201902L");
679 Builder.defineMacro(
"__cpp_designated_initializers",
"201707L");
680 Builder.defineMacro(
"__cpp_impl_three_way_comparison",
"201907L");
682 Builder.defineMacro(
"__cpp_using_enum",
"201907L");
685 if (LangOpts.CPlusPlus2b) {
686 Builder.defineMacro(
"__cpp_implicit_move",
"202011L");
687 Builder.defineMacro(
"__cpp_size_t_suffix",
"202011L");
688 Builder.defineMacro(
"__cpp_if_consteval",
"202106L");
689 Builder.defineMacro(
"__cpp_multidimensional_subscript",
"202110L");
692 Builder.defineMacro(
"__cpp_char8_t",
"201811L");
693 Builder.defineMacro(
"__cpp_impl_destroying_delete",
"201806L");
696 if (LangOpts.Coroutines)
697 Builder.defineMacro(
"__cpp_coroutines",
"201703L");
708 auto defineOpenCLExtMacro = [&](llvm::StringRef Name,
auto... OptArgs) {
713 Builder.defineMacro(Name);
715 #define OPENCL_GENERIC_EXTENSION(Ext, ...) \
716 defineOpenCLExtMacro(#Ext, __VA_ARGS__);
717 #include "clang/Basic/OpenCLExtensions.def"
720 Builder.defineMacro(
"__opencl_c_int64");
729 Builder.defineMacro(
"__llvm__");
730 Builder.defineMacro(
"__clang__");
732 #define TOSTR(X) TOSTR2(X)
733 Builder.defineMacro(
"__clang_major__",
TOSTR(CLANG_VERSION_MAJOR));
734 Builder.defineMacro(
"__clang_minor__",
TOSTR(CLANG_VERSION_MINOR));
735 Builder.defineMacro(
"__clang_patchlevel__",
TOSTR(CLANG_VERSION_PATCHLEVEL));
738 Builder.defineMacro(
"__clang_version__",
739 "\"" CLANG_VERSION_STRING
" "
742 if (LangOpts.GNUCVersion != 0) {
745 unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100;
746 unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100;
747 unsigned GNUCPatch = LangOpts.GNUCVersion % 100;
748 Builder.defineMacro(
"__GNUC__", Twine(GNUCMajor));
749 Builder.defineMacro(
"__GNUC_MINOR__", Twine(GNUCMinor));
750 Builder.defineMacro(
"__GNUC_PATCHLEVEL__", Twine(GNUCPatch));
751 Builder.defineMacro(
"__GXX_ABI_VERSION",
"1002");
753 if (LangOpts.CPlusPlus) {
754 Builder.defineMacro(
"__GNUG__", Twine(GNUCMajor));
755 Builder.defineMacro(
"__GXX_WEAK__");
760 Builder.defineMacro(
"__ATOMIC_RELAXED",
"0");
761 Builder.defineMacro(
"__ATOMIC_CONSUME",
"1");
762 Builder.defineMacro(
"__ATOMIC_ACQUIRE",
"2");
763 Builder.defineMacro(
"__ATOMIC_RELEASE",
"3");
764 Builder.defineMacro(
"__ATOMIC_ACQ_REL",
"4");
765 Builder.defineMacro(
"__ATOMIC_SEQ_CST",
"5");
774 "Invalid OpenCL memory scope enum definition");
775 Builder.defineMacro(
"__OPENCL_MEMORY_SCOPE_WORK_ITEM",
"0");
776 Builder.defineMacro(
"__OPENCL_MEMORY_SCOPE_WORK_GROUP",
"1");
777 Builder.defineMacro(
"__OPENCL_MEMORY_SCOPE_DEVICE",
"2");
778 Builder.defineMacro(
"__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES",
"3");
779 Builder.defineMacro(
"__OPENCL_MEMORY_SCOPE_SUB_GROUP",
"4");
782 Builder.defineMacro(
"__PRAGMA_REDEFINE_EXTNAME",
"1");
786 Builder.defineMacro(
"__VERSION__",
"\"" +
792 if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
793 Builder.defineMacro(
"__STRICT_ANSI__");
795 if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
796 Builder.defineMacro(
"__GXX_EXPERIMENTAL_CXX0X__");
800 Builder.defineMacro(
"__OBJC2__");
802 if (LangOpts.ObjCExceptions)
803 Builder.defineMacro(
"OBJC_ZEROCOST_EXCEPTIONS");
807 Builder.defineMacro(
"__OBJC_GC__");
810 Builder.defineMacro(
"__NEXT_RUNTIME__");
818 if (version >= VersionTuple(2, 0))
819 Builder.defineMacro(
"__OBJC_GNUSTEP_RUNTIME_ABI__",
"20");
821 Builder.defineMacro(
"__OBJC_GNUSTEP_RUNTIME_ABI__",
822 "1" + Twine(
std::min(8
U, version.getMinor().getValueOr(0))));
829 if (tuple.getMinor().hasValue())
830 minor = tuple.getMinor().getValue();
832 unsigned subminor = 0;
833 if (tuple.getSubminor().hasValue())
834 subminor = tuple.getSubminor().getValue();
836 Builder.defineMacro(
"__OBJFW_RUNTIME_ABI__",
837 Twine(tuple.getMajor() * 10000 + minor * 100 +
841 Builder.defineMacro(
"IBOutlet",
"__attribute__((iboutlet))");
842 Builder.defineMacro(
"IBOutletCollection(ClassName)",
843 "__attribute__((iboutletcollection(ClassName)))");
844 Builder.defineMacro(
"IBAction",
"void)__attribute__((ibaction)");
845 Builder.defineMacro(
"IBInspectable",
"");
846 Builder.defineMacro(
"IB_DESIGNABLE",
"");
851 Builder.defineMacro(
"__OBJC_BOOL_IS_BOOL",
854 if (LangOpts.CPlusPlus)
859 if (!LangOpts.NoConstantCFStrings)
860 Builder.defineMacro(
"__CONSTANT_CFSTRINGS__");
863 Builder.defineMacro(
"OBJC_NEW_PROPERTIES");
865 if (LangOpts.PascalStrings)
866 Builder.defineMacro(
"__PASCAL_STRINGS__");
868 if (LangOpts.Blocks) {
869 Builder.defineMacro(
"__block",
"__attribute__((__blocks__(byref)))");
870 Builder.defineMacro(
"__BLOCKS__");
873 if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
874 Builder.defineMacro(
"__EXCEPTIONS");
875 if (LangOpts.GNUCVersion && LangOpts.RTTI)
876 Builder.defineMacro(
"__GXX_RTTI");
879 Builder.defineMacro(
"__USING_SJLJ_EXCEPTIONS__");
881 Builder.defineMacro(
"__SEH__");
884 Builder.defineMacro(
"__ARM_DWARF_EH__");
886 if (LangOpts.Deprecated)
887 Builder.defineMacro(
"__DEPRECATED");
889 if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus)
890 Builder.defineMacro(
"__private_extern__",
"extern");
892 if (LangOpts.MicrosoftExt) {
893 if (LangOpts.WChar) {
895 Builder.defineMacro(
"_WCHAR_T_DEFINED");
896 Builder.defineMacro(
"_NATIVE_WCHAR_T_DEFINED");
903 Builder.defineMacro(
"__clang_literal_encoding__",
"\"UTF-8\"");
907 Builder.defineMacro(
"__clang_wide_literal_encoding__",
"\"UTF-32\"");
912 Builder.defineMacro(
"__clang_wide_literal_encoding__",
"\"UTF-16\"");
915 if (LangOpts.Optimize)
916 Builder.defineMacro(
"__OPTIMIZE__");
917 if (LangOpts.OptimizeSize)
918 Builder.defineMacro(
"__OPTIMIZE_SIZE__");
920 if (LangOpts.FastMath)
921 Builder.defineMacro(
"__FAST_MATH__");
930 Builder.defineMacro(
"__ORDER_LITTLE_ENDIAN__",
"1234");
931 Builder.defineMacro(
"__ORDER_BIG_ENDIAN__",
"4321");
932 Builder.defineMacro(
"__ORDER_PDP_ENDIAN__",
"3412");
934 Builder.defineMacro(
"__BYTE_ORDER__",
"__ORDER_BIG_ENDIAN__");
935 Builder.defineMacro(
"__BIG_ENDIAN__");
937 Builder.defineMacro(
"__BYTE_ORDER__",
"__ORDER_LITTLE_ENDIAN__");
938 Builder.defineMacro(
"__LITTLE_ENDIAN__");
943 Builder.defineMacro(
"_LP64");
944 Builder.defineMacro(
"__LP64__");
949 Builder.defineMacro(
"_ILP32");
950 Builder.defineMacro(
"__ILP32__");
954 assert(TI.
getCharWidth() == 8 &&
"Only support 8-bit char so far");
955 Builder.defineMacro(
"__CHAR_BIT__", Twine(TI.
getCharWidth()));
957 Builder.defineMacro(
"__BOOL_WIDTH__", Twine(TI.
getBoolWidth()));
958 Builder.defineMacro(
"__SHRT_WIDTH__", Twine(TI.
getShortWidth()));
959 Builder.defineMacro(
"__INT_WIDTH__", Twine(TI.
getIntWidth()));
960 Builder.defineMacro(
"__LONG_WIDTH__", Twine(TI.
getLongWidth()));
964 assert(BitIntMaxWidth <= llvm::IntegerType::MAX_INT_BITS &&
965 "Target defined a max bit width larger than LLVM can support!");
967 "Target defined a max bit width smaller than the C standard allows!");
968 Builder.defineMacro(
"__BITINT_MAXWIDTH__", Twine(BitIntMaxWidth));
1006 Builder.defineMacro(
"__INTMAX_C_SUFFIX__",
1010 Builder.defineMacro(
"__UINTMAX_C_SUFFIX__",
1031 "uintptr_t and intptr_t have different widths?");
1034 "uintmax_t and intmax_t have different widths?");
1043 Builder.defineMacro(
"__POINTER_WIDTH__",
1047 Builder.defineMacro(
"__BIGGEST_ALIGNMENT__",
1050 if (!LangOpts.CharIsSigned)
1051 Builder.defineMacro(
"__CHAR_UNSIGNED__");
1054 Builder.defineMacro(
"__WCHAR_UNSIGNED__");
1057 Builder.defineMacro(
"__WINT_UNSIGNED__");
1122 if (!LangOpts.MathErrno)
1123 Builder.defineMacro(
"__NO_MATH_ERRNO__");
1125 if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
1126 Builder.defineMacro(
"__FINITE_MATH_ONLY__",
"1");
1128 Builder.defineMacro(
"__FINITE_MATH_ONLY__",
"0");
1130 if (LangOpts.GNUCVersion) {
1131 if (LangOpts.GNUInline || LangOpts.CPlusPlus)
1132 Builder.defineMacro(
"__GNUC_GNU_INLINE__");
1134 Builder.defineMacro(
"__GNUC_STDC_INLINE__");
1138 Builder.defineMacro(
"__GCC_ATOMIC_TEST_AND_SET_TRUEVAL",
"1");
1141 auto addLockFreeMacros = [&](
const llvm::Twine &Prefix) {
1144 #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
1145 Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \
1146 getLockFreeValue(TI.get##Type##Width(), \
1147 TI.get##Type##Align(), \
1160 Builder.defineMacro(Prefix +
"POINTER_LOCK_FREE",
1164 #undef DEFINE_LOCK_FREE_MACRO
1166 addLockFreeMacros(
"__CLANG_ATOMIC_");
1167 if (LangOpts.GNUCVersion)
1168 addLockFreeMacros(
"__GCC_ATOMIC_");
1170 if (LangOpts.NoInlineDefine)
1171 Builder.defineMacro(
"__NO_INLINE__");
1173 if (
unsigned PICLevel = LangOpts.PICLevel) {
1174 Builder.defineMacro(
"__PIC__", Twine(PICLevel));
1175 Builder.defineMacro(
"__pic__", Twine(PICLevel));
1177 Builder.defineMacro(
"__PIE__", Twine(PICLevel));
1178 Builder.defineMacro(
"__pie__", Twine(PICLevel));
1183 Builder.defineMacro(
"__FLT_RADIX__",
"2");
1184 Builder.defineMacro(
"__DECIMAL_DIG__",
"__LDBL_DECIMAL_DIG__");
1187 Builder.defineMacro(
"__SSP__");
1189 Builder.defineMacro(
"__SSP_STRONG__",
"2");
1191 Builder.defineMacro(
"__SSP_ALL__",
"3");
1194 Builder.defineMacro(
"__clang_analyzer__");
1196 if (LangOpts.FastRelaxedMath)
1197 Builder.defineMacro(
"__FAST_RELAXED_MATH__");
1201 Builder.defineMacro(
"__weak",
"__attribute__((objc_gc(weak)))");
1202 Builder.defineMacro(
"__strong",
"__attribute__((objc_gc(strong)))");
1203 Builder.defineMacro(
"__autoreleasing",
"");
1204 Builder.defineMacro(
"__unsafe_unretained",
"");
1205 }
else if (LangOpts.ObjC) {
1206 Builder.defineMacro(
"__weak",
"__attribute__((objc_ownership(weak)))");
1207 Builder.defineMacro(
"__strong",
"__attribute__((objc_ownership(strong)))");
1208 Builder.defineMacro(
"__autoreleasing",
1209 "__attribute__((objc_ownership(autoreleasing)))");
1210 Builder.defineMacro(
"__unsafe_unretained",
1211 "__attribute__((objc_ownership(none)))");
1217 Builder.defineMacro(
"__nonnull",
"_Nonnull");
1218 Builder.defineMacro(
"__null_unspecified",
"_Null_unspecified");
1219 Builder.defineMacro(
"__nullable",
"_Nullable");
1225 Builder.defineMacro(
"__APPLE_EMBEDDED_SIMULATOR__",
"1");
1233 if (!LangOpts.OpenMPSimd) {
1234 switch (LangOpts.OpenMP) {
1238 Builder.defineMacro(
"_OPENMP",
"201107");
1241 Builder.defineMacro(
"_OPENMP",
"201307");
1244 Builder.defineMacro(
"_OPENMP",
"201511");
1247 Builder.defineMacro(
"_OPENMP",
"202011");
1250 Builder.defineMacro(
"_OPENMP",
"202111");
1255 Builder.defineMacro(
"_OPENMP",
"201811");
1261 if (LangOpts.CUDAIsDevice && !LangOpts.HIP) {
1264 Builder.defineMacro(
"__CUDA_ARCH__");
1269 if (LangOpts.CUDADeviceApproxTranscendentals || LangOpts.FastMath) {
1270 Builder.defineMacro(
"__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
1275 if (LangOpts.SYCLIsDevice) {
1276 Builder.defineMacro(
"__SYCL_DEVICE_ONLY__",
"1");
1280 if (LangOpts.OpenCL) {
1284 Builder.defineMacro(
"__IMAGE_SUPPORT__");
1287 if (TI.
hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
1291 Builder.defineMacro(
"__GLIBCXX_TYPE_INT_N_0",
"__int128");
1292 Builder.defineMacro(
"__GLIBCXX_BITSIZE_INT_N_0",
"128");
1308 PredefineBuffer.reserve(4080);
1309 llvm::raw_string_ostream Predefines(PredefineBuffer);
1316 Builder.append(
"# 1 \"<built-in>\" 3");
1322 if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
1332 if (LangOpts.ObjC && LangOpts.CPlusPlus &&
1333 (LangOpts.ObjCAutoRefCount || LangOpts.ObjCWeak)) {
1355 Builder.append(
"# 1 \"<command line>\" 1");
1358 for (
unsigned i = 0, e = InitOpts.
Macros.size(); i != e; ++i) {
1359 if (InitOpts.
Macros[i].second)
1360 Builder.undefineMacro(InitOpts.
Macros[i].first);
1368 Builder.append(
"# 1 \"<built-in>\" 2");
1372 for (
unsigned i = 0, e = InitOpts.
MacroIncludes.size(); i != e; ++i)
1381 for (
unsigned i = 0, e = InitOpts.
Includes.size(); i != e; ++i) {
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
bool hasSEHExceptions() const
const llvm::fltSemantics & getLongDoubleFormat() const
static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro, DiagnosticsEngine &Diags)
bool SetUpStaticAnalyzer
Set up preprocessor for RunAnalysis action.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
frontend::ActionKind ProgramAction
The frontend action to perform.
const llvm::fltSemantics & getDoubleFormat() const
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
unsigned getSuitableAlign() const
Return the alignment that is the largest alignment ever used for any scalar/SIMD data type on the tar...
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' is g...
static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty, MacroBuilder &Builder)
const char * getUserLabelPrefix() const
Returns the default value of the USER_LABEL_PREFIX macro, which is the prefix given to user symbols b...
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
static void DefineExactWidthIntType(TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
static void DefineTypeWidth(const Twine &MacroName, TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
Concrete class used by the front-end to report problems and issues.
Exposes information about the current target.
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
unsigned getBoolWidth() const
Return the size of '_Bool' and C++ 'bool' for this target, in bits.
unsigned getCharWidth() const
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal, T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, T IEEEQuadVal)
PickFP - This is used to pick a value based on the FP semantics of the specified FP model.
bool hasDWARFExceptions() const
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
@ RewriteObjC
ObjC->C Rewriter.
void setPredefines(std::string P)
Set the predefines for this Preprocessor.
std::vector< std::string > Includes
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
IntType getPtrDiffType(unsigned AddrSpace) const
IntType getUInt64Type() const
const LangOptions & getLangOpts() const
static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP, const PCHContainerReader &PCHContainerRdr, StringRef ImplicitIncludePCH)
Add an implicit #include using the original file used to generate a PCH file.
const VersionTuple & getVersion() const
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
unsigned getLongDoubleWidth() const
getLongDoubleWidth/Align/Format - Return the size/align/format of 'long double'.
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
bool useSignedCharForObjCBool() const
Check if the Objective-C built-in boolean type should be signed char.
static void AddImplicitInclude(MacroBuilder &Builder, StringRef File)
AddImplicitInclude - Add an implicit #include of the specified file to the predefines buffer.
IntType getIntPtrType() const
__DEVICE__ int min(int __a, int __b)
void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI, const LangOptions &Opts, MacroBuilder &Builder)
InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target settings and language versio...
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
clang::ObjCRuntime ObjCRuntime
bool isLittleEndian() const
IntType getChar32Type() const
std::string toString(const til::SExpr *E)
uint64_t getPointerAlign(unsigned AddrSpace) const
FrontendOptions - Options for controlling the behavior of the frontend.
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts)
InitializePreprocessor - Initialize the preprocessor getting it and the environment ready to process ...
static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, const PreprocessorOptions &PPOpts, MacroBuilder &Builder)
const TargetInfo & getTargetInfo() const
#define DEFINE_LOCK_FREE_MACRO(TYPE, Type)
const llvm::fltSemantics & getFloatFormat() const
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
bool hasSjLjExceptions() const
static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
const llvm::fltSemantics & getHalfFormat() const
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
static bool MacroBodyEndsInBackslash(StringRef MacroBody)
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
virtual size_t getMaxBitIntWidth() const
static const char * getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign, unsigned InlineWidth)
Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with the specified properties.
bool isNeXTFamily() const
Is this runtime basically of the NeXT family of runtimes?
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth, StringRef ValSuffix, bool isSigned, MacroBuilder &Builder)
DefineTypeSize - Emit a macro to the predefines buffer that declares a macro named MacroName with the...
@ ObjFW
'objfw' is the Objective-C runtime included in ObjFW
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
IntType getSizeType() const
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
IntType getUInt16Type() const
virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const =0
===-— Other target property query methods -----------------------—===//
IntType getInt16Type() const
const TargetInfo * getAuxTargetInfo() const
IntType getUIntPtrType() const
static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned, const TargetInfo &TI, MacroBuilder &Builder)
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, MacroBuilder &Builder)
Initialize the predefined C++ language feature test macros defined in ISO/IEC JTC1/SC22/WG21 (C++) SD...
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
IntType getWIntType() const
static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File)
GPUDefaultStreamKind GPUDefaultStream
The default stream kind used for HIP kernel launching.
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts, MacroBuilder &Builder)
Add definitions required for a smooth interaction between Objective-C++ automated reference counting ...
IntType getUIntMaxType() const
IntType getIntMaxType() const
FileManager & getFileManager() const
static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, const llvm::fltSemantics *Sem, StringRef Ext)
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
IntType
===-— Target Data Type Query Methods ----------------------------—===//
IntType getChar16Type() const
static void DefineFastIntType(unsigned TypeWidth, bool IsSigned, const TargetInfo &TI, MacroBuilder &Builder)
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
@ ARCXX_libstdcxx
libstdc++
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
@ PerThread
Per-thread default stream.
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
DiagnosticsEngine & getDiagnostics() const
IntType getSigAtomicType() const
std::vector< std::string > MacroIncludes
static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
IntType getInt64Type() const
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
static bool isOpenCLOptionAvailableIn(const LangOptions &LO, Args &&... args)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
static void DefineTypeSizeAndWidth(const Twine &Prefix, TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
std::string getClangFullCPPVersion()
Retrieves a string representing the complete clang version suitable for use in the CPP VERSION macro,...
IntType getWCharType() const
static void InitializeStandardPredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, MacroBuilder &Builder)
std::vector< std::pair< std::string, bool > > Macros
static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth, const TargetInfo &TI, MacroBuilder &Builder)
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.