17330f729Sjoerg //===--- InitPreprocessor.cpp - PP initialization code. ---------*- C++ -*-===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg //
97330f729Sjoerg // This file implements the clang::InitializePreprocessor function.
107330f729Sjoerg //
117330f729Sjoerg //===----------------------------------------------------------------------===//
127330f729Sjoerg
137330f729Sjoerg #include "clang/Basic/FileManager.h"
147330f729Sjoerg #include "clang/Basic/MacroBuilder.h"
157330f729Sjoerg #include "clang/Basic/SourceManager.h"
167330f729Sjoerg #include "clang/Basic/SyncScope.h"
177330f729Sjoerg #include "clang/Basic/TargetInfo.h"
187330f729Sjoerg #include "clang/Basic/Version.h"
197330f729Sjoerg #include "clang/Frontend/FrontendDiagnostic.h"
207330f729Sjoerg #include "clang/Frontend/FrontendOptions.h"
217330f729Sjoerg #include "clang/Frontend/Utils.h"
227330f729Sjoerg #include "clang/Lex/HeaderSearch.h"
237330f729Sjoerg #include "clang/Lex/Preprocessor.h"
247330f729Sjoerg #include "clang/Lex/PreprocessorOptions.h"
257330f729Sjoerg #include "clang/Serialization/ASTReader.h"
267330f729Sjoerg #include "llvm/ADT/APFloat.h"
277330f729Sjoerg #include "llvm/IR/DataLayout.h"
287330f729Sjoerg using namespace clang;
297330f729Sjoerg
MacroBodyEndsInBackslash(StringRef MacroBody)307330f729Sjoerg static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
317330f729Sjoerg while (!MacroBody.empty() && isWhitespace(MacroBody.back()))
327330f729Sjoerg MacroBody = MacroBody.drop_back();
337330f729Sjoerg return !MacroBody.empty() && MacroBody.back() == '\\';
347330f729Sjoerg }
357330f729Sjoerg
367330f729Sjoerg // Append a #define line to Buf for Macro. Macro should be of the form XXX,
377330f729Sjoerg // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
387330f729Sjoerg // "#define XXX Y z W". To get a #define with no value, use "XXX=".
DefineBuiltinMacro(MacroBuilder & Builder,StringRef Macro,DiagnosticsEngine & Diags)397330f729Sjoerg static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
407330f729Sjoerg DiagnosticsEngine &Diags) {
417330f729Sjoerg std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
427330f729Sjoerg StringRef MacroName = MacroPair.first;
437330f729Sjoerg StringRef MacroBody = MacroPair.second;
447330f729Sjoerg if (MacroName.size() != Macro.size()) {
457330f729Sjoerg // Per GCC -D semantics, the macro ends at \n if it exists.
467330f729Sjoerg StringRef::size_type End = MacroBody.find_first_of("\n\r");
477330f729Sjoerg if (End != StringRef::npos)
487330f729Sjoerg Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
497330f729Sjoerg << MacroName;
507330f729Sjoerg MacroBody = MacroBody.substr(0, End);
517330f729Sjoerg // We handle macro bodies which end in a backslash by appending an extra
527330f729Sjoerg // backslash+newline. This makes sure we don't accidentally treat the
537330f729Sjoerg // backslash as a line continuation marker.
547330f729Sjoerg if (MacroBodyEndsInBackslash(MacroBody))
557330f729Sjoerg Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
567330f729Sjoerg else
577330f729Sjoerg Builder.defineMacro(MacroName, MacroBody);
587330f729Sjoerg } else {
597330f729Sjoerg // Push "macroname 1".
607330f729Sjoerg Builder.defineMacro(Macro);
617330f729Sjoerg }
627330f729Sjoerg }
637330f729Sjoerg
647330f729Sjoerg /// AddImplicitInclude - Add an implicit \#include of the specified file to the
657330f729Sjoerg /// predefines buffer.
667330f729Sjoerg /// As these includes are generated by -include arguments the header search
677330f729Sjoerg /// logic is going to search relatively to the current working directory.
AddImplicitInclude(MacroBuilder & Builder,StringRef File)687330f729Sjoerg static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
697330f729Sjoerg Builder.append(Twine("#include \"") + File + "\"");
707330f729Sjoerg }
717330f729Sjoerg
AddImplicitIncludeMacros(MacroBuilder & Builder,StringRef File)727330f729Sjoerg static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
737330f729Sjoerg Builder.append(Twine("#__include_macros \"") + File + "\"");
747330f729Sjoerg // Marker token to stop the __include_macros fetch loop.
757330f729Sjoerg Builder.append("##"); // ##?
767330f729Sjoerg }
777330f729Sjoerg
787330f729Sjoerg /// Add an implicit \#include using the original file used to generate
797330f729Sjoerg /// a PCH file.
AddImplicitIncludePCH(MacroBuilder & Builder,Preprocessor & PP,const PCHContainerReader & PCHContainerRdr,StringRef ImplicitIncludePCH)807330f729Sjoerg static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
817330f729Sjoerg const PCHContainerReader &PCHContainerRdr,
827330f729Sjoerg StringRef ImplicitIncludePCH) {
83*e038c9c4Sjoerg std::string OriginalFile = ASTReader::getOriginalSourceFile(
84*e038c9c4Sjoerg std::string(ImplicitIncludePCH), PP.getFileManager(), PCHContainerRdr,
85*e038c9c4Sjoerg PP.getDiagnostics());
867330f729Sjoerg if (OriginalFile.empty())
877330f729Sjoerg return;
887330f729Sjoerg
897330f729Sjoerg AddImplicitInclude(Builder, OriginalFile);
907330f729Sjoerg }
917330f729Sjoerg
927330f729Sjoerg /// PickFP - This is used to pick a value based on the FP semantics of the
937330f729Sjoerg /// specified FP model.
947330f729Sjoerg template <typename T>
PickFP(const llvm::fltSemantics * Sem,T IEEEHalfVal,T IEEESingleVal,T IEEEDoubleVal,T X87DoubleExtendedVal,T PPCDoubleDoubleVal,T IEEEQuadVal)957330f729Sjoerg static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
967330f729Sjoerg T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
977330f729Sjoerg T IEEEQuadVal) {
987330f729Sjoerg if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
997330f729Sjoerg return IEEEHalfVal;
1007330f729Sjoerg if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
1017330f729Sjoerg return IEEESingleVal;
1027330f729Sjoerg if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
1037330f729Sjoerg return IEEEDoubleVal;
1047330f729Sjoerg if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
1057330f729Sjoerg return X87DoubleExtendedVal;
1067330f729Sjoerg if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
1077330f729Sjoerg return PPCDoubleDoubleVal;
1087330f729Sjoerg assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
1097330f729Sjoerg return IEEEQuadVal;
1107330f729Sjoerg }
1117330f729Sjoerg
DefineFloatMacros(MacroBuilder & Builder,StringRef Prefix,const llvm::fltSemantics * Sem,StringRef Ext)1127330f729Sjoerg static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
1137330f729Sjoerg const llvm::fltSemantics *Sem, StringRef Ext) {
1147330f729Sjoerg const char *DenormMin, *Epsilon, *Max, *Min;
1157330f729Sjoerg DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45",
1167330f729Sjoerg "4.9406564584124654e-324", "3.64519953188247460253e-4951",
1177330f729Sjoerg "4.94065645841246544176568792868221e-324",
1187330f729Sjoerg "6.47517511943802511092443895822764655e-4966");
1197330f729Sjoerg int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33);
1207330f729Sjoerg int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36);
1217330f729Sjoerg Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7",
1227330f729Sjoerg "2.2204460492503131e-16", "1.08420217248550443401e-19",
1237330f729Sjoerg "4.94065645841246544176568792868221e-324",
1247330f729Sjoerg "1.92592994438723585305597794258492732e-34");
1257330f729Sjoerg int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113);
1267330f729Sjoerg int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
1277330f729Sjoerg int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
1287330f729Sjoerg int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
1297330f729Sjoerg int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
1307330f729Sjoerg Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308",
1317330f729Sjoerg "3.36210314311209350626e-4932",
1327330f729Sjoerg "2.00416836000897277799610805135016e-292",
1337330f729Sjoerg "3.36210314311209350626267781732175260e-4932");
1347330f729Sjoerg Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308",
1357330f729Sjoerg "1.18973149535723176502e+4932",
1367330f729Sjoerg "1.79769313486231580793728971405301e+308",
1377330f729Sjoerg "1.18973149535723176508575932662800702e+4932");
1387330f729Sjoerg
1397330f729Sjoerg SmallString<32> DefPrefix;
1407330f729Sjoerg DefPrefix = "__";
1417330f729Sjoerg DefPrefix += Prefix;
1427330f729Sjoerg DefPrefix += "_";
1437330f729Sjoerg
1447330f729Sjoerg Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
1457330f729Sjoerg Builder.defineMacro(DefPrefix + "HAS_DENORM__");
1467330f729Sjoerg Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
1477330f729Sjoerg Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits));
1487330f729Sjoerg Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext);
1497330f729Sjoerg Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
1507330f729Sjoerg Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
1517330f729Sjoerg Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits));
1527330f729Sjoerg
1537330f729Sjoerg Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp));
1547330f729Sjoerg Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp));
1557330f729Sjoerg Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext);
1567330f729Sjoerg
1577330f729Sjoerg Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")");
1587330f729Sjoerg Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")");
1597330f729Sjoerg Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext);
1607330f729Sjoerg }
1617330f729Sjoerg
1627330f729Sjoerg
1637330f729Sjoerg /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
1647330f729Sjoerg /// named MacroName with the max value for a type with width 'TypeWidth' a
1657330f729Sjoerg /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
DefineTypeSize(const Twine & MacroName,unsigned TypeWidth,StringRef ValSuffix,bool isSigned,MacroBuilder & Builder)1667330f729Sjoerg static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
1677330f729Sjoerg StringRef ValSuffix, bool isSigned,
1687330f729Sjoerg MacroBuilder &Builder) {
1697330f729Sjoerg llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
1707330f729Sjoerg : llvm::APInt::getMaxValue(TypeWidth);
1717330f729Sjoerg Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
1727330f729Sjoerg }
1737330f729Sjoerg
1747330f729Sjoerg /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
1757330f729Sjoerg /// the width, suffix, and signedness of the given type
DefineTypeSize(const Twine & MacroName,TargetInfo::IntType Ty,const TargetInfo & TI,MacroBuilder & Builder)1767330f729Sjoerg static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
1777330f729Sjoerg const TargetInfo &TI, MacroBuilder &Builder) {
1787330f729Sjoerg DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
1797330f729Sjoerg TI.isTypeSigned(Ty), Builder);
1807330f729Sjoerg }
1817330f729Sjoerg
DefineFmt(const Twine & Prefix,TargetInfo::IntType Ty,const TargetInfo & TI,MacroBuilder & Builder)1827330f729Sjoerg static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty,
1837330f729Sjoerg const TargetInfo &TI, MacroBuilder &Builder) {
1847330f729Sjoerg bool IsSigned = TI.isTypeSigned(Ty);
1857330f729Sjoerg StringRef FmtModifier = TI.getTypeFormatModifier(Ty);
1867330f729Sjoerg for (const char *Fmt = IsSigned ? "di" : "ouxX"; *Fmt; ++Fmt) {
1877330f729Sjoerg Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__",
1887330f729Sjoerg Twine("\"") + FmtModifier + Twine(*Fmt) + "\"");
1897330f729Sjoerg }
1907330f729Sjoerg }
1917330f729Sjoerg
DefineType(const Twine & MacroName,TargetInfo::IntType Ty,MacroBuilder & Builder)1927330f729Sjoerg static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
1937330f729Sjoerg MacroBuilder &Builder) {
1947330f729Sjoerg Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
1957330f729Sjoerg }
1967330f729Sjoerg
DefineTypeWidth(StringRef MacroName,TargetInfo::IntType Ty,const TargetInfo & TI,MacroBuilder & Builder)1977330f729Sjoerg static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
1987330f729Sjoerg const TargetInfo &TI, MacroBuilder &Builder) {
1997330f729Sjoerg Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
2007330f729Sjoerg }
2017330f729Sjoerg
DefineTypeSizeof(StringRef MacroName,unsigned BitWidth,const TargetInfo & TI,MacroBuilder & Builder)2027330f729Sjoerg static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
2037330f729Sjoerg const TargetInfo &TI, MacroBuilder &Builder) {
2047330f729Sjoerg Builder.defineMacro(MacroName,
2057330f729Sjoerg Twine(BitWidth / TI.getCharWidth()));
2067330f729Sjoerg }
2077330f729Sjoerg
DefineExactWidthIntType(TargetInfo::IntType Ty,const TargetInfo & TI,MacroBuilder & Builder)2087330f729Sjoerg static void DefineExactWidthIntType(TargetInfo::IntType Ty,
2097330f729Sjoerg const TargetInfo &TI,
2107330f729Sjoerg MacroBuilder &Builder) {
2117330f729Sjoerg int TypeWidth = TI.getTypeWidth(Ty);
2127330f729Sjoerg bool IsSigned = TI.isTypeSigned(Ty);
2137330f729Sjoerg
2147330f729Sjoerg // Use the target specified int64 type, when appropriate, so that [u]int64_t
2157330f729Sjoerg // ends up being defined in terms of the correct type.
2167330f729Sjoerg if (TypeWidth == 64)
2177330f729Sjoerg Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
2187330f729Sjoerg
219*e038c9c4Sjoerg // Use the target specified int16 type when appropriate. Some MCU targets
220*e038c9c4Sjoerg // (such as AVR) have definition of [u]int16_t to [un]signed int.
221*e038c9c4Sjoerg if (TypeWidth == 16)
222*e038c9c4Sjoerg Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
223*e038c9c4Sjoerg
2247330f729Sjoerg const char *Prefix = IsSigned ? "__INT" : "__UINT";
2257330f729Sjoerg
2267330f729Sjoerg DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
2277330f729Sjoerg DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
2287330f729Sjoerg
2297330f729Sjoerg StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
2307330f729Sjoerg Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
2317330f729Sjoerg }
2327330f729Sjoerg
DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,const TargetInfo & TI,MacroBuilder & Builder)2337330f729Sjoerg static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
2347330f729Sjoerg const TargetInfo &TI,
2357330f729Sjoerg MacroBuilder &Builder) {
2367330f729Sjoerg int TypeWidth = TI.getTypeWidth(Ty);
2377330f729Sjoerg bool IsSigned = TI.isTypeSigned(Ty);
2387330f729Sjoerg
2397330f729Sjoerg // Use the target specified int64 type, when appropriate, so that [u]int64_t
2407330f729Sjoerg // ends up being defined in terms of the correct type.
2417330f729Sjoerg if (TypeWidth == 64)
2427330f729Sjoerg Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
2437330f729Sjoerg
2447330f729Sjoerg const char *Prefix = IsSigned ? "__INT" : "__UINT";
2457330f729Sjoerg DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
2467330f729Sjoerg }
2477330f729Sjoerg
DefineLeastWidthIntType(unsigned TypeWidth,bool IsSigned,const TargetInfo & TI,MacroBuilder & Builder)2487330f729Sjoerg static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
2497330f729Sjoerg const TargetInfo &TI,
2507330f729Sjoerg MacroBuilder &Builder) {
2517330f729Sjoerg TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
2527330f729Sjoerg if (Ty == TargetInfo::NoInt)
2537330f729Sjoerg return;
2547330f729Sjoerg
2557330f729Sjoerg const char *Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
2567330f729Sjoerg DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
2577330f729Sjoerg DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
2587330f729Sjoerg DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
2597330f729Sjoerg }
2607330f729Sjoerg
DefineFastIntType(unsigned TypeWidth,bool IsSigned,const TargetInfo & TI,MacroBuilder & Builder)2617330f729Sjoerg static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
2627330f729Sjoerg const TargetInfo &TI, MacroBuilder &Builder) {
2637330f729Sjoerg // stdint.h currently defines the fast int types as equivalent to the least
2647330f729Sjoerg // types.
2657330f729Sjoerg TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
2667330f729Sjoerg if (Ty == TargetInfo::NoInt)
2677330f729Sjoerg return;
2687330f729Sjoerg
2697330f729Sjoerg const char *Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
2707330f729Sjoerg DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
2717330f729Sjoerg DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
2727330f729Sjoerg
2737330f729Sjoerg DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
2747330f729Sjoerg }
2757330f729Sjoerg
2767330f729Sjoerg
2777330f729Sjoerg /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
2787330f729Sjoerg /// the specified properties.
getLockFreeValue(unsigned TypeWidth,unsigned TypeAlign,unsigned InlineWidth)2797330f729Sjoerg static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
2807330f729Sjoerg unsigned InlineWidth) {
2817330f729Sjoerg // Fully-aligned, power-of-2 sizes no larger than the inline
2827330f729Sjoerg // width will be inlined as lock-free operations.
2837330f729Sjoerg if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
2847330f729Sjoerg TypeWidth <= InlineWidth)
2857330f729Sjoerg return "2"; // "always lock free"
2867330f729Sjoerg // We cannot be certain what operations the lib calls might be
2877330f729Sjoerg // able to implement as lock-free on future processors.
2887330f729Sjoerg return "1"; // "sometimes lock free"
2897330f729Sjoerg }
2907330f729Sjoerg
2917330f729Sjoerg /// Add definitions required for a smooth interaction between
2927330f729Sjoerg /// Objective-C++ automated reference counting and libstdc++ (4.2).
AddObjCXXARCLibstdcxxDefines(const LangOptions & LangOpts,MacroBuilder & Builder)2937330f729Sjoerg static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts,
2947330f729Sjoerg MacroBuilder &Builder) {
2957330f729Sjoerg Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
2967330f729Sjoerg
2977330f729Sjoerg std::string Result;
2987330f729Sjoerg {
2997330f729Sjoerg // Provide specializations for the __is_scalar type trait so that
3007330f729Sjoerg // lifetime-qualified objects are not considered "scalar" types, which
3017330f729Sjoerg // libstdc++ uses as an indicator of the presence of trivial copy, assign,
3027330f729Sjoerg // default-construct, and destruct semantics (none of which hold for
3037330f729Sjoerg // lifetime-qualified objects in ARC).
3047330f729Sjoerg llvm::raw_string_ostream Out(Result);
3057330f729Sjoerg
3067330f729Sjoerg Out << "namespace std {\n"
3077330f729Sjoerg << "\n"
3087330f729Sjoerg << "struct __true_type;\n"
3097330f729Sjoerg << "struct __false_type;\n"
3107330f729Sjoerg << "\n";
3117330f729Sjoerg
3127330f729Sjoerg Out << "template<typename _Tp> struct __is_scalar;\n"
3137330f729Sjoerg << "\n";
3147330f729Sjoerg
3157330f729Sjoerg if (LangOpts.ObjCAutoRefCount) {
3167330f729Sjoerg Out << "template<typename _Tp>\n"
3177330f729Sjoerg << "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
3187330f729Sjoerg << " enum { __value = 0 };\n"
3197330f729Sjoerg << " typedef __false_type __type;\n"
3207330f729Sjoerg << "};\n"
3217330f729Sjoerg << "\n";
3227330f729Sjoerg }
3237330f729Sjoerg
3247330f729Sjoerg if (LangOpts.ObjCWeak) {
3257330f729Sjoerg Out << "template<typename _Tp>\n"
3267330f729Sjoerg << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
3277330f729Sjoerg << " enum { __value = 0 };\n"
3287330f729Sjoerg << " typedef __false_type __type;\n"
3297330f729Sjoerg << "};\n"
3307330f729Sjoerg << "\n";
3317330f729Sjoerg }
3327330f729Sjoerg
3337330f729Sjoerg if (LangOpts.ObjCAutoRefCount) {
3347330f729Sjoerg Out << "template<typename _Tp>\n"
3357330f729Sjoerg << "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
3367330f729Sjoerg << " _Tp> {\n"
3377330f729Sjoerg << " enum { __value = 0 };\n"
3387330f729Sjoerg << " typedef __false_type __type;\n"
3397330f729Sjoerg << "};\n"
3407330f729Sjoerg << "\n";
3417330f729Sjoerg }
3427330f729Sjoerg
3437330f729Sjoerg Out << "}\n";
3447330f729Sjoerg }
3457330f729Sjoerg Builder.append(Result);
3467330f729Sjoerg }
3477330f729Sjoerg
InitializeStandardPredefinedMacros(const TargetInfo & TI,const LangOptions & LangOpts,const FrontendOptions & FEOpts,MacroBuilder & Builder)3487330f729Sjoerg static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
3497330f729Sjoerg const LangOptions &LangOpts,
3507330f729Sjoerg const FrontendOptions &FEOpts,
3517330f729Sjoerg MacroBuilder &Builder) {
352*e038c9c4Sjoerg // C++ [cpp.predefined]p1:
353*e038c9c4Sjoerg // The following macro names shall be defined by the implementation:
354*e038c9c4Sjoerg
355*e038c9c4Sjoerg // -- __STDC__
356*e038c9c4Sjoerg // [C++] Whether __STDC__ is predefined and if so, what its value is,
357*e038c9c4Sjoerg // are implementation-defined.
358*e038c9c4Sjoerg // (Removed in C++20.)
3597330f729Sjoerg if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP)
3607330f729Sjoerg Builder.defineMacro("__STDC__");
361*e038c9c4Sjoerg // -- __STDC_HOSTED__
362*e038c9c4Sjoerg // The integer literal 1 if the implementation is a hosted
363*e038c9c4Sjoerg // implementation or the integer literal 0 if it is not.
3647330f729Sjoerg if (LangOpts.Freestanding)
3657330f729Sjoerg Builder.defineMacro("__STDC_HOSTED__", "0");
3667330f729Sjoerg else
3677330f729Sjoerg Builder.defineMacro("__STDC_HOSTED__");
3687330f729Sjoerg
369*e038c9c4Sjoerg // -- __STDC_VERSION__
370*e038c9c4Sjoerg // [C++] Whether __STDC_VERSION__ is predefined and if so, what its
371*e038c9c4Sjoerg // value is, are implementation-defined.
372*e038c9c4Sjoerg // (Removed in C++20.)
3737330f729Sjoerg if (!LangOpts.CPlusPlus) {
3747330f729Sjoerg if (LangOpts.C17)
3757330f729Sjoerg Builder.defineMacro("__STDC_VERSION__", "201710L");
3767330f729Sjoerg else if (LangOpts.C11)
3777330f729Sjoerg Builder.defineMacro("__STDC_VERSION__", "201112L");
3787330f729Sjoerg else if (LangOpts.C99)
3797330f729Sjoerg Builder.defineMacro("__STDC_VERSION__", "199901L");
3807330f729Sjoerg else if (!LangOpts.GNUMode && LangOpts.Digraphs)
3817330f729Sjoerg Builder.defineMacro("__STDC_VERSION__", "199409L");
3827330f729Sjoerg } else {
383*e038c9c4Sjoerg // -- __cplusplus
384*e038c9c4Sjoerg // FIXME: Use correct value for C++23.
385*e038c9c4Sjoerg if (LangOpts.CPlusPlus2b)
386*e038c9c4Sjoerg Builder.defineMacro("__cplusplus", "202101L");
387*e038c9c4Sjoerg // [C++20] The integer literal 202002L.
388*e038c9c4Sjoerg else if (LangOpts.CPlusPlus20)
389*e038c9c4Sjoerg Builder.defineMacro("__cplusplus", "202002L");
390*e038c9c4Sjoerg // [C++17] The integer literal 201703L.
3917330f729Sjoerg else if (LangOpts.CPlusPlus17)
3927330f729Sjoerg Builder.defineMacro("__cplusplus", "201703L");
393*e038c9c4Sjoerg // [C++14] The name __cplusplus is defined to the value 201402L when
394*e038c9c4Sjoerg // compiling a C++ translation unit.
3957330f729Sjoerg else if (LangOpts.CPlusPlus14)
3967330f729Sjoerg Builder.defineMacro("__cplusplus", "201402L");
397*e038c9c4Sjoerg // [C++11] The name __cplusplus is defined to the value 201103L when
398*e038c9c4Sjoerg // compiling a C++ translation unit.
3997330f729Sjoerg else if (LangOpts.CPlusPlus11)
4007330f729Sjoerg Builder.defineMacro("__cplusplus", "201103L");
401*e038c9c4Sjoerg // [C++03] The name __cplusplus is defined to the value 199711L when
402*e038c9c4Sjoerg // compiling a C++ translation unit.
4037330f729Sjoerg else
4047330f729Sjoerg Builder.defineMacro("__cplusplus", "199711L");
4057330f729Sjoerg
406*e038c9c4Sjoerg // -- __STDCPP_DEFAULT_NEW_ALIGNMENT__
407*e038c9c4Sjoerg // [C++17] An integer literal of type std::size_t whose value is the
408*e038c9c4Sjoerg // alignment guaranteed by a call to operator new(std::size_t)
4097330f729Sjoerg //
4107330f729Sjoerg // We provide this in all language modes, since it seems generally useful.
4117330f729Sjoerg Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__",
4127330f729Sjoerg Twine(TI.getNewAlign() / TI.getCharWidth()) +
4137330f729Sjoerg TI.getTypeConstantSuffix(TI.getSizeType()));
414*e038c9c4Sjoerg
415*e038c9c4Sjoerg // -- __STDCPP_THREADS__
416*e038c9c4Sjoerg // Defined, and has the value integer literal 1, if and only if a
417*e038c9c4Sjoerg // program can have more than one thread of execution.
418*e038c9c4Sjoerg if (LangOpts.getThreadModel() == LangOptions::ThreadModelKind::POSIX)
419*e038c9c4Sjoerg Builder.defineMacro("__STDCPP_THREADS__", "1");
4207330f729Sjoerg }
4217330f729Sjoerg
4227330f729Sjoerg // In C11 these are environment macros. In C++11 they are only defined
4237330f729Sjoerg // as part of <cuchar>. To prevent breakage when mixing C and C++
4247330f729Sjoerg // code, define these macros unconditionally. We can define them
4257330f729Sjoerg // unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
4267330f729Sjoerg // and 32-bit character literals.
4277330f729Sjoerg Builder.defineMacro("__STDC_UTF_16__", "1");
4287330f729Sjoerg Builder.defineMacro("__STDC_UTF_32__", "1");
4297330f729Sjoerg
4307330f729Sjoerg if (LangOpts.ObjC)
4317330f729Sjoerg Builder.defineMacro("__OBJC__");
4327330f729Sjoerg
4337330f729Sjoerg // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
4347330f729Sjoerg if (LangOpts.OpenCL) {
4357330f729Sjoerg if (LangOpts.CPlusPlus) {
4367330f729Sjoerg if (LangOpts.OpenCLCPlusPlusVersion == 100)
4377330f729Sjoerg Builder.defineMacro("__OPENCL_CPP_VERSION__", "100");
4387330f729Sjoerg else
4397330f729Sjoerg llvm_unreachable("Unsupported C++ version for OpenCL");
4407330f729Sjoerg Builder.defineMacro("__CL_CPP_VERSION_1_0__", "100");
4417330f729Sjoerg } else {
4427330f729Sjoerg // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
4437330f729Sjoerg // language standard with which the program is compiled. __OPENCL_VERSION__
4447330f729Sjoerg // is for the OpenCL version supported by the OpenCL device, which is not
4457330f729Sjoerg // necessarily the language standard with which the program is compiled.
4467330f729Sjoerg // A shared OpenCL header file requires a macro to indicate the language
4477330f729Sjoerg // standard. As a workaround, __OPENCL_C_VERSION__ is defined for
4487330f729Sjoerg // OpenCL v1.0 and v1.1.
4497330f729Sjoerg switch (LangOpts.OpenCLVersion) {
4507330f729Sjoerg case 100:
4517330f729Sjoerg Builder.defineMacro("__OPENCL_C_VERSION__", "100");
4527330f729Sjoerg break;
4537330f729Sjoerg case 110:
4547330f729Sjoerg Builder.defineMacro("__OPENCL_C_VERSION__", "110");
4557330f729Sjoerg break;
4567330f729Sjoerg case 120:
4577330f729Sjoerg Builder.defineMacro("__OPENCL_C_VERSION__", "120");
4587330f729Sjoerg break;
4597330f729Sjoerg case 200:
4607330f729Sjoerg Builder.defineMacro("__OPENCL_C_VERSION__", "200");
4617330f729Sjoerg break;
462*e038c9c4Sjoerg case 300:
463*e038c9c4Sjoerg Builder.defineMacro("__OPENCL_C_VERSION__", "300");
464*e038c9c4Sjoerg break;
4657330f729Sjoerg default:
4667330f729Sjoerg llvm_unreachable("Unsupported OpenCL version");
4677330f729Sjoerg }
4687330f729Sjoerg }
4697330f729Sjoerg Builder.defineMacro("CL_VERSION_1_0", "100");
4707330f729Sjoerg Builder.defineMacro("CL_VERSION_1_1", "110");
4717330f729Sjoerg Builder.defineMacro("CL_VERSION_1_2", "120");
4727330f729Sjoerg Builder.defineMacro("CL_VERSION_2_0", "200");
473*e038c9c4Sjoerg Builder.defineMacro("CL_VERSION_3_0", "300");
4747330f729Sjoerg
4757330f729Sjoerg if (TI.isLittleEndian())
4767330f729Sjoerg Builder.defineMacro("__ENDIAN_LITTLE__");
4777330f729Sjoerg
4787330f729Sjoerg if (LangOpts.FastRelaxedMath)
4797330f729Sjoerg Builder.defineMacro("__FAST_RELAXED_MATH__");
4807330f729Sjoerg }
481*e038c9c4Sjoerg
482*e038c9c4Sjoerg if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) {
483*e038c9c4Sjoerg // SYCL Version is set to a value when building SYCL applications
484*e038c9c4Sjoerg if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
485*e038c9c4Sjoerg Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
486*e038c9c4Sjoerg else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
487*e038c9c4Sjoerg Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
488*e038c9c4Sjoerg }
489*e038c9c4Sjoerg
4907330f729Sjoerg // Not "standard" per se, but available even with the -undef flag.
4917330f729Sjoerg if (LangOpts.AsmPreprocessor)
4927330f729Sjoerg Builder.defineMacro("__ASSEMBLER__");
4937330f729Sjoerg if (LangOpts.CUDA && !LangOpts.HIP)
4947330f729Sjoerg Builder.defineMacro("__CUDA__");
4957330f729Sjoerg if (LangOpts.HIP) {
4967330f729Sjoerg Builder.defineMacro("__HIP__");
4977330f729Sjoerg Builder.defineMacro("__HIPCC__");
4987330f729Sjoerg if (LangOpts.CUDAIsDevice)
4997330f729Sjoerg Builder.defineMacro("__HIP_DEVICE_COMPILE__");
5007330f729Sjoerg }
5017330f729Sjoerg }
5027330f729Sjoerg
5037330f729Sjoerg /// Initialize the predefined C++ language feature test macros defined in
5047330f729Sjoerg /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
InitializeCPlusPlusFeatureTestMacros(const LangOptions & LangOpts,MacroBuilder & Builder)5057330f729Sjoerg static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
5067330f729Sjoerg MacroBuilder &Builder) {
5077330f729Sjoerg // C++98 features.
5087330f729Sjoerg if (LangOpts.RTTI)
5097330f729Sjoerg Builder.defineMacro("__cpp_rtti", "199711L");
5107330f729Sjoerg if (LangOpts.CXXExceptions)
5117330f729Sjoerg Builder.defineMacro("__cpp_exceptions", "199711L");
5127330f729Sjoerg
5137330f729Sjoerg // C++11 features.
5147330f729Sjoerg if (LangOpts.CPlusPlus11) {
5157330f729Sjoerg Builder.defineMacro("__cpp_unicode_characters", "200704L");
5167330f729Sjoerg Builder.defineMacro("__cpp_raw_strings", "200710L");
5177330f729Sjoerg Builder.defineMacro("__cpp_unicode_literals", "200710L");
5187330f729Sjoerg Builder.defineMacro("__cpp_user_defined_literals", "200809L");
5197330f729Sjoerg Builder.defineMacro("__cpp_lambdas", "200907L");
5207330f729Sjoerg Builder.defineMacro("__cpp_constexpr",
521*e038c9c4Sjoerg LangOpts.CPlusPlus20 ? "201907L" :
5227330f729Sjoerg LangOpts.CPlusPlus17 ? "201603L" :
5237330f729Sjoerg LangOpts.CPlusPlus14 ? "201304L" : "200704");
524*e038c9c4Sjoerg Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
5257330f729Sjoerg Builder.defineMacro("__cpp_range_based_for",
5267330f729Sjoerg LangOpts.CPlusPlus17 ? "201603L" : "200907");
5277330f729Sjoerg Builder.defineMacro("__cpp_static_assert",
5287330f729Sjoerg LangOpts.CPlusPlus17 ? "201411L" : "200410");
5297330f729Sjoerg Builder.defineMacro("__cpp_decltype", "200707L");
5307330f729Sjoerg Builder.defineMacro("__cpp_attributes", "200809L");
5317330f729Sjoerg Builder.defineMacro("__cpp_rvalue_references", "200610L");
5327330f729Sjoerg Builder.defineMacro("__cpp_variadic_templates", "200704L");
5337330f729Sjoerg Builder.defineMacro("__cpp_initializer_lists", "200806L");
5347330f729Sjoerg Builder.defineMacro("__cpp_delegating_constructors", "200604L");
5357330f729Sjoerg Builder.defineMacro("__cpp_nsdmi", "200809L");
5367330f729Sjoerg Builder.defineMacro("__cpp_inheriting_constructors", "201511L");
5377330f729Sjoerg Builder.defineMacro("__cpp_ref_qualifiers", "200710L");
5387330f729Sjoerg Builder.defineMacro("__cpp_alias_templates", "200704L");
5397330f729Sjoerg }
5407330f729Sjoerg if (LangOpts.ThreadsafeStatics)
5417330f729Sjoerg Builder.defineMacro("__cpp_threadsafe_static_init", "200806L");
5427330f729Sjoerg
5437330f729Sjoerg // C++14 features.
5447330f729Sjoerg if (LangOpts.CPlusPlus14) {
5457330f729Sjoerg Builder.defineMacro("__cpp_binary_literals", "201304L");
5467330f729Sjoerg Builder.defineMacro("__cpp_digit_separators", "201309L");
547*e038c9c4Sjoerg Builder.defineMacro("__cpp_init_captures",
548*e038c9c4Sjoerg LangOpts.CPlusPlus20 ? "201803L" : "201304L");
549*e038c9c4Sjoerg Builder.defineMacro("__cpp_generic_lambdas",
550*e038c9c4Sjoerg LangOpts.CPlusPlus20 ? "201707L" : "201304L");
5517330f729Sjoerg Builder.defineMacro("__cpp_decltype_auto", "201304L");
5527330f729Sjoerg Builder.defineMacro("__cpp_return_type_deduction", "201304L");
5537330f729Sjoerg Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L");
5547330f729Sjoerg Builder.defineMacro("__cpp_variable_templates", "201304L");
5557330f729Sjoerg }
5567330f729Sjoerg if (LangOpts.SizedDeallocation)
5577330f729Sjoerg Builder.defineMacro("__cpp_sized_deallocation", "201309L");
5587330f729Sjoerg
5597330f729Sjoerg // C++17 features.
5607330f729Sjoerg if (LangOpts.CPlusPlus17) {
5617330f729Sjoerg Builder.defineMacro("__cpp_hex_float", "201603L");
5627330f729Sjoerg Builder.defineMacro("__cpp_inline_variables", "201606L");
5637330f729Sjoerg Builder.defineMacro("__cpp_noexcept_function_type", "201510L");
5647330f729Sjoerg Builder.defineMacro("__cpp_capture_star_this", "201603L");
5657330f729Sjoerg Builder.defineMacro("__cpp_if_constexpr", "201606L");
566*e038c9c4Sjoerg Builder.defineMacro("__cpp_deduction_guides", "201703L"); // (not latest)
5677330f729Sjoerg Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name)
5687330f729Sjoerg Builder.defineMacro("__cpp_namespace_attributes", "201411L");
5697330f729Sjoerg Builder.defineMacro("__cpp_enumerator_attributes", "201411L");
5707330f729Sjoerg Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
5717330f729Sjoerg Builder.defineMacro("__cpp_variadic_using", "201611L");
5727330f729Sjoerg Builder.defineMacro("__cpp_aggregate_bases", "201603L");
5737330f729Sjoerg Builder.defineMacro("__cpp_structured_bindings", "201606L");
574*e038c9c4Sjoerg Builder.defineMacro("__cpp_nontype_template_args",
575*e038c9c4Sjoerg "201411L"); // (not latest)
5767330f729Sjoerg Builder.defineMacro("__cpp_fold_expressions", "201603L");
5777330f729Sjoerg Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
5787330f729Sjoerg Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
5797330f729Sjoerg }
5807330f729Sjoerg if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
5817330f729Sjoerg Builder.defineMacro("__cpp_aligned_new", "201606L");
5827330f729Sjoerg if (LangOpts.RelaxedTemplateTemplateArgs)
5837330f729Sjoerg Builder.defineMacro("__cpp_template_template_args", "201611L");
5847330f729Sjoerg
5857330f729Sjoerg // C++20 features.
586*e038c9c4Sjoerg if (LangOpts.CPlusPlus20) {
587*e038c9c4Sjoerg //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
588*e038c9c4Sjoerg Builder.defineMacro("__cpp_concepts", "201907L");
5897330f729Sjoerg Builder.defineMacro("__cpp_conditional_explicit", "201806L");
590*e038c9c4Sjoerg //Builder.defineMacro("__cpp_consteval", "201811L");
5917330f729Sjoerg Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
5927330f729Sjoerg Builder.defineMacro("__cpp_constinit", "201907L");
593*e038c9c4Sjoerg //Builder.defineMacro("__cpp_coroutines", "201902L");
594*e038c9c4Sjoerg Builder.defineMacro("__cpp_designated_initializers", "201707L");
595*e038c9c4Sjoerg Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L");
596*e038c9c4Sjoerg //Builder.defineMacro("__cpp_modules", "201907L");
597*e038c9c4Sjoerg //Builder.defineMacro("__cpp_using_enum", "201907L");
5987330f729Sjoerg }
599*e038c9c4Sjoerg // C++2b features.
600*e038c9c4Sjoerg if (LangOpts.CPlusPlus2b)
601*e038c9c4Sjoerg Builder.defineMacro("__cpp_size_t_suffix", "202011L");
6027330f729Sjoerg if (LangOpts.Char8)
6037330f729Sjoerg Builder.defineMacro("__cpp_char8_t", "201811L");
6047330f729Sjoerg Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
6057330f729Sjoerg
6067330f729Sjoerg // TS features.
6077330f729Sjoerg if (LangOpts.Coroutines)
6087330f729Sjoerg Builder.defineMacro("__cpp_coroutines", "201703L");
6097330f729Sjoerg }
6107330f729Sjoerg
611*e038c9c4Sjoerg /// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
612*e038c9c4Sjoerg /// settings and language version
InitializeOpenCLFeatureTestMacros(const TargetInfo & TI,const LangOptions & Opts,MacroBuilder & Builder)613*e038c9c4Sjoerg void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
614*e038c9c4Sjoerg const LangOptions &Opts,
615*e038c9c4Sjoerg MacroBuilder &Builder) {
616*e038c9c4Sjoerg const llvm::StringMap<bool> &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
617*e038c9c4Sjoerg // FIXME: OpenCL options which affect language semantics/syntax
618*e038c9c4Sjoerg // should be moved into LangOptions.
619*e038c9c4Sjoerg auto defineOpenCLExtMacro = [&](llvm::StringRef Name, auto... OptArgs) {
620*e038c9c4Sjoerg // Check if extension is supported by target and is available in this
621*e038c9c4Sjoerg // OpenCL version
622*e038c9c4Sjoerg if (TI.hasFeatureEnabled(OpenCLFeaturesMap, Name) &&
623*e038c9c4Sjoerg OpenCLOptions::isOpenCLOptionAvailableIn(Opts, OptArgs...))
624*e038c9c4Sjoerg Builder.defineMacro(Name);
625*e038c9c4Sjoerg };
626*e038c9c4Sjoerg #define OPENCL_GENERIC_EXTENSION(Ext, ...) \
627*e038c9c4Sjoerg defineOpenCLExtMacro(#Ext, __VA_ARGS__);
628*e038c9c4Sjoerg #include "clang/Basic/OpenCLExtensions.def"
629*e038c9c4Sjoerg
630*e038c9c4Sjoerg // Assume compiling for FULL profile
631*e038c9c4Sjoerg Builder.defineMacro("__opencl_c_int64");
632*e038c9c4Sjoerg }
633*e038c9c4Sjoerg
InitializePredefinedMacros(const TargetInfo & TI,const LangOptions & LangOpts,const FrontendOptions & FEOpts,const PreprocessorOptions & PPOpts,MacroBuilder & Builder)6347330f729Sjoerg static void InitializePredefinedMacros(const TargetInfo &TI,
6357330f729Sjoerg const LangOptions &LangOpts,
6367330f729Sjoerg const FrontendOptions &FEOpts,
6377330f729Sjoerg const PreprocessorOptions &PPOpts,
6387330f729Sjoerg MacroBuilder &Builder) {
6397330f729Sjoerg // Compiler version introspection macros.
6407330f729Sjoerg Builder.defineMacro("__llvm__"); // LLVM Backend
6417330f729Sjoerg Builder.defineMacro("__clang__"); // Clang Frontend
6427330f729Sjoerg #define TOSTR2(X) #X
6437330f729Sjoerg #define TOSTR(X) TOSTR2(X)
6447330f729Sjoerg Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
6457330f729Sjoerg Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
6467330f729Sjoerg Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
6477330f729Sjoerg #undef TOSTR
6487330f729Sjoerg #undef TOSTR2
6497330f729Sjoerg Builder.defineMacro("__clang_version__",
6507330f729Sjoerg "\"" CLANG_VERSION_STRING " "
6517330f729Sjoerg + getClangFullRepositoryVersion() + "\"");
6527330f729Sjoerg
6537330f729Sjoerg if (LangOpts.GNUCVersion != 0) {
6547330f729Sjoerg // Major, minor, patch, are given two decimal places each, so 4.2.1 becomes
6557330f729Sjoerg // 40201.
6567330f729Sjoerg unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100;
6577330f729Sjoerg unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100;
6587330f729Sjoerg unsigned GNUCPatch = LangOpts.GNUCVersion % 100;
6597330f729Sjoerg Builder.defineMacro("__GNUC__", Twine(GNUCMajor));
6607330f729Sjoerg Builder.defineMacro("__GNUC_MINOR__", Twine(GNUCMinor));
6617330f729Sjoerg Builder.defineMacro("__GNUC_PATCHLEVEL__", Twine(GNUCPatch));
6627330f729Sjoerg Builder.defineMacro("__GXX_ABI_VERSION", "1002");
6637330f729Sjoerg
6647330f729Sjoerg if (LangOpts.CPlusPlus) {
6657330f729Sjoerg Builder.defineMacro("__GNUG__", Twine(GNUCMajor));
6667330f729Sjoerg Builder.defineMacro("__GXX_WEAK__");
6677330f729Sjoerg }
6687330f729Sjoerg }
6697330f729Sjoerg
6707330f729Sjoerg // Define macros for the C11 / C++11 memory orderings
6717330f729Sjoerg Builder.defineMacro("__ATOMIC_RELAXED", "0");
6727330f729Sjoerg Builder.defineMacro("__ATOMIC_CONSUME", "1");
6737330f729Sjoerg Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
6747330f729Sjoerg Builder.defineMacro("__ATOMIC_RELEASE", "3");
6757330f729Sjoerg Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
6767330f729Sjoerg Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
6777330f729Sjoerg
6787330f729Sjoerg // Define macros for the OpenCL memory scope.
6797330f729Sjoerg // The values should match AtomicScopeOpenCLModel::ID enum.
6807330f729Sjoerg static_assert(
6817330f729Sjoerg static_cast<unsigned>(AtomicScopeOpenCLModel::WorkGroup) == 1 &&
6827330f729Sjoerg static_cast<unsigned>(AtomicScopeOpenCLModel::Device) == 2 &&
6837330f729Sjoerg static_cast<unsigned>(AtomicScopeOpenCLModel::AllSVMDevices) == 3 &&
6847330f729Sjoerg static_cast<unsigned>(AtomicScopeOpenCLModel::SubGroup) == 4,
6857330f729Sjoerg "Invalid OpenCL memory scope enum definition");
6867330f729Sjoerg Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0");
6877330f729Sjoerg Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1");
6887330f729Sjoerg Builder.defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2");
6897330f729Sjoerg Builder.defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3");
6907330f729Sjoerg Builder.defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4");
6917330f729Sjoerg
6927330f729Sjoerg // Support for #pragma redefine_extname (Sun compatibility)
6937330f729Sjoerg Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
6947330f729Sjoerg
6957330f729Sjoerg // Previously this macro was set to a string aiming to achieve compatibility
6967330f729Sjoerg // with GCC 4.2.1. Now, just return the full Clang version
6977330f729Sjoerg Builder.defineMacro("__VERSION__", "\"" +
6987330f729Sjoerg Twine(getClangFullCPPVersion()) + "\"");
6997330f729Sjoerg
7007330f729Sjoerg // Initialize language-specific preprocessor defines.
7017330f729Sjoerg
7027330f729Sjoerg // Standard conforming mode?
7037330f729Sjoerg if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
7047330f729Sjoerg Builder.defineMacro("__STRICT_ANSI__");
7057330f729Sjoerg
7067330f729Sjoerg if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
7077330f729Sjoerg Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
7087330f729Sjoerg
7097330f729Sjoerg if (LangOpts.ObjC) {
7107330f729Sjoerg if (LangOpts.ObjCRuntime.isNonFragile()) {
7117330f729Sjoerg Builder.defineMacro("__OBJC2__");
7127330f729Sjoerg
7137330f729Sjoerg if (LangOpts.ObjCExceptions)
7147330f729Sjoerg Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
7157330f729Sjoerg }
7167330f729Sjoerg
7177330f729Sjoerg if (LangOpts.getGC() != LangOptions::NonGC)
7187330f729Sjoerg Builder.defineMacro("__OBJC_GC__");
7197330f729Sjoerg
7207330f729Sjoerg if (LangOpts.ObjCRuntime.isNeXTFamily())
7217330f729Sjoerg Builder.defineMacro("__NEXT_RUNTIME__");
7227330f729Sjoerg
7237330f729Sjoerg if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::GNUstep) {
7247330f729Sjoerg auto version = LangOpts.ObjCRuntime.getVersion();
7257330f729Sjoerg std::string versionString = "1";
7267330f729Sjoerg // Don't rely on the tuple argument, because we can be asked to target
7277330f729Sjoerg // later ABIs than we actually support, so clamp these values to those
7287330f729Sjoerg // currently supported
7297330f729Sjoerg if (version >= VersionTuple(2, 0))
7307330f729Sjoerg Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", "20");
7317330f729Sjoerg else
7327330f729Sjoerg Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__",
7337330f729Sjoerg "1" + Twine(std::min(8U, version.getMinor().getValueOr(0))));
7347330f729Sjoerg }
7357330f729Sjoerg
7367330f729Sjoerg if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
7377330f729Sjoerg VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
7387330f729Sjoerg
7397330f729Sjoerg unsigned minor = 0;
7407330f729Sjoerg if (tuple.getMinor().hasValue())
7417330f729Sjoerg minor = tuple.getMinor().getValue();
7427330f729Sjoerg
7437330f729Sjoerg unsigned subminor = 0;
7447330f729Sjoerg if (tuple.getSubminor().hasValue())
7457330f729Sjoerg subminor = tuple.getSubminor().getValue();
7467330f729Sjoerg
7477330f729Sjoerg Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
7487330f729Sjoerg Twine(tuple.getMajor() * 10000 + minor * 100 +
7497330f729Sjoerg subminor));
7507330f729Sjoerg }
7517330f729Sjoerg
7527330f729Sjoerg Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
7537330f729Sjoerg Builder.defineMacro("IBOutletCollection(ClassName)",
7547330f729Sjoerg "__attribute__((iboutletcollection(ClassName)))");
7557330f729Sjoerg Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
7567330f729Sjoerg Builder.defineMacro("IBInspectable", "");
7577330f729Sjoerg Builder.defineMacro("IB_DESIGNABLE", "");
7587330f729Sjoerg }
7597330f729Sjoerg
7607330f729Sjoerg // Define a macro that describes the Objective-C boolean type even for C
7617330f729Sjoerg // and C++ since BOOL can be used from non Objective-C code.
7627330f729Sjoerg Builder.defineMacro("__OBJC_BOOL_IS_BOOL",
7637330f729Sjoerg Twine(TI.useSignedCharForObjCBool() ? "0" : "1"));
7647330f729Sjoerg
7657330f729Sjoerg if (LangOpts.CPlusPlus)
7667330f729Sjoerg InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
7677330f729Sjoerg
7687330f729Sjoerg // darwin_constant_cfstrings controls this. This is also dependent
7697330f729Sjoerg // on other things like the runtime I believe. This is set even for C code.
7707330f729Sjoerg if (!LangOpts.NoConstantCFStrings)
7717330f729Sjoerg Builder.defineMacro("__CONSTANT_CFSTRINGS__");
7727330f729Sjoerg
7737330f729Sjoerg if (LangOpts.ObjC)
7747330f729Sjoerg Builder.defineMacro("OBJC_NEW_PROPERTIES");
7757330f729Sjoerg
7767330f729Sjoerg if (LangOpts.PascalStrings)
7777330f729Sjoerg Builder.defineMacro("__PASCAL_STRINGS__");
7787330f729Sjoerg
7797330f729Sjoerg if (LangOpts.Blocks) {
7807330f729Sjoerg Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
7817330f729Sjoerg Builder.defineMacro("__BLOCKS__");
7827330f729Sjoerg }
7837330f729Sjoerg
7847330f729Sjoerg if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
7857330f729Sjoerg Builder.defineMacro("__EXCEPTIONS");
7867330f729Sjoerg if (LangOpts.GNUCVersion && LangOpts.RTTI)
7877330f729Sjoerg Builder.defineMacro("__GXX_RTTI");
7887330f729Sjoerg
789*e038c9c4Sjoerg if (LangOpts.hasSjLjExceptions())
7907330f729Sjoerg Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
791*e038c9c4Sjoerg else if (LangOpts.hasSEHExceptions())
7927330f729Sjoerg Builder.defineMacro("__SEH__");
793*e038c9c4Sjoerg else if (LangOpts.hasDWARFExceptions() &&
7947330f729Sjoerg (TI.getTriple().isThumb() || TI.getTriple().isARM()))
7957330f729Sjoerg Builder.defineMacro("__ARM_DWARF_EH__");
7967330f729Sjoerg
7977330f729Sjoerg if (LangOpts.Deprecated)
7987330f729Sjoerg Builder.defineMacro("__DEPRECATED");
7997330f729Sjoerg
8007330f729Sjoerg if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus)
8017330f729Sjoerg Builder.defineMacro("__private_extern__", "extern");
8027330f729Sjoerg
8037330f729Sjoerg if (LangOpts.MicrosoftExt) {
8047330f729Sjoerg if (LangOpts.WChar) {
8057330f729Sjoerg // wchar_t supported as a keyword.
8067330f729Sjoerg Builder.defineMacro("_WCHAR_T_DEFINED");
8077330f729Sjoerg Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
8087330f729Sjoerg }
8097330f729Sjoerg }
8107330f729Sjoerg
811*e038c9c4Sjoerg // Macros to help identify the narrow and wide character sets
812*e038c9c4Sjoerg // FIXME: clang currently ignores -fexec-charset=. If this changes,
813*e038c9c4Sjoerg // then this may need to be updated.
814*e038c9c4Sjoerg Builder.defineMacro("__clang_literal_encoding__", "\"UTF-8\"");
815*e038c9c4Sjoerg if (TI.getTypeWidth(TI.getWCharType()) >= 32) {
816*e038c9c4Sjoerg // FIXME: 32-bit wchar_t signals UTF-32. This may change
817*e038c9c4Sjoerg // if -fwide-exec-charset= is ever supported.
818*e038c9c4Sjoerg Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\"");
819*e038c9c4Sjoerg } else {
820*e038c9c4Sjoerg // FIXME: Less-than 32-bit wchar_t generally means UTF-16
821*e038c9c4Sjoerg // (e.g., Windows, 32-bit IBM). This may need to be
822*e038c9c4Sjoerg // updated if -fwide-exec-charset= is ever supported.
823*e038c9c4Sjoerg Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\"");
824*e038c9c4Sjoerg }
825*e038c9c4Sjoerg
8267330f729Sjoerg if (LangOpts.Optimize)
8277330f729Sjoerg Builder.defineMacro("__OPTIMIZE__");
8287330f729Sjoerg if (LangOpts.OptimizeSize)
8297330f729Sjoerg Builder.defineMacro("__OPTIMIZE_SIZE__");
8307330f729Sjoerg
8317330f729Sjoerg if (LangOpts.FastMath)
8327330f729Sjoerg Builder.defineMacro("__FAST_MATH__");
8337330f729Sjoerg
8347330f729Sjoerg // Initialize target-specific preprocessor defines.
8357330f729Sjoerg
8367330f729Sjoerg // __BYTE_ORDER__ was added in GCC 4.6. It's analogous
8377330f729Sjoerg // to the macro __BYTE_ORDER (no trailing underscores)
8387330f729Sjoerg // from glibc's <endian.h> header.
8397330f729Sjoerg // We don't support the PDP-11 as a target, but include
8407330f729Sjoerg // the define so it can still be compared against.
8417330f729Sjoerg Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
8427330f729Sjoerg Builder.defineMacro("__ORDER_BIG_ENDIAN__", "4321");
8437330f729Sjoerg Builder.defineMacro("__ORDER_PDP_ENDIAN__", "3412");
8447330f729Sjoerg if (TI.isBigEndian()) {
8457330f729Sjoerg Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
8467330f729Sjoerg Builder.defineMacro("__BIG_ENDIAN__");
8477330f729Sjoerg } else {
8487330f729Sjoerg Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
8497330f729Sjoerg Builder.defineMacro("__LITTLE_ENDIAN__");
8507330f729Sjoerg }
8517330f729Sjoerg
8527330f729Sjoerg if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
8537330f729Sjoerg && TI.getIntWidth() == 32) {
8547330f729Sjoerg Builder.defineMacro("_LP64");
8557330f729Sjoerg Builder.defineMacro("__LP64__");
8567330f729Sjoerg }
8577330f729Sjoerg
8587330f729Sjoerg if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
8597330f729Sjoerg && TI.getIntWidth() == 32) {
8607330f729Sjoerg Builder.defineMacro("_ILP32");
8617330f729Sjoerg Builder.defineMacro("__ILP32__");
8627330f729Sjoerg }
8637330f729Sjoerg
8647330f729Sjoerg // Define type sizing macros based on the target properties.
8657330f729Sjoerg assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
8667330f729Sjoerg Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
8677330f729Sjoerg
8687330f729Sjoerg DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
8697330f729Sjoerg DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
8707330f729Sjoerg DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
8717330f729Sjoerg DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
8727330f729Sjoerg DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
8737330f729Sjoerg DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
8747330f729Sjoerg DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder);
8757330f729Sjoerg DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
8767330f729Sjoerg DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
8777330f729Sjoerg
8787330f729Sjoerg DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
8797330f729Sjoerg DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
8807330f729Sjoerg DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
8817330f729Sjoerg DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
8827330f729Sjoerg
8837330f729Sjoerg DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
8847330f729Sjoerg DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
8857330f729Sjoerg DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
8867330f729Sjoerg DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
8877330f729Sjoerg DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
8887330f729Sjoerg DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
8897330f729Sjoerg DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
8907330f729Sjoerg DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
8917330f729Sjoerg DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
8927330f729Sjoerg TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
8937330f729Sjoerg DefineTypeSizeof("__SIZEOF_SIZE_T__",
8947330f729Sjoerg TI.getTypeWidth(TI.getSizeType()), TI, Builder);
8957330f729Sjoerg DefineTypeSizeof("__SIZEOF_WCHAR_T__",
8967330f729Sjoerg TI.getTypeWidth(TI.getWCharType()), TI, Builder);
8977330f729Sjoerg DefineTypeSizeof("__SIZEOF_WINT_T__",
8987330f729Sjoerg TI.getTypeWidth(TI.getWIntType()), TI, Builder);
8997330f729Sjoerg if (TI.hasInt128Type())
9007330f729Sjoerg DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
9017330f729Sjoerg
9027330f729Sjoerg DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
9037330f729Sjoerg DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
9047330f729Sjoerg Builder.defineMacro("__INTMAX_C_SUFFIX__",
9057330f729Sjoerg TI.getTypeConstantSuffix(TI.getIntMaxType()));
9067330f729Sjoerg DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
9077330f729Sjoerg DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
9087330f729Sjoerg Builder.defineMacro("__UINTMAX_C_SUFFIX__",
9097330f729Sjoerg TI.getTypeConstantSuffix(TI.getUIntMaxType()));
9107330f729Sjoerg DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder);
9117330f729Sjoerg DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
9127330f729Sjoerg DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
9137330f729Sjoerg DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
9147330f729Sjoerg DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
9157330f729Sjoerg DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
9167330f729Sjoerg DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
9177330f729Sjoerg DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
9187330f729Sjoerg DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
9197330f729Sjoerg DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
9207330f729Sjoerg DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
9217330f729Sjoerg DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
9227330f729Sjoerg DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
9237330f729Sjoerg DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
9247330f729Sjoerg DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
9257330f729Sjoerg DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
9267330f729Sjoerg DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
9277330f729Sjoerg DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
9287330f729Sjoerg
9297330f729Sjoerg DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder);
9307330f729Sjoerg DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
9317330f729Sjoerg DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
9327330f729Sjoerg DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
9337330f729Sjoerg
9347330f729Sjoerg if (TI.hasFloat16Type())
9357330f729Sjoerg DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
9367330f729Sjoerg DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
9377330f729Sjoerg DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
9387330f729Sjoerg DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
9397330f729Sjoerg
9407330f729Sjoerg // Define a __POINTER_WIDTH__ macro for stdint.h.
9417330f729Sjoerg Builder.defineMacro("__POINTER_WIDTH__",
9427330f729Sjoerg Twine((int)TI.getPointerWidth(0)));
9437330f729Sjoerg
9447330f729Sjoerg // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
9457330f729Sjoerg Builder.defineMacro("__BIGGEST_ALIGNMENT__",
9467330f729Sjoerg Twine(TI.getSuitableAlign() / TI.getCharWidth()) );
9477330f729Sjoerg
9487330f729Sjoerg if (!LangOpts.CharIsSigned)
9497330f729Sjoerg Builder.defineMacro("__CHAR_UNSIGNED__");
9507330f729Sjoerg
9517330f729Sjoerg if (!TargetInfo::isTypeSigned(TI.getWCharType()))
9527330f729Sjoerg Builder.defineMacro("__WCHAR_UNSIGNED__");
9537330f729Sjoerg
9547330f729Sjoerg if (!TargetInfo::isTypeSigned(TI.getWIntType()))
9557330f729Sjoerg Builder.defineMacro("__WINT_UNSIGNED__");
9567330f729Sjoerg
9577330f729Sjoerg // Define exact-width integer types for stdint.h
9587330f729Sjoerg DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder);
9597330f729Sjoerg
9607330f729Sjoerg if (TI.getShortWidth() > TI.getCharWidth())
9617330f729Sjoerg DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
9627330f729Sjoerg
9637330f729Sjoerg if (TI.getIntWidth() > TI.getShortWidth())
9647330f729Sjoerg DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
9657330f729Sjoerg
9667330f729Sjoerg if (TI.getLongWidth() > TI.getIntWidth())
9677330f729Sjoerg DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
9687330f729Sjoerg
9697330f729Sjoerg if (TI.getLongLongWidth() > TI.getLongWidth())
9707330f729Sjoerg DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
9717330f729Sjoerg
9727330f729Sjoerg DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
9737330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
9747330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
9757330f729Sjoerg
9767330f729Sjoerg if (TI.getShortWidth() > TI.getCharWidth()) {
9777330f729Sjoerg DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
9787330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
9797330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
9807330f729Sjoerg }
9817330f729Sjoerg
9827330f729Sjoerg if (TI.getIntWidth() > TI.getShortWidth()) {
9837330f729Sjoerg DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
9847330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
9857330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
9867330f729Sjoerg }
9877330f729Sjoerg
9887330f729Sjoerg if (TI.getLongWidth() > TI.getIntWidth()) {
9897330f729Sjoerg DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
9907330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
9917330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
9927330f729Sjoerg }
9937330f729Sjoerg
9947330f729Sjoerg if (TI.getLongLongWidth() > TI.getLongWidth()) {
9957330f729Sjoerg DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
9967330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
9977330f729Sjoerg DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
9987330f729Sjoerg }
9997330f729Sjoerg
10007330f729Sjoerg DefineLeastWidthIntType(8, true, TI, Builder);
10017330f729Sjoerg DefineLeastWidthIntType(8, false, TI, Builder);
10027330f729Sjoerg DefineLeastWidthIntType(16, true, TI, Builder);
10037330f729Sjoerg DefineLeastWidthIntType(16, false, TI, Builder);
10047330f729Sjoerg DefineLeastWidthIntType(32, true, TI, Builder);
10057330f729Sjoerg DefineLeastWidthIntType(32, false, TI, Builder);
10067330f729Sjoerg DefineLeastWidthIntType(64, true, TI, Builder);
10077330f729Sjoerg DefineLeastWidthIntType(64, false, TI, Builder);
10087330f729Sjoerg
10097330f729Sjoerg DefineFastIntType(8, true, TI, Builder);
10107330f729Sjoerg DefineFastIntType(8, false, TI, Builder);
10117330f729Sjoerg DefineFastIntType(16, true, TI, Builder);
10127330f729Sjoerg DefineFastIntType(16, false, TI, Builder);
10137330f729Sjoerg DefineFastIntType(32, true, TI, Builder);
10147330f729Sjoerg DefineFastIntType(32, false, TI, Builder);
10157330f729Sjoerg DefineFastIntType(64, true, TI, Builder);
10167330f729Sjoerg DefineFastIntType(64, false, TI, Builder);
10177330f729Sjoerg
1018*e038c9c4Sjoerg Builder.defineMacro("__USER_LABEL_PREFIX__", TI.getUserLabelPrefix());
10197330f729Sjoerg
10207330f729Sjoerg if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
10217330f729Sjoerg Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
10227330f729Sjoerg else
10237330f729Sjoerg Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
10247330f729Sjoerg
10257330f729Sjoerg if (LangOpts.GNUCVersion) {
10267330f729Sjoerg if (LangOpts.GNUInline || LangOpts.CPlusPlus)
10277330f729Sjoerg Builder.defineMacro("__GNUC_GNU_INLINE__");
10287330f729Sjoerg else
10297330f729Sjoerg Builder.defineMacro("__GNUC_STDC_INLINE__");
10307330f729Sjoerg
10317330f729Sjoerg // The value written by __atomic_test_and_set.
10327330f729Sjoerg // FIXME: This is target-dependent.
10337330f729Sjoerg Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
10347330f729Sjoerg }
10357330f729Sjoerg
10367330f729Sjoerg auto addLockFreeMacros = [&](const llvm::Twine &Prefix) {
10377330f729Sjoerg // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
10387330f729Sjoerg unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
10397330f729Sjoerg #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
10407330f729Sjoerg Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \
10417330f729Sjoerg getLockFreeValue(TI.get##Type##Width(), \
10427330f729Sjoerg TI.get##Type##Align(), \
10437330f729Sjoerg InlineWidthBits));
10447330f729Sjoerg DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
10457330f729Sjoerg DEFINE_LOCK_FREE_MACRO(CHAR, Char);
10467330f729Sjoerg if (LangOpts.Char8)
10477330f729Sjoerg DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
10487330f729Sjoerg DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
10497330f729Sjoerg DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
10507330f729Sjoerg DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
10517330f729Sjoerg DEFINE_LOCK_FREE_MACRO(SHORT, Short);
10527330f729Sjoerg DEFINE_LOCK_FREE_MACRO(INT, Int);
10537330f729Sjoerg DEFINE_LOCK_FREE_MACRO(LONG, Long);
10547330f729Sjoerg DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
10557330f729Sjoerg Builder.defineMacro(Prefix + "POINTER_LOCK_FREE",
10567330f729Sjoerg getLockFreeValue(TI.getPointerWidth(0),
10577330f729Sjoerg TI.getPointerAlign(0),
10587330f729Sjoerg InlineWidthBits));
10597330f729Sjoerg #undef DEFINE_LOCK_FREE_MACRO
10607330f729Sjoerg };
10617330f729Sjoerg addLockFreeMacros("__CLANG_ATOMIC_");
10627330f729Sjoerg if (LangOpts.GNUCVersion)
10637330f729Sjoerg addLockFreeMacros("__GCC_ATOMIC_");
10647330f729Sjoerg
10657330f729Sjoerg if (LangOpts.NoInlineDefine)
10667330f729Sjoerg Builder.defineMacro("__NO_INLINE__");
10677330f729Sjoerg
10687330f729Sjoerg if (unsigned PICLevel = LangOpts.PICLevel) {
10697330f729Sjoerg Builder.defineMacro("__PIC__", Twine(PICLevel));
10707330f729Sjoerg Builder.defineMacro("__pic__", Twine(PICLevel));
10717330f729Sjoerg if (LangOpts.PIE) {
10727330f729Sjoerg Builder.defineMacro("__PIE__", Twine(PICLevel));
10737330f729Sjoerg Builder.defineMacro("__pie__", Twine(PICLevel));
10747330f729Sjoerg }
10757330f729Sjoerg }
10767330f729Sjoerg
10777330f729Sjoerg // Macros to control C99 numerics and <float.h>
10787330f729Sjoerg Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
10797330f729Sjoerg Builder.defineMacro("__FLT_RADIX__", "2");
10807330f729Sjoerg Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
10817330f729Sjoerg
10827330f729Sjoerg if (LangOpts.getStackProtector() == LangOptions::SSPOn)
10837330f729Sjoerg Builder.defineMacro("__SSP__");
10847330f729Sjoerg else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
10857330f729Sjoerg Builder.defineMacro("__SSP_STRONG__", "2");
10867330f729Sjoerg else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
10877330f729Sjoerg Builder.defineMacro("__SSP_ALL__", "3");
10887330f729Sjoerg
10897330f729Sjoerg if (PPOpts.SetUpStaticAnalyzer)
10907330f729Sjoerg Builder.defineMacro("__clang_analyzer__");
10917330f729Sjoerg
10927330f729Sjoerg if (LangOpts.FastRelaxedMath)
10937330f729Sjoerg Builder.defineMacro("__FAST_RELAXED_MATH__");
10947330f729Sjoerg
10957330f729Sjoerg if (FEOpts.ProgramAction == frontend::RewriteObjC ||
10967330f729Sjoerg LangOpts.getGC() != LangOptions::NonGC) {
10977330f729Sjoerg Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
10987330f729Sjoerg Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
10997330f729Sjoerg Builder.defineMacro("__autoreleasing", "");
11007330f729Sjoerg Builder.defineMacro("__unsafe_unretained", "");
11017330f729Sjoerg } else if (LangOpts.ObjC) {
11027330f729Sjoerg Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
11037330f729Sjoerg Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
11047330f729Sjoerg Builder.defineMacro("__autoreleasing",
11057330f729Sjoerg "__attribute__((objc_ownership(autoreleasing)))");
11067330f729Sjoerg Builder.defineMacro("__unsafe_unretained",
11077330f729Sjoerg "__attribute__((objc_ownership(none)))");
11087330f729Sjoerg }
11097330f729Sjoerg
11107330f729Sjoerg // On Darwin, there are __double_underscored variants of the type
11117330f729Sjoerg // nullability qualifiers.
11127330f729Sjoerg if (TI.getTriple().isOSDarwin()) {
11137330f729Sjoerg Builder.defineMacro("__nonnull", "_Nonnull");
11147330f729Sjoerg Builder.defineMacro("__null_unspecified", "_Null_unspecified");
11157330f729Sjoerg Builder.defineMacro("__nullable", "_Nullable");
11167330f729Sjoerg }
11177330f729Sjoerg
11187330f729Sjoerg // Add a macro to differentiate between regular iOS/tvOS/watchOS targets and
11197330f729Sjoerg // the corresponding simulator targets.
11207330f729Sjoerg if (TI.getTriple().isOSDarwin() && TI.getTriple().isSimulatorEnvironment())
11217330f729Sjoerg Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1");
11227330f729Sjoerg
11237330f729Sjoerg // OpenMP definition
11247330f729Sjoerg // OpenMP 2.2:
11257330f729Sjoerg // In implementations that support a preprocessor, the _OPENMP
11267330f729Sjoerg // macro name is defined to have the decimal value yyyymm where
11277330f729Sjoerg // yyyy and mm are the year and the month designations of the
11287330f729Sjoerg // version of the OpenMP API that the implementation support.
11297330f729Sjoerg if (!LangOpts.OpenMPSimd) {
11307330f729Sjoerg switch (LangOpts.OpenMP) {
11317330f729Sjoerg case 0:
11327330f729Sjoerg break;
11337330f729Sjoerg case 31:
11347330f729Sjoerg Builder.defineMacro("_OPENMP", "201107");
11357330f729Sjoerg break;
11367330f729Sjoerg case 40:
11377330f729Sjoerg Builder.defineMacro("_OPENMP", "201307");
11387330f729Sjoerg break;
1139*e038c9c4Sjoerg case 45:
1140*e038c9c4Sjoerg Builder.defineMacro("_OPENMP", "201511");
11417330f729Sjoerg break;
11427330f729Sjoerg default:
1143*e038c9c4Sjoerg // Default version is OpenMP 5.0
1144*e038c9c4Sjoerg Builder.defineMacro("_OPENMP", "201811");
11457330f729Sjoerg break;
11467330f729Sjoerg }
11477330f729Sjoerg }
11487330f729Sjoerg
11497330f729Sjoerg // CUDA device path compilaton
11507330f729Sjoerg if (LangOpts.CUDAIsDevice && !LangOpts.HIP) {
11517330f729Sjoerg // The CUDA_ARCH value is set for the GPU target specified in the NVPTX
11527330f729Sjoerg // backend's target defines.
11537330f729Sjoerg Builder.defineMacro("__CUDA_ARCH__");
11547330f729Sjoerg }
11557330f729Sjoerg
11567330f729Sjoerg // We need to communicate this to our CUDA header wrapper, which in turn
11577330f729Sjoerg // informs the proper CUDA headers of this choice.
11587330f729Sjoerg if (LangOpts.CUDADeviceApproxTranscendentals || LangOpts.FastMath) {
11597330f729Sjoerg Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
11607330f729Sjoerg }
11617330f729Sjoerg
11627330f729Sjoerg // Define a macro indicating that the source file is being compiled with a
11637330f729Sjoerg // SYCL device compiler which doesn't produce host binary.
11647330f729Sjoerg if (LangOpts.SYCLIsDevice) {
11657330f729Sjoerg Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
11667330f729Sjoerg }
11677330f729Sjoerg
11687330f729Sjoerg // OpenCL definitions.
11697330f729Sjoerg if (LangOpts.OpenCL) {
1170*e038c9c4Sjoerg InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
11717330f729Sjoerg
11727330f729Sjoerg if (TI.getTriple().isSPIR())
11737330f729Sjoerg Builder.defineMacro("__IMAGE_SUPPORT__");
11747330f729Sjoerg }
11757330f729Sjoerg
11767330f729Sjoerg if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
11777330f729Sjoerg // For each extended integer type, g++ defines a macro mapping the
11787330f729Sjoerg // index of the type (0 in this case) in some list of extended types
11797330f729Sjoerg // to the type.
11807330f729Sjoerg Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128");
11817330f729Sjoerg Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
11827330f729Sjoerg }
11837330f729Sjoerg
11847330f729Sjoerg // Get other target #defines.
11857330f729Sjoerg TI.getTargetDefines(LangOpts, Builder);
11867330f729Sjoerg }
11877330f729Sjoerg
11887330f729Sjoerg /// InitializePreprocessor - Initialize the preprocessor getting it and the
11897330f729Sjoerg /// environment ready to process a single file. This returns true on error.
11907330f729Sjoerg ///
InitializePreprocessor(Preprocessor & PP,const PreprocessorOptions & InitOpts,const PCHContainerReader & PCHContainerRdr,const FrontendOptions & FEOpts)11917330f729Sjoerg void clang::InitializePreprocessor(
11927330f729Sjoerg Preprocessor &PP, const PreprocessorOptions &InitOpts,
11937330f729Sjoerg const PCHContainerReader &PCHContainerRdr,
11947330f729Sjoerg const FrontendOptions &FEOpts) {
11957330f729Sjoerg const LangOptions &LangOpts = PP.getLangOpts();
11967330f729Sjoerg std::string PredefineBuffer;
11977330f729Sjoerg PredefineBuffer.reserve(4080);
11987330f729Sjoerg llvm::raw_string_ostream Predefines(PredefineBuffer);
11997330f729Sjoerg MacroBuilder Builder(Predefines);
12007330f729Sjoerg
12017330f729Sjoerg // Emit line markers for various builtin sections of the file. We don't do
12027330f729Sjoerg // this in asm preprocessor mode, because "# 4" is not a line marker directive
12037330f729Sjoerg // in this mode.
12047330f729Sjoerg if (!PP.getLangOpts().AsmPreprocessor)
12057330f729Sjoerg Builder.append("# 1 \"<built-in>\" 3");
12067330f729Sjoerg
12077330f729Sjoerg // Install things like __POWERPC__, __GNUC__, etc into the macro table.
12087330f729Sjoerg if (InitOpts.UsePredefines) {
12097330f729Sjoerg // FIXME: This will create multiple definitions for most of the predefined
12107330f729Sjoerg // macros. This is not the right way to handle this.
1211*e038c9c4Sjoerg if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
1212*e038c9c4Sjoerg PP.getAuxTargetInfo())
12137330f729Sjoerg InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
12147330f729Sjoerg PP.getPreprocessorOpts(), Builder);
12157330f729Sjoerg
12167330f729Sjoerg InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts,
12177330f729Sjoerg PP.getPreprocessorOpts(), Builder);
12187330f729Sjoerg
12197330f729Sjoerg // Install definitions to make Objective-C++ ARC work well with various
12207330f729Sjoerg // C++ Standard Library implementations.
12217330f729Sjoerg if (LangOpts.ObjC && LangOpts.CPlusPlus &&
12227330f729Sjoerg (LangOpts.ObjCAutoRefCount || LangOpts.ObjCWeak)) {
12237330f729Sjoerg switch (InitOpts.ObjCXXARCStandardLibrary) {
12247330f729Sjoerg case ARCXX_nolib:
12257330f729Sjoerg case ARCXX_libcxx:
12267330f729Sjoerg break;
12277330f729Sjoerg
12287330f729Sjoerg case ARCXX_libstdcxx:
12297330f729Sjoerg AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
12307330f729Sjoerg break;
12317330f729Sjoerg }
12327330f729Sjoerg }
12337330f729Sjoerg }
12347330f729Sjoerg
12357330f729Sjoerg // Even with predefines off, some macros are still predefined.
12367330f729Sjoerg // These should all be defined in the preprocessor according to the
12377330f729Sjoerg // current language configuration.
12387330f729Sjoerg InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
12397330f729Sjoerg FEOpts, Builder);
12407330f729Sjoerg
12417330f729Sjoerg // Add on the predefines from the driver. Wrap in a #line directive to report
12427330f729Sjoerg // that they come from the command line.
12437330f729Sjoerg if (!PP.getLangOpts().AsmPreprocessor)
12447330f729Sjoerg Builder.append("# 1 \"<command line>\" 1");
12457330f729Sjoerg
12467330f729Sjoerg // Process #define's and #undef's in the order they are given.
12477330f729Sjoerg for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
12487330f729Sjoerg if (InitOpts.Macros[i].second) // isUndef
12497330f729Sjoerg Builder.undefineMacro(InitOpts.Macros[i].first);
12507330f729Sjoerg else
12517330f729Sjoerg DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
12527330f729Sjoerg PP.getDiagnostics());
12537330f729Sjoerg }
12547330f729Sjoerg
12557330f729Sjoerg // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
12567330f729Sjoerg if (!PP.getLangOpts().AsmPreprocessor)
12577330f729Sjoerg Builder.append("# 1 \"<built-in>\" 2");
12587330f729Sjoerg
12597330f729Sjoerg // If -imacros are specified, include them now. These are processed before
12607330f729Sjoerg // any -include directives.
12617330f729Sjoerg for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
12627330f729Sjoerg AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
12637330f729Sjoerg
12647330f729Sjoerg // Process -include-pch/-include-pth directives.
12657330f729Sjoerg if (!InitOpts.ImplicitPCHInclude.empty())
12667330f729Sjoerg AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
12677330f729Sjoerg InitOpts.ImplicitPCHInclude);
12687330f729Sjoerg
12697330f729Sjoerg // Process -include directives.
12707330f729Sjoerg for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
12717330f729Sjoerg const std::string &Path = InitOpts.Includes[i];
12727330f729Sjoerg AddImplicitInclude(Builder, Path);
12737330f729Sjoerg }
12747330f729Sjoerg
12757330f729Sjoerg // Instruct the preprocessor to skip the preamble.
12767330f729Sjoerg PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
12777330f729Sjoerg InitOpts.PrecompiledPreambleBytes.second);
12787330f729Sjoerg
12797330f729Sjoerg // Copy PredefinedBuffer into the Preprocessor.
12807330f729Sjoerg PP.setPredefines(Predefines.str());
12817330f729Sjoerg }
1282