Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Frontend/InitPreprocessor.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- InitPreprocessor.cpp - PP initialization code. ---------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the clang::InitializePreprocessor function.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Basic/FileManager.h"
14
#include "clang/Basic/MacroBuilder.h"
15
#include "clang/Basic/SourceManager.h"
16
#include "clang/Basic/SyncScope.h"
17
#include "clang/Basic/TargetInfo.h"
18
#include "clang/Basic/Version.h"
19
#include "clang/Frontend/FrontendDiagnostic.h"
20
#include "clang/Frontend/FrontendOptions.h"
21
#include "clang/Frontend/Utils.h"
22
#include "clang/Lex/HeaderSearch.h"
23
#include "clang/Lex/Preprocessor.h"
24
#include "clang/Lex/PreprocessorOptions.h"
25
#include "clang/Serialization/ASTReader.h"
26
#include "llvm/ADT/APFloat.h"
27
using namespace clang;
28
29
5.76k
static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
30
5.76k
  while (!MacroBody.empty() && 
isWhitespace(MacroBody.back())5.46k
)
31
0
    MacroBody = MacroBody.drop_back();
32
5.76k
  return !MacroBody.empty() && 
MacroBody.back() == '\\'5.46k
;
33
5.76k
}
34
35
// Append a #define line to Buf for Macro.  Macro should be of the form XXX,
36
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
37
// "#define XXX Y z W".  To get a #define with no value, use "XXX=".
38
static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
39
329k
                               DiagnosticsEngine &Diags) {
40
329k
  std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
41
329k
  StringRef MacroName = MacroPair.first;
42
329k
  StringRef MacroBody = MacroPair.second;
43
329k
  if (MacroName.size() != Macro.size()) {
44
5.76k
    // Per GCC -D semantics, the macro ends at \n if it exists.
45
5.76k
    StringRef::size_type End = MacroBody.find_first_of("\n\r");
46
5.76k
    if (End != StringRef::npos)
47
3
      Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
48
3
        << MacroName;
49
5.76k
    MacroBody = MacroBody.substr(0, End);
50
5.76k
    // We handle macro bodies which end in a backslash by appending an extra
51
5.76k
    // backslash+newline.  This makes sure we don't accidentally treat the
52
5.76k
    // backslash as a line continuation marker.
53
5.76k
    if (MacroBodyEndsInBackslash(MacroBody))
54
2
      Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
55
5.76k
    else
56
5.76k
      Builder.defineMacro(MacroName, MacroBody);
57
324k
  } else {
58
324k
    // Push "macroname 1".
59
324k
    Builder.defineMacro(Macro);
60
324k
  }
61
329k
}
62
63
/// AddImplicitInclude - Add an implicit \#include of the specified file to the
64
/// predefines buffer.
65
/// As these includes are generated by -include arguments the header search
66
/// logic is going to search relatively to the current working directory.
67
2.65k
static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
68
2.65k
  Builder.append(Twine("#include \"") + File + "\"");
69
2.65k
}
70
71
2
static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
72
2
  Builder.append(Twine("#__include_macros \"") + File + "\"");
73
2
  // Marker token to stop the __include_macros fetch loop.
74
2
  Builder.append("##"); // ##?
75
2
}
76
77
/// Add an implicit \#include using the original file used to generate
78
/// a PCH file.
79
static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
80
                                  const PCHContainerReader &PCHContainerRdr,
81
2.36k
                                  StringRef ImplicitIncludePCH) {
82
2.36k
  std::string OriginalFile =
83
2.36k
      ASTReader::getOriginalSourceFile(ImplicitIncludePCH, PP.getFileManager(),
84
2.36k
                                       PCHContainerRdr, PP.getDiagnostics());
85
2.36k
  if (OriginalFile.empty())
86
1
    return;
87
2.36k
88
2.36k
  AddImplicitInclude(Builder, OriginalFile);
89
2.36k
}
90
91
/// PickFP - This is used to pick a value based on the FP semantics of the
92
/// specified FP model.
93
template <typename T>
94
static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
95
                T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
96
1.54M
                T IEEEQuadVal) {
97
1.54M
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
98
85.7k
    return IEEEHalfVal;
99
1.45M
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
100
485k
    return IEEESingleVal;
101
970k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
102
579k
    return IEEEDoubleVal;
103
390k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
104
349k
    return X87DoubleExtendedVal;
105
40.9k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
106
27.0k
    return PPCDoubleDoubleVal;
107
13.8k
  assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
108
13.8k
  return IEEEQuadVal;
109
13.8k
}
InitPreprocessor.cpp:char const* PickFP<char const*>(llvm::fltSemantics const*, char const*, char const*, char const*, char const*, char const*, char const*)
Line
Count
Source
96
560k
                T IEEEQuadVal) {
97
560k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
98
31.1k
    return IEEEHalfVal;
99
529k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
100
176k
    return IEEESingleVal;
101
352k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
102
210k
    return IEEEDoubleVal;
103
142k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
104
127k
    return X87DoubleExtendedVal;
105
14.8k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
106
9.84k
    return PPCDoubleDoubleVal;
107
5.05k
  assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
108
5.05k
  return IEEEQuadVal;
109
5.05k
}
InitPreprocessor.cpp:int PickFP<int>(llvm::fltSemantics const*, int, int, int, int, int, int)
Line
Count
Source
96
981k
                T IEEEQuadVal) {
97
981k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
98
54.5k
    return IEEEHalfVal;
99
926k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
100
309k
    return IEEESingleVal;
101
617k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
102
368k
    return IEEEDoubleVal;
103
248k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
104
222k
    return X87DoubleExtendedVal;
105
26.0k
  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
106
17.2k
    return PPCDoubleDoubleVal;
107
8.84k
  assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
108
8.84k
  return IEEEQuadVal;
109
8.84k
}
110
111
static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
112
140k
                              const llvm::fltSemantics *Sem, StringRef Ext) {
113
140k
  const char *DenormMin, *Epsilon, *Max, *Min;
114
140k
  DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45",
115
140k
                     "4.9406564584124654e-324", "3.64519953188247460253e-4951",
116
140k
                     "4.94065645841246544176568792868221e-324",
117
140k
                     "6.47517511943802511092443895822764655e-4966");
118
140k
  int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33);
119
140k
  int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36);
120
140k
  Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7",
121
140k
                   "2.2204460492503131e-16", "1.08420217248550443401e-19",
122
140k
                   "4.94065645841246544176568792868221e-324",
123
140k
                   "1.92592994438723585305597794258492732e-34");
124
140k
  int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113);
125
140k
  int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
126
140k
  int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
127
140k
  int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
128
140k
  int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
129
140k
  Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308",
130
140k
               "3.36210314311209350626e-4932",
131
140k
               "2.00416836000897277799610805135016e-292",
132
140k
               "3.36210314311209350626267781732175260e-4932");
133
140k
  Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308",
134
140k
               "1.18973149535723176502e+4932",
135
140k
               "1.79769313486231580793728971405301e+308",
136
140k
               "1.18973149535723176508575932662800702e+4932");
137
140k
138
140k
  SmallString<32> DefPrefix;
139
140k
  DefPrefix = "__";
140
140k
  DefPrefix += Prefix;
141
140k
  DefPrefix += "_";
142
140k
143
140k
  Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
144
140k
  Builder.defineMacro(DefPrefix + "HAS_DENORM__");
145
140k
  Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
146
140k
  Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits));
147
140k
  Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext);
148
140k
  Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
149
140k
  Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
150
140k
  Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits));
151
140k
152
140k
  Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp));
153
140k
  Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp));
154
140k
  Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext);
155
140k
156
140k
  Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")");
157
140k
  Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")");
158
140k
  Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext);
159
140k
}
160
161
162
/// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
163
/// named MacroName with the max value for a type with width 'TypeWidth' a
164
/// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
165
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
166
                           StringRef ValSuffix, bool isSigned,
167
1.67M
                           MacroBuilder &Builder) {
168
1.67M
  llvm::APInt MaxVal = isSigned ? 
llvm::APInt::getSignedMaxValue(TypeWidth)1.00M
169
1.67M
                                : 
llvm::APInt::getMaxValue(TypeWidth)669k
;
170
1.67M
  Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
171
1.67M
}
172
173
/// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
174
/// the width, suffix, and signedness of the given type
175
static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
176
1.67M
                           const TargetInfo &TI, MacroBuilder &Builder) {
177
1.67M
  DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
178
1.67M
                 TI.isTypeSigned(Ty), Builder);
179
1.67M
}
180
181
static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty,
182
1.32M
                      const TargetInfo &TI, MacroBuilder &Builder) {
183
1.32M
  bool IsSigned = TI.isTypeSigned(Ty);
184
1.32M
  StringRef FmtModifier = TI.getTypeFormatModifier(Ty);
185
5.30M
  for (const char *Fmt = IsSigned ? 
"di"662k
:
"ouxX"662k
; *Fmt;
++Fmt3.97M
) {
186
3.97M
    Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__",
187
3.97M
                        Twine("\"") + FmtModifier + Twine(*Fmt) + "\"");
188
3.97M
  }
189
1.32M
}
190
191
static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
192
1.50M
                       MacroBuilder &Builder) {
193
1.50M
  Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
194
1.50M
}
195
196
static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
197
397k
                            const TargetInfo &TI, MacroBuilder &Builder) {
198
397k
  Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
199
397k
}
200
201
static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
202
563k
                             const TargetInfo &TI, MacroBuilder &Builder) {
203
563k
  Builder.defineMacro(MacroName,
204
563k
                      Twine(BitWidth / TI.getCharWidth()));
205
563k
}
206
207
static void DefineExactWidthIntType(TargetInfo::IntType Ty,
208
                                    const TargetInfo &TI,
209
354k
                                    MacroBuilder &Builder) {
210
354k
  int TypeWidth = TI.getTypeWidth(Ty);
211
354k
  bool IsSigned = TI.isTypeSigned(Ty);
212
354k
213
354k
  // Use the target specified int64 type, when appropriate, so that [u]int64_t
214
354k
  // ends up being defined in terms of the correct type.
215
354k
  if (TypeWidth == 64)
216
88.2k
    Ty = IsSigned ? 
TI.getInt64Type()44.1k
:
TI.getUInt64Type()44.1k
;
217
354k
218
354k
  const char *Prefix = IsSigned ? 
"__INT"177k
:
"__UINT"177k
;
219
354k
220
354k
  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
221
354k
  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
222
354k
223
354k
  StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
224
354k
  Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
225
354k
}
226
227
static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
228
                                        const TargetInfo &TI,
229
354k
                                        MacroBuilder &Builder) {
230
354k
  int TypeWidth = TI.getTypeWidth(Ty);
231
354k
  bool IsSigned = TI.isTypeSigned(Ty);
232
354k
233
354k
  // Use the target specified int64 type, when appropriate, so that [u]int64_t
234
354k
  // ends up being defined in terms of the correct type.
235
354k
  if (TypeWidth == 64)
236
88.2k
    Ty = IsSigned ? 
TI.getInt64Type()44.1k
:
TI.getUInt64Type()44.1k
;
237
354k
238
354k
  const char *Prefix = IsSigned ? 
"__INT"177k
:
"__UINT"177k
;
239
354k
  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
240
354k
}
241
242
static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
243
                                    const TargetInfo &TI,
244
353k
                                    MacroBuilder &Builder) {
245
353k
  TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
246
353k
  if (Ty == TargetInfo::NoInt)
247
12
    return;
248
353k
249
353k
  const char *Prefix = IsSigned ? 
"__INT_LEAST"176k
:
"__UINT_LEAST"176k
;
250
353k
  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
251
353k
  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
252
353k
  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
253
353k
}
254
255
static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
256
353k
                              const TargetInfo &TI, MacroBuilder &Builder) {
257
353k
  // stdint.h currently defines the fast int types as equivalent to the least
258
353k
  // types.
259
353k
  TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
260
353k
  if (Ty == TargetInfo::NoInt)
261
12
    return;
262
353k
263
353k
  const char *Prefix = IsSigned ? 
"__INT_FAST"176k
:
"__UINT_FAST"176k
;
264
353k
  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
265
353k
  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
266
353k
267
353k
  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
268
353k
}
269
270
271
/// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
272
/// the specified properties.
273
static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
274
865k
                                    unsigned InlineWidth) {
275
865k
  // Fully-aligned, power-of-2 sizes no larger than the inline
276
865k
  // width will be inlined as lock-free operations.
277
865k
  if (TypeWidth == TypeAlign && 
(TypeWidth & (TypeWidth - 1)) == 0852k
&&
278
865k
      
TypeWidth <= InlineWidth852k
)
279
835k
    return "2"; // "always lock free"
280
29.8k
  // We cannot be certain what operations the lib calls might be
281
29.8k
  // able to implement as lock-free on future processors.
282
29.8k
  return "1"; // "sometimes lock free"
283
29.8k
}
284
285
/// Add definitions required for a smooth interaction between
286
/// Objective-C++ automated reference counting and libstdc++ (4.2).
287
static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts,
288
1
                                         MacroBuilder &Builder) {
289
1
  Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
290
1
291
1
  std::string Result;
292
1
  {
293
1
    // Provide specializations for the __is_scalar type trait so that
294
1
    // lifetime-qualified objects are not considered "scalar" types, which
295
1
    // libstdc++ uses as an indicator of the presence of trivial copy, assign,
296
1
    // default-construct, and destruct semantics (none of which hold for
297
1
    // lifetime-qualified objects in ARC).
298
1
    llvm::raw_string_ostream Out(Result);
299
1
300
1
    Out << "namespace std {\n"
301
1
        << "\n"
302
1
        << "struct __true_type;\n"
303
1
        << "struct __false_type;\n"
304
1
        << "\n";
305
1
306
1
    Out << "template<typename _Tp> struct __is_scalar;\n"
307
1
        << "\n";
308
1
309
1
    if (LangOpts.ObjCAutoRefCount) {
310
1
      Out << "template<typename _Tp>\n"
311
1
          << "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
312
1
          << "  enum { __value = 0 };\n"
313
1
          << "  typedef __false_type __type;\n"
314
1
          << "};\n"
315
1
          << "\n";
316
1
    }
317
1
318
1
    if (LangOpts.ObjCWeak) {
319
1
      Out << "template<typename _Tp>\n"
320
1
          << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
321
1
          << "  enum { __value = 0 };\n"
322
1
          << "  typedef __false_type __type;\n"
323
1
          << "};\n"
324
1
          << "\n";
325
1
    }
326
1
327
1
    if (LangOpts.ObjCAutoRefCount) {
328
1
      Out << "template<typename _Tp>\n"
329
1
          << "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
330
1
          << " _Tp> {\n"
331
1
          << "  enum { __value = 0 };\n"
332
1
          << "  typedef __false_type __type;\n"
333
1
          << "};\n"
334
1
          << "\n";
335
1
    }
336
1
337
1
    Out << "}\n";
338
1
  }
339
1
  Builder.append(Result);
340
1
}
341
342
static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
343
                                               const LangOptions &LangOpts,
344
                                               const FrontendOptions &FEOpts,
345
44.0k
                                               MacroBuilder &Builder) {
346
44.0k
  if (!LangOpts.MSVCCompat && 
!LangOpts.TraditionalCPP42.3k
)
347
42.3k
    Builder.defineMacro("__STDC__");
348
44.0k
  if (LangOpts.Freestanding)
349
3.21k
    Builder.defineMacro("__STDC_HOSTED__", "0");
350
40.8k
  else
351
40.8k
    Builder.defineMacro("__STDC_HOSTED__");
352
44.0k
353
44.0k
  if (!LangOpts.CPlusPlus) {
354
17.8k
    if (LangOpts.C17)
355
9
      Builder.defineMacro("__STDC_VERSION__", "201710L");
356
17.7k
    else if (LangOpts.C11)
357
16.5k
      Builder.defineMacro("__STDC_VERSION__", "201112L");
358
1.21k
    else if (LangOpts.C99)
359
1.04k
      Builder.defineMacro("__STDC_VERSION__", "199901L");
360
173
    else if (!LangOpts.GNUMode && 
LangOpts.Digraphs60
)
361
5
      Builder.defineMacro("__STDC_VERSION__", "199409L");
362
26.2k
  } else {
363
26.2k
    // FIXME: Use correct value for C++20.
364
26.2k
    if (LangOpts.CPlusPlus2a)
365
223
      Builder.defineMacro("__cplusplus", "201707L");
366
26.0k
    // C++17 [cpp.predefined]p1:
367
26.0k
    //   The name __cplusplus is defined to the value 201703L when compiling a
368
26.0k
    //   C++ translation unit.
369
26.0k
    else if (LangOpts.CPlusPlus17)
370
637
      Builder.defineMacro("__cplusplus", "201703L");
371
25.4k
    // C++1y [cpp.predefined]p1:
372
25.4k
    //   The name __cplusplus is defined to the value 201402L when compiling a
373
25.4k
    //   C++ translation unit.
374
25.4k
    else if (LangOpts.CPlusPlus14)
375
10.3k
      Builder.defineMacro("__cplusplus", "201402L");
376
15.0k
    // C++11 [cpp.predefined]p1:
377
15.0k
    //   The name __cplusplus is defined to the value 201103L when compiling a
378
15.0k
    //   C++ translation unit.
379
15.0k
    else if (LangOpts.CPlusPlus11)
380
11.6k
      Builder.defineMacro("__cplusplus", "201103L");
381
3.38k
    // C++03 [cpp.predefined]p1:
382
3.38k
    //   The name __cplusplus is defined to the value 199711L when compiling a
383
3.38k
    //   C++ translation unit.
384
3.38k
    else
385
3.38k
      Builder.defineMacro("__cplusplus", "199711L");
386
26.2k
387
26.2k
    // C++1z [cpp.predefined]p1:
388
26.2k
    //   An integer literal of type std::size_t whose value is the alignment
389
26.2k
    //   guaranteed by a call to operator new(std::size_t)
390
26.2k
    //
391
26.2k
    // We provide this in all language modes, since it seems generally useful.
392
26.2k
    Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__",
393
26.2k
                        Twine(TI.getNewAlign() / TI.getCharWidth()) +
394
26.2k
                            TI.getTypeConstantSuffix(TI.getSizeType()));
395
26.2k
  }
396
44.0k
397
44.0k
  // In C11 these are environment macros. In C++11 they are only defined
398
44.0k
  // as part of <cuchar>. To prevent breakage when mixing C and C++
399
44.0k
  // code, define these macros unconditionally. We can define them
400
44.0k
  // unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
401
44.0k
  // and 32-bit character literals.
402
44.0k
  Builder.defineMacro("__STDC_UTF_16__", "1");
403
44.0k
  Builder.defineMacro("__STDC_UTF_32__", "1");
404
44.0k
405
44.0k
  if (LangOpts.ObjC)
406
4.96k
    Builder.defineMacro("__OBJC__");
407
44.0k
408
44.0k
  // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
409
44.0k
  if (LangOpts.OpenCL) {
410
610
    if (LangOpts.CPlusPlus) {
411
55
      if (LangOpts.OpenCLCPlusPlusVersion == 100)
412
55
        Builder.defineMacro("__OPENCL_CPP_VERSION__", "100");
413
55
      else
414
55
        
llvm_unreachable0
("Unsupported C++ version for OpenCL");
415
55
      Builder.defineMacro("__CL_CPP_VERSION_1_0__", "100");
416
555
    } else {
417
555
      // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
418
555
      // language standard with which the program is compiled. __OPENCL_VERSION__
419
555
      // is for the OpenCL version supported by the OpenCL device, which is not
420
555
      // necessarily the language standard with which the program is compiled.
421
555
      // A shared OpenCL header file requires a macro to indicate the language
422
555
      // standard. As a workaround, __OPENCL_C_VERSION__ is defined for
423
555
      // OpenCL v1.0 and v1.1.
424
555
      switch (LangOpts.OpenCLVersion) {
425
555
      case 100:
426
315
        Builder.defineMacro("__OPENCL_C_VERSION__", "100");
427
315
        break;
428
555
      case 110:
429
25
        Builder.defineMacro("__OPENCL_C_VERSION__", "110");
430
25
        break;
431
555
      case 120:
432
64
        Builder.defineMacro("__OPENCL_C_VERSION__", "120");
433
64
        break;
434
555
      case 200:
435
151
        Builder.defineMacro("__OPENCL_C_VERSION__", "200");
436
151
        break;
437
555
      default:
438
0
        llvm_unreachable("Unsupported OpenCL version");
439
555
      }
440
555
      Builder.defineMacro("CL_VERSION_1_0", "100");
441
555
      Builder.defineMacro("CL_VERSION_1_1", "110");
442
555
      Builder.defineMacro("CL_VERSION_1_2", "120");
443
555
      Builder.defineMacro("CL_VERSION_2_0", "200");
444
555
445
555
      if (TI.isLittleEndian())
446
555
        Builder.defineMacro("__ENDIAN_LITTLE__");
447
555
448
555
      if (LangOpts.FastRelaxedMath)
449
2
        Builder.defineMacro("__FAST_RELAXED_MATH__");
450
555
    }
451
610
  }
452
44.0k
  // Not "standard" per se, but available even with the -undef flag.
453
44.0k
  if (LangOpts.AsmPreprocessor)
454
740
    Builder.defineMacro("__ASSEMBLER__");
455
44.0k
  if (LangOpts.CUDA && 
!LangOpts.HIP257
)
456
237
    Builder.defineMacro("__CUDA__");
457
44.0k
  if (LangOpts.HIP) {
458
20
    Builder.defineMacro("__HIP__");
459
20
    Builder.defineMacro("__HIPCC__");
460
20
    if (LangOpts.CUDAIsDevice)
461
8
      Builder.defineMacro("__HIP_DEVICE_COMPILE__");
462
20
  }
463
44.0k
}
464
465
/// Initialize the predefined C++ language feature test macros defined in
466
/// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
467
static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
468
26.3k
                                                 MacroBuilder &Builder) {
469
26.3k
  // C++98 features.
470
26.3k
  if (LangOpts.RTTI)
471
24.1k
    Builder.defineMacro("__cpp_rtti", "199711L");
472
26.3k
  if (LangOpts.CXXExceptions)
473
9.55k
    Builder.defineMacro("__cpp_exceptions", "199711L");
474
26.3k
475
26.3k
  // C++11 features.
476
26.3k
  if (LangOpts.CPlusPlus11) {
477
22.9k
    Builder.defineMacro("__cpp_unicode_characters", "200704L");
478
22.9k
    Builder.defineMacro("__cpp_raw_strings", "200710L");
479
22.9k
    Builder.defineMacro("__cpp_unicode_literals", "200710L");
480
22.9k
    Builder.defineMacro("__cpp_user_defined_literals", "200809L");
481
22.9k
    Builder.defineMacro("__cpp_lambdas", "200907L");
482
22.9k
    Builder.defineMacro("__cpp_constexpr",
483
22.9k
                        LangOpts.CPlusPlus17 ? 
"201603L"862
:
484
22.9k
                        
LangOpts.CPlusPlus14 22.0k
?
"201304L"10.3k
:
"200704"11.6k
);
485
22.9k
    Builder.defineMacro("__cpp_range_based_for",
486
22.9k
                        LangOpts.CPlusPlus17 ? 
"201603L"862
:
"200907"22.0k
);
487
22.9k
    Builder.defineMacro("__cpp_static_assert",
488
22.9k
                        LangOpts.CPlusPlus17 ? 
"201411L"862
:
"200410"22.0k
);
489
22.9k
    Builder.defineMacro("__cpp_decltype", "200707L");
490
22.9k
    Builder.defineMacro("__cpp_attributes", "200809L");
491
22.9k
    Builder.defineMacro("__cpp_rvalue_references", "200610L");
492
22.9k
    Builder.defineMacro("__cpp_variadic_templates", "200704L");
493
22.9k
    Builder.defineMacro("__cpp_initializer_lists", "200806L");
494
22.9k
    Builder.defineMacro("__cpp_delegating_constructors", "200604L");
495
22.9k
    Builder.defineMacro("__cpp_nsdmi", "200809L");
496
22.9k
    Builder.defineMacro("__cpp_inheriting_constructors", "201511L");
497
22.9k
    Builder.defineMacro("__cpp_ref_qualifiers", "200710L");
498
22.9k
    Builder.defineMacro("__cpp_alias_templates", "200704L");
499
22.9k
  }
500
26.3k
  if (LangOpts.ThreadsafeStatics)
501
26.1k
    Builder.defineMacro("__cpp_threadsafe_static_init", "200806L");
502
26.3k
503
26.3k
  // C++14 features.
504
26.3k
  if (LangOpts.CPlusPlus14) {
505
11.2k
    Builder.defineMacro("__cpp_binary_literals", "201304L");
506
11.2k
    Builder.defineMacro("__cpp_digit_separators", "201309L");
507
11.2k
    Builder.defineMacro("__cpp_init_captures", "201304L");
508
11.2k
    Builder.defineMacro("__cpp_generic_lambdas", "201304L");
509
11.2k
    Builder.defineMacro("__cpp_decltype_auto", "201304L");
510
11.2k
    Builder.defineMacro("__cpp_return_type_deduction", "201304L");
511
11.2k
    Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L");
512
11.2k
    Builder.defineMacro("__cpp_variable_templates", "201304L");
513
11.2k
  }
514
26.3k
  if (LangOpts.SizedDeallocation)
515
36
    Builder.defineMacro("__cpp_sized_deallocation", "201309L");
516
26.3k
517
26.3k
  // C++17 features.
518
26.3k
  if (LangOpts.CPlusPlus17) {
519
862
    Builder.defineMacro("__cpp_hex_float", "201603L");
520
862
    Builder.defineMacro("__cpp_inline_variables", "201606L");
521
862
    Builder.defineMacro("__cpp_noexcept_function_type", "201510L");
522
862
    Builder.defineMacro("__cpp_capture_star_this", "201603L");
523
862
    Builder.defineMacro("__cpp_if_constexpr", "201606L");
524
862
    Builder.defineMacro("__cpp_deduction_guides", "201703L");
525
862
    Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name)
526
862
    Builder.defineMacro("__cpp_namespace_attributes", "201411L");
527
862
    Builder.defineMacro("__cpp_enumerator_attributes", "201411L");
528
862
    Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
529
862
    Builder.defineMacro("__cpp_variadic_using", "201611L");
530
862
    Builder.defineMacro("__cpp_aggregate_bases", "201603L");
531
862
    Builder.defineMacro("__cpp_structured_bindings", "201606L");
532
862
    Builder.defineMacro("__cpp_nontype_template_args", "201411L");
533
862
    Builder.defineMacro("__cpp_fold_expressions", "201603L");
534
862
    Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
535
862
    Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
536
862
  }
537
26.3k
  if (LangOpts.AlignedAllocation && 
!LangOpts.AlignedAllocationUnavailable867
)
538
857
    Builder.defineMacro("__cpp_aligned_new", "201606L");
539
26.3k
  if (LangOpts.RelaxedTemplateTemplateArgs)
540
2
    Builder.defineMacro("__cpp_template_template_args", "201611L");
541
26.3k
542
26.3k
  // C++20 features.
543
26.3k
  if (LangOpts.CPlusPlus2a)
544
223
    Builder.defineMacro("__cpp_conditional_explicit", "201806L");
545
26.3k
  if (LangOpts.Char8)
546
226
    Builder.defineMacro("__cpp_char8_t", "201811L");
547
26.3k
  Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
548
26.3k
549
26.3k
  // TS features.
550
26.3k
  if (LangOpts.ConceptsTS)
551
8
    Builder.defineMacro("__cpp_experimental_concepts", "1L");
552
26.3k
  if (LangOpts.Coroutines)
553
262
    Builder.defineMacro("__cpp_coroutines", "201703L");
554
26.3k
}
555
556
static void InitializePredefinedMacros(const TargetInfo &TI,
557
                                       const LangOptions &LangOpts,
558
                                       const FrontendOptions &FEOpts,
559
44.1k
                                       MacroBuilder &Builder) {
560
44.1k
  // Compiler version introspection macros.
561
44.1k
  Builder.defineMacro("__llvm__");  // LLVM Backend
562
44.1k
  Builder.defineMacro("__clang__"); // Clang Frontend
563
132k
#define TOSTR2(X) #X
564
132k
#define TOSTR(X) TOSTR2(X)
565
44.1k
  Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
566
44.1k
  Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
567
44.1k
  Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
568
44.1k
#undef TOSTR
569
44.1k
#undef TOSTR2
570
44.1k
  Builder.defineMacro("__clang_version__",
571
44.1k
                      "\"" CLANG_VERSION_STRING " "
572
44.1k
                      + getClangFullRepositoryVersion() + "\"");
573
44.1k
  if (!LangOpts.MSVCCompat) {
574
42.4k
    // Currently claim to be compatible with GCC 4.2.1-5621, but only if we're
575
42.4k
    // not compiling for MSVC compatibility
576
42.4k
    Builder.defineMacro("__GNUC_MINOR__", "2");
577
42.4k
    Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
578
42.4k
    Builder.defineMacro("__GNUC__", "4");
579
42.4k
    Builder.defineMacro("__GXX_ABI_VERSION", "1002");
580
42.4k
  }
581
44.1k
582
44.1k
  // Define macros for the C11 / C++11 memory orderings
583
44.1k
  Builder.defineMacro("__ATOMIC_RELAXED", "0");
584
44.1k
  Builder.defineMacro("__ATOMIC_CONSUME", "1");
585
44.1k
  Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
586
44.1k
  Builder.defineMacro("__ATOMIC_RELEASE", "3");
587
44.1k
  Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
588
44.1k
  Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
589
44.1k
590
44.1k
  // Define macros for the OpenCL memory scope.
591
44.1k
  // The values should match AtomicScopeOpenCLModel::ID enum.
592
44.1k
  static_assert(
593
44.1k
      static_cast<unsigned>(AtomicScopeOpenCLModel::WorkGroup) == 1 &&
594
44.1k
          static_cast<unsigned>(AtomicScopeOpenCLModel::Device) == 2 &&
595
44.1k
          static_cast<unsigned>(AtomicScopeOpenCLModel::AllSVMDevices) == 3 &&
596
44.1k
          static_cast<unsigned>(AtomicScopeOpenCLModel::SubGroup) == 4,
597
44.1k
      "Invalid OpenCL memory scope enum definition");
598
44.1k
  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0");
599
44.1k
  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1");
600
44.1k
  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2");
601
44.1k
  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3");
602
44.1k
  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4");
603
44.1k
604
44.1k
  // Support for #pragma redefine_extname (Sun compatibility)
605
44.1k
  Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
606
44.1k
607
44.1k
  // Previously this macro was set to a string aiming to achieve compatibility
608
44.1k
  // with GCC 4.2.1. Now, just return the full Clang version
609
44.1k
  Builder.defineMacro("__VERSION__", "\"" +
610
44.1k
                      Twine(getClangFullCPPVersion()) + "\"");
611
44.1k
612
44.1k
  // Initialize language-specific preprocessor defines.
613
44.1k
614
44.1k
  // Standard conforming mode?
615
44.1k
  if (!LangOpts.GNUMode && 
!LangOpts.MSVCCompat17.5k
)
616
15.9k
    Builder.defineMacro("__STRICT_ANSI__");
617
44.1k
618
44.1k
  if (!LangOpts.MSVCCompat && 
LangOpts.CPlusPlus1142.4k
)
619
22.3k
    Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
620
44.1k
621
44.1k
  if (LangOpts.ObjC) {
622
4.96k
    if (LangOpts.ObjCRuntime.isNonFragile()) {
623
4.65k
      Builder.defineMacro("__OBJC2__");
624
4.65k
625
4.65k
      if (LangOpts.ObjCExceptions)
626
1.62k
        Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
627
4.65k
    }
628
4.96k
629
4.96k
    if (LangOpts.getGC() != LangOptions::NonGC)
630
92
      Builder.defineMacro("__OBJC_GC__");
631
4.96k
632
4.96k
    if (LangOpts.ObjCRuntime.isNeXTFamily())
633
4.81k
      Builder.defineMacro("__NEXT_RUNTIME__");
634
4.96k
635
4.96k
    if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::GNUstep) {
636
92
      auto version = LangOpts.ObjCRuntime.getVersion();
637
92
      std::string versionString = "1";
638
92
      // Don't rely on the tuple argument, because we can be asked to target
639
92
      // later ABIs than we actually support, so clamp these values to those
640
92
      // currently supported
641
92
      if (version >= VersionTuple(2, 0))
642
10
        Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", "20");
643
82
      else
644
82
        Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__",
645
82
            "1" + Twine(std::min(8U, version.getMinor().getValueOr(0))));
646
92
    }
647
4.96k
648
4.96k
    if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
649
21
      VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
650
21
651
21
      unsigned minor = 0;
652
21
      if (tuple.getMinor().hasValue())
653
21
        minor = tuple.getMinor().getValue();
654
21
655
21
      unsigned subminor = 0;
656
21
      if (tuple.getSubminor().hasValue())
657
0
        subminor = tuple.getSubminor().getValue();
658
21
659
21
      Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
660
21
                          Twine(tuple.getMajor() * 10000 + minor * 100 +
661
21
                                subminor));
662
21
    }
663
4.96k
664
4.96k
    Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
665
4.96k
    Builder.defineMacro("IBOutletCollection(ClassName)",
666
4.96k
                        "__attribute__((iboutletcollection(ClassName)))");
667
4.96k
    Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
668
4.96k
    Builder.defineMacro("IBInspectable", "");
669
4.96k
    Builder.defineMacro("IB_DESIGNABLE", "");
670
4.96k
  }
671
44.1k
672
44.1k
  // Define a macro that describes the Objective-C boolean type even for C
673
44.1k
  // and C++ since BOOL can be used from non Objective-C code.
674
44.1k
  Builder.defineMacro("__OBJC_BOOL_IS_BOOL",
675
44.1k
                      Twine(TI.useSignedCharForObjCBool() ? 
"0"39.4k
:
"1"4.65k
));
676
44.1k
677
44.1k
  if (LangOpts.CPlusPlus)
678
26.3k
    InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
679
44.1k
680
44.1k
  // darwin_constant_cfstrings controls this. This is also dependent
681
44.1k
  // on other things like the runtime I believe.  This is set even for C code.
682
44.1k
  if (!LangOpts.NoConstantCFStrings)
683
44.1k
      Builder.defineMacro("__CONSTANT_CFSTRINGS__");
684
44.1k
685
44.1k
  if (LangOpts.ObjC)
686
4.96k
    Builder.defineMacro("OBJC_NEW_PROPERTIES");
687
44.1k
688
44.1k
  if (LangOpts.PascalStrings)
689
8
    Builder.defineMacro("__PASCAL_STRINGS__");
690
44.1k
691
44.1k
  if (LangOpts.Blocks) {
692
18.2k
    Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
693
18.2k
    Builder.defineMacro("__BLOCKS__");
694
18.2k
  }
695
44.1k
696
44.1k
  if (!LangOpts.MSVCCompat && 
LangOpts.Exceptions42.4k
)
697
9.55k
    Builder.defineMacro("__EXCEPTIONS");
698
44.1k
  if (!LangOpts.MSVCCompat && 
LangOpts.RTTI42.4k
)
699
22.7k
    Builder.defineMacro("__GXX_RTTI");
700
44.1k
701
44.1k
  if (LangOpts.SjLjExceptions)
702
1.38k
    Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
703
42.7k
  else if (LangOpts.SEHExceptions)
704
24
    Builder.defineMacro("__SEH__");
705
42.7k
  else if (LangOpts.DWARFExceptions &&
706
42.7k
          
(698
TI.getTriple().isThumb()698
||
TI.getTriple().isARM()25
))
707
678
    Builder.defineMacro("__ARM_DWARF_EH__");
708
44.1k
709
44.1k
  if (LangOpts.Deprecated)
710
10.7k
    Builder.defineMacro("__DEPRECATED");
711
44.1k
712
44.1k
  if (!LangOpts.MSVCCompat && 
LangOpts.CPlusPlus42.4k
) {
713
24.8k
    Builder.defineMacro("__GNUG__", "4");
714
24.8k
    Builder.defineMacro("__GXX_WEAK__");
715
24.8k
    Builder.defineMacro("__private_extern__", "extern");
716
24.8k
  }
717
44.1k
718
44.1k
  if (LangOpts.MicrosoftExt) {
719
2.32k
    if (LangOpts.WChar) {
720
1.92k
      // wchar_t supported as a keyword.
721
1.92k
      Builder.defineMacro("_WCHAR_T_DEFINED");
722
1.92k
      Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
723
1.92k
    }
724
2.32k
  }
725
44.1k
726
44.1k
  if (LangOpts.Optimize)
727
9.55k
    Builder.defineMacro("__OPTIMIZE__");
728
44.1k
  if (LangOpts.OptimizeSize)
729
1.61k
    Builder.defineMacro("__OPTIMIZE_SIZE__");
730
44.1k
731
44.1k
  if (LangOpts.FastMath)
732
14
    Builder.defineMacro("__FAST_MATH__");
733
44.1k
734
44.1k
  // Initialize target-specific preprocessor defines.
735
44.1k
736
44.1k
  // __BYTE_ORDER__ was added in GCC 4.6. It's analogous
737
44.1k
  // to the macro __BYTE_ORDER (no trailing underscores)
738
44.1k
  // from glibc's <endian.h> header.
739
44.1k
  // We don't support the PDP-11 as a target, but include
740
44.1k
  // the define so it can still be compared against.
741
44.1k
  Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
742
44.1k
  Builder.defineMacro("__ORDER_BIG_ENDIAN__",    "4321");
743
44.1k
  Builder.defineMacro("__ORDER_PDP_ENDIAN__",    "3412");
744
44.1k
  if (TI.isBigEndian()) {
745
549
    Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
746
549
    Builder.defineMacro("__BIG_ENDIAN__");
747
43.5k
  } else {
748
43.5k
    Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
749
43.5k
    Builder.defineMacro("__LITTLE_ENDIAN__");
750
43.5k
  }
751
44.1k
752
44.1k
  if (TI.getPointerWidth(0) == 64 && 
TI.getLongWidth() == 6433.6k
753
44.1k
      && 
TI.getIntWidth() == 3233.1k
) {
754
33.1k
    Builder.defineMacro("_LP64");
755
33.1k
    Builder.defineMacro("__LP64__");
756
33.1k
  }
757
44.1k
758
44.1k
  if (TI.getPointerWidth(0) == 32 && 
TI.getLongWidth() == 3210.4k
759
44.1k
      && 
TI.getIntWidth() == 3210.2k
) {
760
10.2k
    Builder.defineMacro("_ILP32");
761
10.2k
    Builder.defineMacro("__ILP32__");
762
10.2k
  }
763
44.1k
764
44.1k
  // Define type sizing macros based on the target properties.
765
44.1k
  assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
766
44.1k
  Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
767
44.1k
768
44.1k
  DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
769
44.1k
  DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
770
44.1k
  DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
771
44.1k
  DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
772
44.1k
  DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
773
44.1k
  DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
774
44.1k
  DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder);
775
44.1k
  DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
776
44.1k
  DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
777
44.1k
778
44.1k
  DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
779
44.1k
  DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
780
44.1k
  DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
781
44.1k
  DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
782
44.1k
783
44.1k
  DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
784
44.1k
  DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
785
44.1k
  DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
786
44.1k
  DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
787
44.1k
  DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
788
44.1k
  DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
789
44.1k
  DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
790
44.1k
  DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
791
44.1k
  DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
792
44.1k
                   TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
793
44.1k
  DefineTypeSizeof("__SIZEOF_SIZE_T__",
794
44.1k
                   TI.getTypeWidth(TI.getSizeType()), TI, Builder);
795
44.1k
  DefineTypeSizeof("__SIZEOF_WCHAR_T__",
796
44.1k
                   TI.getTypeWidth(TI.getWCharType()), TI, Builder);
797
44.1k
  DefineTypeSizeof("__SIZEOF_WINT_T__",
798
44.1k
                   TI.getTypeWidth(TI.getWIntType()), TI, Builder);
799
44.1k
  if (TI.hasInt128Type())
800
33.7k
    DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
801
44.1k
802
44.1k
  DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
803
44.1k
  DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
804
44.1k
  Builder.defineMacro("__INTMAX_C_SUFFIX__",
805
44.1k
                      TI.getTypeConstantSuffix(TI.getIntMaxType()));
806
44.1k
  DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
807
44.1k
  DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
808
44.1k
  Builder.defineMacro("__UINTMAX_C_SUFFIX__",
809
44.1k
                      TI.getTypeConstantSuffix(TI.getUIntMaxType()));
810
44.1k
  DefineTypeWidth("__INTMAX_WIDTH__",  TI.getIntMaxType(), TI, Builder);
811
44.1k
  DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
812
44.1k
  DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
813
44.1k
  DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
814
44.1k
  DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
815
44.1k
  DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
816
44.1k
  DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
817
44.1k
  DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
818
44.1k
  DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
819
44.1k
  DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
820
44.1k
  DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
821
44.1k
  DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
822
44.1k
  DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
823
44.1k
  DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
824
44.1k
  DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
825
44.1k
  DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
826
44.1k
  DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
827
44.1k
  DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
828
44.1k
829
44.1k
  DefineTypeWidth("__UINTMAX_WIDTH__",  TI.getUIntMaxType(), TI, Builder);
830
44.1k
  DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
831
44.1k
  DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
832
44.1k
  DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
833
44.1k
834
44.1k
  if (TI.hasFloat16Type())
835
7.79k
    DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
836
44.1k
  DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
837
44.1k
  DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
838
44.1k
  DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
839
44.1k
840
44.1k
  // Define a __POINTER_WIDTH__ macro for stdint.h.
841
44.1k
  Builder.defineMacro("__POINTER_WIDTH__",
842
44.1k
                      Twine((int)TI.getPointerWidth(0)));
843
44.1k
844
44.1k
  // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
845
44.1k
  Builder.defineMacro("__BIGGEST_ALIGNMENT__",
846
44.1k
                      Twine(TI.getSuitableAlign() / TI.getCharWidth()) );
847
44.1k
848
44.1k
  if (!LangOpts.CharIsSigned)
849
1.50k
    Builder.defineMacro("__CHAR_UNSIGNED__");
850
44.1k
851
44.1k
  if (!TargetInfo::isTypeSigned(TI.getWCharType()))
852
3.44k
    Builder.defineMacro("__WCHAR_UNSIGNED__");
853
44.1k
854
44.1k
  if (!TargetInfo::isTypeSigned(TI.getWIntType()))
855
3.72k
    Builder.defineMacro("__WINT_UNSIGNED__");
856
44.1k
857
44.1k
  // Define exact-width integer types for stdint.h
858
44.1k
  DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder);
859
44.1k
860
44.1k
  if (TI.getShortWidth() > TI.getCharWidth())
861
44.1k
    DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
862
44.1k
863
44.1k
  if (TI.getIntWidth() > TI.getShortWidth())
864
44.1k
    DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
865
44.1k
866
44.1k
  if (TI.getLongWidth() > TI.getIntWidth())
867
33.3k
    DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
868
44.1k
869
44.1k
  if (TI.getLongLongWidth() > TI.getLongWidth())
870
11.3k
    DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
871
44.1k
872
44.1k
  DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
873
44.1k
  DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
874
44.1k
  DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
875
44.1k
876
44.1k
  if (TI.getShortWidth() > TI.getCharWidth()) {
877
44.1k
    DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
878
44.1k
    DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
879
44.1k
    DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
880
44.1k
  }
881
44.1k
882
44.1k
  if (TI.getIntWidth() > TI.getShortWidth()) {
883
44.1k
    DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
884
44.1k
    DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
885
44.1k
    DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
886
44.1k
  }
887
44.1k
888
44.1k
  if (TI.getLongWidth() > TI.getIntWidth()) {
889
33.3k
    DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
890
33.3k
    DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
891
33.3k
    DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
892
33.3k
  }
893
44.1k
894
44.1k
  if (TI.getLongLongWidth() > TI.getLongWidth()) {
895
11.3k
    DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
896
11.3k
    DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
897
11.3k
    DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
898
11.3k
  }
899
44.1k
900
44.1k
  DefineLeastWidthIntType(8, true, TI, Builder);
901
44.1k
  DefineLeastWidthIntType(8, false, TI, Builder);
902
44.1k
  DefineLeastWidthIntType(16, true, TI, Builder);
903
44.1k
  DefineLeastWidthIntType(16, false, TI, Builder);
904
44.1k
  DefineLeastWidthIntType(32, true, TI, Builder);
905
44.1k
  DefineLeastWidthIntType(32, false, TI, Builder);
906
44.1k
  DefineLeastWidthIntType(64, true, TI, Builder);
907
44.1k
  DefineLeastWidthIntType(64, false, TI, Builder);
908
44.1k
909
44.1k
  DefineFastIntType(8, true, TI, Builder);
910
44.1k
  DefineFastIntType(8, false, TI, Builder);
911
44.1k
  DefineFastIntType(16, true, TI, Builder);
912
44.1k
  DefineFastIntType(16, false, TI, Builder);
913
44.1k
  DefineFastIntType(32, true, TI, Builder);
914
44.1k
  DefineFastIntType(32, false, TI, Builder);
915
44.1k
  DefineFastIntType(64, true, TI, Builder);
916
44.1k
  DefineFastIntType(64, false, TI, Builder);
917
44.1k
918
44.1k
  char UserLabelPrefix[2] = {TI.getDataLayout().getGlobalPrefix(), 0};
919
44.1k
  Builder.defineMacro("__USER_LABEL_PREFIX__", UserLabelPrefix);
920
44.1k
921
44.1k
  if (LangOpts.FastMath || 
LangOpts.FiniteMathOnly44.1k
)
922
17
    Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
923
44.1k
  else
924
44.1k
    Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
925
44.1k
926
44.1k
  if (!LangOpts.MSVCCompat) {
927
42.4k
    if (LangOpts.GNUInline || 
LangOpts.CPlusPlus42.2k
)
928
24.9k
      Builder.defineMacro("__GNUC_GNU_INLINE__");
929
17.4k
    else
930
17.4k
      Builder.defineMacro("__GNUC_STDC_INLINE__");
931
42.4k
932
42.4k
    // The value written by __atomic_test_and_set.
933
42.4k
    // FIXME: This is target-dependent.
934
42.4k
    Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
935
42.4k
  }
936
44.1k
937
86.5k
  auto addLockFreeMacros = [&](const llvm::Twine &Prefix) {
938
86.5k
    // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
939
86.5k
    unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
940
86.5k
#define DEFINE_LOCK_FREE_MACRO(TYPE, Type)                                     \
941
86.5k
  Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE",                             \
942
451
                      getLockFreeValue(TI.get##Type##Width(),                  \
943
451
                                       TI.get##Type##Align(),                  \
944
451
                                       InlineWidthBits));
945
86.5k
    DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
946
86.5k
    DEFINE_LOCK_FREE_MACRO(CHAR, Char);
947
86.5k
    if (LangOpts.Char8)
948
86.5k
      
DEFINE_LOCK_FREE_MACRO451
(CHAR8_T, Char); // Treat char8_t like char.
949
86.5k
    DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
950
86.5k
    DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
951
86.5k
    DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
952
86.5k
    DEFINE_LOCK_FREE_MACRO(SHORT, Short);
953
86.5k
    DEFINE_LOCK_FREE_MACRO(INT, Int);
954
86.5k
    DEFINE_LOCK_FREE_MACRO(LONG, Long);
955
86.5k
    DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
956
86.5k
    Builder.defineMacro(Prefix + "POINTER_LOCK_FREE",
957
86.5k
                        getLockFreeValue(TI.getPointerWidth(0),
958
86.5k
                                         TI.getPointerAlign(0),
959
86.5k
                                         InlineWidthBits));
960
86.5k
#undef DEFINE_LOCK_FREE_MACRO
961
86.5k
  };
962
44.1k
  addLockFreeMacros("__CLANG_ATOMIC_");
963
44.1k
  if (!LangOpts.MSVCCompat)
964
42.4k
    addLockFreeMacros("__GCC_ATOMIC_");
965
44.1k
966
44.1k
  if (LangOpts.NoInlineDefine)
967
34.5k
    Builder.defineMacro("__NO_INLINE__");
968
44.1k
969
44.1k
  if (unsigned PICLevel = LangOpts.PICLevel) {
970
15.8k
    Builder.defineMacro("__PIC__", Twine(PICLevel));
971
15.8k
    Builder.defineMacro("__pic__", Twine(PICLevel));
972
15.8k
    if (LangOpts.PIE) {
973
20
      Builder.defineMacro("__PIE__", Twine(PICLevel));
974
20
      Builder.defineMacro("__pie__", Twine(PICLevel));
975
20
    }
976
15.8k
  }
977
44.1k
978
44.1k
  // Macros to control C99 numerics and <float.h>
979
44.1k
  Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
980
44.1k
  Builder.defineMacro("__FLT_RADIX__", "2");
981
44.1k
  Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
982
44.1k
983
44.1k
  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
984
13.4k
    Builder.defineMacro("__SSP__");
985
30.6k
  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
986
52
    Builder.defineMacro("__SSP_STRONG__", "2");
987
30.5k
  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
988
2
    Builder.defineMacro("__SSP_ALL__", "3");
989
44.1k
990
44.1k
  // Define a macro that exists only when using the static analyzer.
991
44.1k
  if (FEOpts.ProgramAction == frontend::RunAnalysis)
992
908
    Builder.defineMacro("__clang_analyzer__");
993
44.1k
994
44.1k
  if (LangOpts.FastRelaxedMath)
995
2
    Builder.defineMacro("__FAST_RELAXED_MATH__");
996
44.1k
997
44.1k
  if (FEOpts.ProgramAction == frontend::RewriteObjC ||
998
44.1k
      
LangOpts.getGC() != LangOptions::NonGC43.9k
) {
999
255
    Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
1000
255
    Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
1001
255
    Builder.defineMacro("__autoreleasing", "");
1002
255
    Builder.defineMacro("__unsafe_unretained", "");
1003
43.8k
  } else if (LangOpts.ObjC) {
1004
4.70k
    Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
1005
4.70k
    Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
1006
4.70k
    Builder.defineMacro("__autoreleasing",
1007
4.70k
                        "__attribute__((objc_ownership(autoreleasing)))");
1008
4.70k
    Builder.defineMacro("__unsafe_unretained",
1009
4.70k
                        "__attribute__((objc_ownership(none)))");
1010
4.70k
  }
1011
44.1k
1012
44.1k
  // On Darwin, there are __double_underscored variants of the type
1013
44.1k
  // nullability qualifiers.
1014
44.1k
  if (TI.getTriple().isOSDarwin()) {
1015
30.9k
    Builder.defineMacro("__nonnull", "_Nonnull");
1016
30.9k
    Builder.defineMacro("__null_unspecified", "_Null_unspecified");
1017
30.9k
    Builder.defineMacro("__nullable", "_Nullable");
1018
30.9k
  }
1019
44.1k
1020
44.1k
  // Add a macro to differentiate between regular iOS/tvOS/watchOS targets and
1021
44.1k
  // the corresponding simulator targets.
1022
44.1k
  if (TI.getTriple().isOSDarwin() && 
TI.getTriple().isSimulatorEnvironment()30.9k
)
1023
883
    Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1");
1024
44.1k
1025
44.1k
  // OpenMP definition
1026
44.1k
  // OpenMP 2.2:
1027
44.1k
  //   In implementations that support a preprocessor, the _OPENMP
1028
44.1k
  //   macro name is defined to have the decimal value yyyymm where
1029
44.1k
  //   yyyy and mm are the year and the month designations of the
1030
44.1k
  //   version of the OpenMP API that the implementation support.
1031
44.1k
  if (!LangOpts.OpenMPSimd) {
1032
40.9k
    switch (LangOpts.OpenMP) {
1033
40.9k
    case 0:
1034
37.1k
      break;
1035
40.9k
    case 40:
1036
2
      Builder.defineMacro("_OPENMP", "201307");
1037
2
      break;
1038
40.9k
    case 45:
1039
2.27k
      Builder.defineMacro("_OPENMP", "201511");
1040
2.27k
      break;
1041
40.9k
    default:
1042
1.42k
      // Default version is OpenMP 3.1
1043
1.42k
      Builder.defineMacro("_OPENMP", "201107");
1044
1.42k
      break;
1045
44.1k
    }
1046
44.1k
  }
1047
44.1k
1048
44.1k
  // CUDA device path compilaton
1049
44.1k
  if (LangOpts.CUDAIsDevice && 
!LangOpts.HIP164
) {
1050
156
    // The CUDA_ARCH value is set for the GPU target specified in the NVPTX
1051
156
    // backend's target defines.
1052
156
    Builder.defineMacro("__CUDA_ARCH__");
1053
156
  }
1054
44.1k
1055
44.1k
  // We need to communicate this to our CUDA header wrapper, which in turn
1056
44.1k
  // informs the proper CUDA headers of this choice.
1057
44.1k
  if (LangOpts.CUDADeviceApproxTranscendentals || 
LangOpts.FastMath44.1k
) {
1058
16
    Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
1059
16
  }
1060
44.1k
1061
44.1k
  // Define a macro indicating that the source file is being compiled with a
1062
44.1k
  // SYCL device compiler which doesn't produce host binary.
1063
44.1k
  if (LangOpts.SYCLIsDevice) {
1064
1
    Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
1065
1
  }
1066
44.1k
1067
44.1k
  // OpenCL definitions.
1068
44.1k
  if (LangOpts.OpenCL) {
1069
610
#define OPENCLEXT(Ext)                                                         \
1070
25.0k
  if (TI.getSupportedOpenCLOpts().isSupported(#Ext, LangOpts))                 \
1071
25.0k
    
Builder.defineMacro(#Ext)13.3k
;
1072
610
#include "clang/Basic/OpenCLExtensions.def"
1073
610
1074
610
    if (TI.getTriple().isSPIR())
1075
158
      Builder.defineMacro("__IMAGE_SUPPORT__");
1076
610
  }
1077
44.1k
1078
44.1k
  if (TI.hasInt128Type() && 
LangOpts.CPlusPlus33.7k
&&
LangOpts.GNUMode20.7k
) {
1079
8.56k
    // For each extended integer type, g++ defines a macro mapping the
1080
8.56k
    // index of the type (0 in this case) in some list of extended types
1081
8.56k
    // to the type.
1082
8.56k
    Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128");
1083
8.56k
    Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
1084
8.56k
  }
1085
44.1k
1086
44.1k
  // Get other target #defines.
1087
44.1k
  TI.getTargetDefines(LangOpts, Builder);
1088
44.1k
}
1089
1090
/// InitializePreprocessor - Initialize the preprocessor getting it and the
1091
/// environment ready to process a single file. This returns true on error.
1092
///
1093
void clang::InitializePreprocessor(
1094
    Preprocessor &PP, const PreprocessorOptions &InitOpts,
1095
    const PCHContainerReader &PCHContainerRdr,
1096
44.0k
    const FrontendOptions &FEOpts) {
1097
44.0k
  const LangOptions &LangOpts = PP.getLangOpts();
1098
44.0k
  std::string PredefineBuffer;
1099
44.0k
  PredefineBuffer.reserve(4080);
1100
44.0k
  llvm::raw_string_ostream Predefines(PredefineBuffer);
1101
44.0k
  MacroBuilder Builder(Predefines);
1102
44.0k
1103
44.0k
  // Emit line markers for various builtin sections of the file.  We don't do
1104
44.0k
  // this in asm preprocessor mode, because "# 4" is not a line marker directive
1105
44.0k
  // in this mode.
1106
44.0k
  if (!PP.getLangOpts().AsmPreprocessor)
1107
43.3k
    Builder.append("# 1 \"<built-in>\" 3");
1108
44.0k
1109
44.0k
  // Install things like __POWERPC__, __GNUC__, etc into the macro table.
1110
44.0k
  if (InitOpts.UsePredefines) {
1111
44.0k
    // FIXME: This will create multiple definitions for most of the predefined
1112
44.0k
    // macros. This is not the right way to handle this.
1113
44.0k
    if ((LangOpts.CUDA || 
LangOpts.OpenMPIsDevice43.8k
) &&
PP.getAuxTargetInfo()714
)
1114
65
      InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
1115
65
                                 Builder);
1116
44.0k
1117
44.0k
    InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder);
1118
44.0k
1119
44.0k
    // Install definitions to make Objective-C++ ARC work well with various
1120
44.0k
    // C++ Standard Library implementations.
1121
44.0k
    if (LangOpts.ObjC && 
LangOpts.CPlusPlus4.96k
&&
1122
44.0k
        
(1.00k
LangOpts.ObjCAutoRefCount1.00k
||
LangOpts.ObjCWeak883
)) {
1123
131
      switch (InitOpts.ObjCXXARCStandardLibrary) {
1124
131
      case ARCXX_nolib:
1125
130
      case ARCXX_libcxx:
1126
130
        break;
1127
130
1128
130
      case ARCXX_libstdcxx:
1129
1
        AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
1130
1
        break;
1131
44.0k
      }
1132
44.0k
    }
1133
44.0k
  }
1134
44.0k
1135
44.0k
  // Even with predefines off, some macros are still predefined.
1136
44.0k
  // These should all be defined in the preprocessor according to the
1137
44.0k
  // current language configuration.
1138
44.0k
  InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
1139
44.0k
                                     FEOpts, Builder);
1140
44.0k
1141
44.0k
  // Add on the predefines from the driver.  Wrap in a #line directive to report
1142
44.0k
  // that they come from the command line.
1143
44.0k
  if (!PP.getLangOpts().AsmPreprocessor)
1144
43.3k
    Builder.append("# 1 \"<command line>\" 1");
1145
44.0k
1146
44.0k
  // Process #define's and #undef's in the order they are given.
1147
374k
  for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; 
++i330k
) {
1148
330k
    if (InitOpts.Macros[i].second)  // isUndef
1149
62
      Builder.undefineMacro(InitOpts.Macros[i].first);
1150
329k
    else
1151
329k
      DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
1152
329k
                         PP.getDiagnostics());
1153
330k
  }
1154
44.0k
1155
44.0k
  // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
1156
44.0k
  if (!PP.getLangOpts().AsmPreprocessor)
1157
43.3k
    Builder.append("# 1 \"<built-in>\" 2");
1158
44.0k
1159
44.0k
  // If -imacros are specified, include them now.  These are processed before
1160
44.0k
  // any -include directives.
1161
44.0k
  for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; 
++i2
)
1162
2
    AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
1163
44.0k
1164
44.0k
  // Process -include-pch/-include-pth directives.
1165
44.0k
  if (!InitOpts.ImplicitPCHInclude.empty())
1166
2.36k
    AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
1167
2.36k
                          InitOpts.ImplicitPCHInclude);
1168
44.0k
1169
44.0k
  // Process -include directives.
1170
44.3k
  for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; 
++i288
) {
1171
288
    const std::string &Path = InitOpts.Includes[i];
1172
288
    AddImplicitInclude(Builder, Path);
1173
288
  }
1174
44.0k
1175
44.0k
  // Instruct the preprocessor to skip the preamble.
1176
44.0k
  PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
1177
44.0k
                             InitOpts.PrecompiledPreambleBytes.second);
1178
44.0k
1179
44.0k
  // Copy PredefinedBuffer into the Preprocessor.
1180
44.0k
  PP.setPredefines(Predefines.str());
1181
44.0k
}