clang  14.0.0git
InitPreprocessor.cpp
Go to the documentation of this file.
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 
16 #include "clang/Basic/SyncScope.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/Version.h"
21 #include "clang/Frontend/Utils.h"
22 #include "clang/Lex/HeaderSearch.h"
23 #include "clang/Lex/Preprocessor.h"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/IR/DataLayout.h"
28 using namespace clang;
29 
30 static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
31  while (!MacroBody.empty() && isWhitespace(MacroBody.back()))
32  MacroBody = MacroBody.drop_back();
33  return !MacroBody.empty() && MacroBody.back() == '\\';
34 }
35 
36 // Append a #define line to Buf for Macro. Macro should be of the form XXX,
37 // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
38 // "#define XXX Y z W". To get a #define with no value, use "XXX=".
39 static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
40  DiagnosticsEngine &Diags) {
41  std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
42  StringRef MacroName = MacroPair.first;
43  StringRef MacroBody = MacroPair.second;
44  if (MacroName.size() != Macro.size()) {
45  // Per GCC -D semantics, the macro ends at \n if it exists.
46  StringRef::size_type End = MacroBody.find_first_of("\n\r");
47  if (End != StringRef::npos)
48  Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
49  << MacroName;
50  MacroBody = MacroBody.substr(0, End);
51  // We handle macro bodies which end in a backslash by appending an extra
52  // backslash+newline. This makes sure we don't accidentally treat the
53  // backslash as a line continuation marker.
54  if (MacroBodyEndsInBackslash(MacroBody))
55  Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
56  else
57  Builder.defineMacro(MacroName, MacroBody);
58  } else {
59  // Push "macroname 1".
60  Builder.defineMacro(Macro);
61  }
62 }
63 
64 /// AddImplicitInclude - Add an implicit \#include of the specified file to the
65 /// predefines buffer.
66 /// As these includes are generated by -include arguments the header search
67 /// logic is going to search relatively to the current working directory.
68 static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
69  Builder.append(Twine("#include \"") + File + "\"");
70 }
71 
72 static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
73  Builder.append(Twine("#__include_macros \"") + File + "\"");
74  // Marker token to stop the __include_macros fetch loop.
75  Builder.append("##"); // ##?
76 }
77 
78 /// Add an implicit \#include using the original file used to generate
79 /// a PCH file.
81  const PCHContainerReader &PCHContainerRdr,
82  StringRef ImplicitIncludePCH) {
84  std::string(ImplicitIncludePCH), PP.getFileManager(), PCHContainerRdr,
85  PP.getDiagnostics());
86  if (OriginalFile.empty())
87  return;
88 
89  AddImplicitInclude(Builder, OriginalFile);
90 }
91 
92 /// PickFP - This is used to pick a value based on the FP semantics of the
93 /// specified FP model.
94 template <typename T>
95 static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
96  T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
97  T IEEEQuadVal) {
98  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
99  return IEEEHalfVal;
100  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
101  return IEEESingleVal;
102  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
103  return IEEEDoubleVal;
104  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended())
105  return X87DoubleExtendedVal;
106  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble())
107  return PPCDoubleDoubleVal;
108  assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad());
109  return IEEEQuadVal;
110 }
111 
112 static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
113  const llvm::fltSemantics *Sem, StringRef Ext) {
114  const char *DenormMin, *Epsilon, *Max, *Min;
115  DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45",
116  "4.9406564584124654e-324", "3.64519953188247460253e-4951",
117  "4.94065645841246544176568792868221e-324",
118  "6.47517511943802511092443895822764655e-4966");
119  int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33);
120  int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36);
121  Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7",
122  "2.2204460492503131e-16", "1.08420217248550443401e-19",
123  "4.94065645841246544176568792868221e-324",
124  "1.92592994438723585305597794258492732e-34");
125  int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113);
126  int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931);
127  int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932);
128  int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381);
129  int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384);
130  Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308",
131  "3.36210314311209350626e-4932",
132  "2.00416836000897277799610805135016e-292",
133  "3.36210314311209350626267781732175260e-4932");
134  Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308",
135  "1.18973149535723176502e+4932",
136  "1.79769313486231580793728971405301e+308",
137  "1.18973149535723176508575932662800702e+4932");
138 
139  SmallString<32> DefPrefix;
140  DefPrefix = "__";
141  DefPrefix += Prefix;
142  DefPrefix += "_";
143 
144  Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
145  Builder.defineMacro(DefPrefix + "HAS_DENORM__");
146  Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
147  Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits));
148  Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext);
149  Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
150  Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
151  Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits));
152 
153  Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp));
154  Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp));
155  Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext);
156 
157  Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")");
158  Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")");
159  Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext);
160 }
161 
162 
163 /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
164 /// named MacroName with the max value for a type with width 'TypeWidth' a
165 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
166 static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
167  StringRef ValSuffix, bool isSigned,
168  MacroBuilder &Builder) {
169  llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
170  : llvm::APInt::getMaxValue(TypeWidth);
171  Builder.defineMacro(MacroName, toString(MaxVal, 10, isSigned) + ValSuffix);
172 }
173 
174 /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
175 /// the width, suffix, and signedness of the given type
176 static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
177  const TargetInfo &TI, MacroBuilder &Builder) {
178  DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty),
179  TI.isTypeSigned(Ty), Builder);
180 }
181 
182 static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty,
183  const TargetInfo &TI, MacroBuilder &Builder) {
184  bool IsSigned = TI.isTypeSigned(Ty);
185  StringRef FmtModifier = TI.getTypeFormatModifier(Ty);
186  for (const char *Fmt = IsSigned ? "di" : "ouxX"; *Fmt; ++Fmt) {
187  Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__",
188  Twine("\"") + FmtModifier + Twine(*Fmt) + "\"");
189  }
190 }
191 
192 static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
193  MacroBuilder &Builder) {
194  Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
195 }
196 
197 static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
198  const TargetInfo &TI, MacroBuilder &Builder) {
199  Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
200 }
201 
202 static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
203  const TargetInfo &TI, MacroBuilder &Builder) {
204  Builder.defineMacro(MacroName,
205  Twine(BitWidth / TI.getCharWidth()));
206 }
207 
209  const TargetInfo &TI,
210  MacroBuilder &Builder) {
211  int TypeWidth = TI.getTypeWidth(Ty);
212  bool IsSigned = TI.isTypeSigned(Ty);
213 
214  // Use the target specified int64 type, when appropriate, so that [u]int64_t
215  // ends up being defined in terms of the correct type.
216  if (TypeWidth == 64)
217  Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
218 
219  // Use the target specified int16 type when appropriate. Some MCU targets
220  // (such as AVR) have definition of [u]int16_t to [un]signed int.
221  if (TypeWidth == 16)
222  Ty = IsSigned ? TI.getInt16Type() : TI.getUInt16Type();
223 
224  const char *Prefix = IsSigned ? "__INT" : "__UINT";
225 
226  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
227  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
228 
229  StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
230  Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
231 }
232 
234  const TargetInfo &TI,
235  MacroBuilder &Builder) {
236  int TypeWidth = TI.getTypeWidth(Ty);
237  bool IsSigned = TI.isTypeSigned(Ty);
238 
239  // Use the target specified int64 type, when appropriate, so that [u]int64_t
240  // ends up being defined in terms of the correct type.
241  if (TypeWidth == 64)
242  Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
243 
244  const char *Prefix = IsSigned ? "__INT" : "__UINT";
245  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
246 }
247 
248 static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
249  const TargetInfo &TI,
250  MacroBuilder &Builder) {
251  TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
252  if (Ty == TargetInfo::NoInt)
253  return;
254 
255  const char *Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
256  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
257  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
258  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
259 }
260 
261 static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
262  const TargetInfo &TI, MacroBuilder &Builder) {
263  // stdint.h currently defines the fast int types as equivalent to the least
264  // types.
265  TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
266  if (Ty == TargetInfo::NoInt)
267  return;
268 
269  const char *Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
270  DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
271  DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
272 
273  DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
274 }
275 
276 
277 /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
278 /// the specified properties.
279 static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
280  unsigned InlineWidth) {
281  // Fully-aligned, power-of-2 sizes no larger than the inline
282  // width will be inlined as lock-free operations.
283  if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
284  TypeWidth <= InlineWidth)
285  return "2"; // "always lock free"
286  // We cannot be certain what operations the lib calls might be
287  // able to implement as lock-free on future processors.
288  return "1"; // "sometimes lock free"
289 }
290 
291 /// Add definitions required for a smooth interaction between
292 /// Objective-C++ automated reference counting and libstdc++ (4.2).
293 static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts,
294  MacroBuilder &Builder) {
295  Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
296 
297  std::string Result;
298  {
299  // Provide specializations for the __is_scalar type trait so that
300  // lifetime-qualified objects are not considered "scalar" types, which
301  // libstdc++ uses as an indicator of the presence of trivial copy, assign,
302  // default-construct, and destruct semantics (none of which hold for
303  // lifetime-qualified objects in ARC).
304  llvm::raw_string_ostream Out(Result);
305 
306  Out << "namespace std {\n"
307  << "\n"
308  << "struct __true_type;\n"
309  << "struct __false_type;\n"
310  << "\n";
311 
312  Out << "template<typename _Tp> struct __is_scalar;\n"
313  << "\n";
314 
315  if (LangOpts.ObjCAutoRefCount) {
316  Out << "template<typename _Tp>\n"
317  << "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
318  << " enum { __value = 0 };\n"
319  << " typedef __false_type __type;\n"
320  << "};\n"
321  << "\n";
322  }
323 
324  if (LangOpts.ObjCWeak) {
325  Out << "template<typename _Tp>\n"
326  << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
327  << " enum { __value = 0 };\n"
328  << " typedef __false_type __type;\n"
329  << "};\n"
330  << "\n";
331  }
332 
333  if (LangOpts.ObjCAutoRefCount) {
334  Out << "template<typename _Tp>\n"
335  << "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
336  << " _Tp> {\n"
337  << " enum { __value = 0 };\n"
338  << " typedef __false_type __type;\n"
339  << "};\n"
340  << "\n";
341  }
342 
343  Out << "}\n";
344  }
345  Builder.append(Result);
346 }
347 
349  const LangOptions &LangOpts,
350  const FrontendOptions &FEOpts,
351  MacroBuilder &Builder) {
352  // C++ [cpp.predefined]p1:
353  // The following macro names shall be defined by the implementation:
354 
355  // -- __STDC__
356  // [C++] Whether __STDC__ is predefined and if so, what its value is,
357  // are implementation-defined.
358  // (Removed in C++20.)
359  if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP)
360  Builder.defineMacro("__STDC__");
361  // -- __STDC_HOSTED__
362  // The integer literal 1 if the implementation is a hosted
363  // implementation or the integer literal 0 if it is not.
364  if (LangOpts.Freestanding)
365  Builder.defineMacro("__STDC_HOSTED__", "0");
366  else
367  Builder.defineMacro("__STDC_HOSTED__");
368 
369  // -- __STDC_VERSION__
370  // [C++] Whether __STDC_VERSION__ is predefined and if so, what its
371  // value is, are implementation-defined.
372  // (Removed in C++20.)
373  if (!LangOpts.CPlusPlus) {
374  // FIXME: Use correct value for C23.
375  if (LangOpts.C2x)
376  Builder.defineMacro("__STDC_VERSION__", "202000L");
377  else if (LangOpts.C17)
378  Builder.defineMacro("__STDC_VERSION__", "201710L");
379  else if (LangOpts.C11)
380  Builder.defineMacro("__STDC_VERSION__", "201112L");
381  else if (LangOpts.C99)
382  Builder.defineMacro("__STDC_VERSION__", "199901L");
383  else if (!LangOpts.GNUMode && LangOpts.Digraphs)
384  Builder.defineMacro("__STDC_VERSION__", "199409L");
385  } else {
386  // -- __cplusplus
387  // FIXME: Use correct value for C++23.
388  if (LangOpts.CPlusPlus2b)
389  Builder.defineMacro("__cplusplus", "202101L");
390  // [C++20] The integer literal 202002L.
391  else if (LangOpts.CPlusPlus20)
392  Builder.defineMacro("__cplusplus", "202002L");
393  // [C++17] The integer literal 201703L.
394  else if (LangOpts.CPlusPlus17)
395  Builder.defineMacro("__cplusplus", "201703L");
396  // [C++14] The name __cplusplus is defined to the value 201402L when
397  // compiling a C++ translation unit.
398  else if (LangOpts.CPlusPlus14)
399  Builder.defineMacro("__cplusplus", "201402L");
400  // [C++11] The name __cplusplus is defined to the value 201103L when
401  // compiling a C++ translation unit.
402  else if (LangOpts.CPlusPlus11)
403  Builder.defineMacro("__cplusplus", "201103L");
404  // [C++03] The name __cplusplus is defined to the value 199711L when
405  // compiling a C++ translation unit.
406  else
407  Builder.defineMacro("__cplusplus", "199711L");
408 
409  // -- __STDCPP_DEFAULT_NEW_ALIGNMENT__
410  // [C++17] An integer literal of type std::size_t whose value is the
411  // alignment guaranteed by a call to operator new(std::size_t)
412  //
413  // We provide this in all language modes, since it seems generally useful.
414  Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__",
415  Twine(TI.getNewAlign() / TI.getCharWidth()) +
417 
418  // -- __STDCPP_­THREADS__
419  // Defined, and has the value integer literal 1, if and only if a
420  // program can have more than one thread of execution.
421  if (LangOpts.getThreadModel() == LangOptions::ThreadModelKind::POSIX)
422  Builder.defineMacro("__STDCPP_THREADS__", "1");
423  }
424 
425  // In C11 these are environment macros. In C++11 they are only defined
426  // as part of <cuchar>. To prevent breakage when mixing C and C++
427  // code, define these macros unconditionally. We can define them
428  // unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
429  // and 32-bit character literals.
430  Builder.defineMacro("__STDC_UTF_16__", "1");
431  Builder.defineMacro("__STDC_UTF_32__", "1");
432 
433  if (LangOpts.ObjC)
434  Builder.defineMacro("__OBJC__");
435 
436  // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros.
437  if (LangOpts.OpenCL) {
438  if (LangOpts.CPlusPlus) {
439  switch (LangOpts.OpenCLCPlusPlusVersion) {
440  case 100:
441  Builder.defineMacro("__OPENCL_CPP_VERSION__", "100");
442  break;
443  case 202100:
444  Builder.defineMacro("__OPENCL_CPP_VERSION__", "202100");
445  break;
446  default:
447  llvm_unreachable("Unsupported C++ version for OpenCL");
448  }
449  Builder.defineMacro("__CL_CPP_VERSION_1_0__", "100");
450  Builder.defineMacro("__CL_CPP_VERSION_2021__", "202100");
451  } else {
452  // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
453  // language standard with which the program is compiled. __OPENCL_VERSION__
454  // is for the OpenCL version supported by the OpenCL device, which is not
455  // necessarily the language standard with which the program is compiled.
456  // A shared OpenCL header file requires a macro to indicate the language
457  // standard. As a workaround, __OPENCL_C_VERSION__ is defined for
458  // OpenCL v1.0 and v1.1.
459  switch (LangOpts.OpenCLVersion) {
460  case 100:
461  Builder.defineMacro("__OPENCL_C_VERSION__", "100");
462  break;
463  case 110:
464  Builder.defineMacro("__OPENCL_C_VERSION__", "110");
465  break;
466  case 120:
467  Builder.defineMacro("__OPENCL_C_VERSION__", "120");
468  break;
469  case 200:
470  Builder.defineMacro("__OPENCL_C_VERSION__", "200");
471  break;
472  case 300:
473  Builder.defineMacro("__OPENCL_C_VERSION__", "300");
474  break;
475  default:
476  llvm_unreachable("Unsupported OpenCL version");
477  }
478  }
479  Builder.defineMacro("CL_VERSION_1_0", "100");
480  Builder.defineMacro("CL_VERSION_1_1", "110");
481  Builder.defineMacro("CL_VERSION_1_2", "120");
482  Builder.defineMacro("CL_VERSION_2_0", "200");
483  Builder.defineMacro("CL_VERSION_3_0", "300");
484 
485  if (TI.isLittleEndian())
486  Builder.defineMacro("__ENDIAN_LITTLE__");
487 
488  if (LangOpts.FastRelaxedMath)
489  Builder.defineMacro("__FAST_RELAXED_MATH__");
490  }
491 
492  if (LangOpts.SYCLIsDevice || LangOpts.SYCLIsHost) {
493  // SYCL Version is set to a value when building SYCL applications
494  if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
495  Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
496  else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
497  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
498  }
499 
500  // Not "standard" per se, but available even with the -undef flag.
501  if (LangOpts.AsmPreprocessor)
502  Builder.defineMacro("__ASSEMBLER__");
503  if (LangOpts.CUDA && !LangOpts.HIP)
504  Builder.defineMacro("__CUDA__");
505  if (LangOpts.HIP) {
506  Builder.defineMacro("__HIP__");
507  Builder.defineMacro("__HIPCC__");
508  if (LangOpts.CUDAIsDevice)
509  Builder.defineMacro("__HIP_DEVICE_COMPILE__");
510  }
511 }
512 
513 /// Initialize the predefined C++ language feature test macros defined in
514 /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
516  MacroBuilder &Builder) {
517  // C++98 features.
518  if (LangOpts.RTTI)
519  Builder.defineMacro("__cpp_rtti", "199711L");
520  if (LangOpts.CXXExceptions)
521  Builder.defineMacro("__cpp_exceptions", "199711L");
522 
523  // C++11 features.
524  if (LangOpts.CPlusPlus11) {
525  Builder.defineMacro("__cpp_unicode_characters", "200704L");
526  Builder.defineMacro("__cpp_raw_strings", "200710L");
527  Builder.defineMacro("__cpp_unicode_literals", "200710L");
528  Builder.defineMacro("__cpp_user_defined_literals", "200809L");
529  Builder.defineMacro("__cpp_lambdas", "200907L");
530  Builder.defineMacro("__cpp_constexpr",
531  LangOpts.CPlusPlus20 ? "201907L" :
532  LangOpts.CPlusPlus17 ? "201603L" :
533  LangOpts.CPlusPlus14 ? "201304L" : "200704");
534  Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L");
535  Builder.defineMacro("__cpp_range_based_for",
536  LangOpts.CPlusPlus17 ? "201603L" : "200907");
537  Builder.defineMacro("__cpp_static_assert",
538  LangOpts.CPlusPlus17 ? "201411L" : "200410");
539  Builder.defineMacro("__cpp_decltype", "200707L");
540  Builder.defineMacro("__cpp_attributes", "200809L");
541  Builder.defineMacro("__cpp_rvalue_references", "200610L");
542  Builder.defineMacro("__cpp_variadic_templates", "200704L");
543  Builder.defineMacro("__cpp_initializer_lists", "200806L");
544  Builder.defineMacro("__cpp_delegating_constructors", "200604L");
545  Builder.defineMacro("__cpp_nsdmi", "200809L");
546  Builder.defineMacro("__cpp_inheriting_constructors", "201511L");
547  Builder.defineMacro("__cpp_ref_qualifiers", "200710L");
548  Builder.defineMacro("__cpp_alias_templates", "200704L");
549  }
550  if (LangOpts.ThreadsafeStatics)
551  Builder.defineMacro("__cpp_threadsafe_static_init", "200806L");
552 
553  // C++14 features.
554  if (LangOpts.CPlusPlus14) {
555  Builder.defineMacro("__cpp_binary_literals", "201304L");
556  Builder.defineMacro("__cpp_digit_separators", "201309L");
557  Builder.defineMacro("__cpp_init_captures",
558  LangOpts.CPlusPlus20 ? "201803L" : "201304L");
559  Builder.defineMacro("__cpp_generic_lambdas",
560  LangOpts.CPlusPlus20 ? "201707L" : "201304L");
561  Builder.defineMacro("__cpp_decltype_auto", "201304L");
562  Builder.defineMacro("__cpp_return_type_deduction", "201304L");
563  Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L");
564  Builder.defineMacro("__cpp_variable_templates", "201304L");
565  }
566  if (LangOpts.SizedDeallocation)
567  Builder.defineMacro("__cpp_sized_deallocation", "201309L");
568 
569  // C++17 features.
570  if (LangOpts.CPlusPlus17) {
571  Builder.defineMacro("__cpp_hex_float", "201603L");
572  Builder.defineMacro("__cpp_inline_variables", "201606L");
573  Builder.defineMacro("__cpp_noexcept_function_type", "201510L");
574  Builder.defineMacro("__cpp_capture_star_this", "201603L");
575  Builder.defineMacro("__cpp_if_constexpr", "201606L");
576  Builder.defineMacro("__cpp_deduction_guides", "201703L"); // (not latest)
577  Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name)
578  Builder.defineMacro("__cpp_namespace_attributes", "201411L");
579  Builder.defineMacro("__cpp_enumerator_attributes", "201411L");
580  Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L");
581  Builder.defineMacro("__cpp_variadic_using", "201611L");
582  Builder.defineMacro("__cpp_aggregate_bases", "201603L");
583  Builder.defineMacro("__cpp_structured_bindings", "201606L");
584  Builder.defineMacro("__cpp_nontype_template_args",
585  "201411L"); // (not latest)
586  Builder.defineMacro("__cpp_fold_expressions", "201603L");
587  Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L");
588  Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L");
589  }
590  if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable)
591  Builder.defineMacro("__cpp_aligned_new", "201606L");
592  if (LangOpts.RelaxedTemplateTemplateArgs)
593  Builder.defineMacro("__cpp_template_template_args", "201611L");
594 
595  // C++20 features.
596  if (LangOpts.CPlusPlus20) {
597  //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
598  Builder.defineMacro("__cpp_concepts", "201907L");
599  Builder.defineMacro("__cpp_conditional_explicit", "201806L");
600  //Builder.defineMacro("__cpp_consteval", "201811L");
601  Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L");
602  Builder.defineMacro("__cpp_constinit", "201907L");
603  //Builder.defineMacro("__cpp_coroutines", "201902L");
604  Builder.defineMacro("__cpp_designated_initializers", "201707L");
605  Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L");
606  //Builder.defineMacro("__cpp_modules", "201907L");
607  Builder.defineMacro("__cpp_using_enum", "201907L");
608  }
609  // C++2b features.
610  if (LangOpts.CPlusPlus2b) {
611  Builder.defineMacro("__cpp_implicit_move", "202011L");
612  Builder.defineMacro("__cpp_size_t_suffix", "202011L");
613  Builder.defineMacro("__cpp_if_consteval", "202106L");
614  }
615  if (LangOpts.Char8)
616  Builder.defineMacro("__cpp_char8_t", "201811L");
617  Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
618 
619  // TS features.
620  if (LangOpts.Coroutines)
621  Builder.defineMacro("__cpp_coroutines", "201703L");
622 }
623 
624 /// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
625 /// settings and language version
627  const LangOptions &Opts,
628  MacroBuilder &Builder) {
629  const llvm::StringMap<bool> &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
630  // FIXME: OpenCL options which affect language semantics/syntax
631  // should be moved into LangOptions.
632  auto defineOpenCLExtMacro = [&](llvm::StringRef Name, auto... OptArgs) {
633  // Check if extension is supported by target and is available in this
634  // OpenCL version
635  if (TI.hasFeatureEnabled(OpenCLFeaturesMap, Name) &&
637  Builder.defineMacro(Name);
638  };
639 #define OPENCL_GENERIC_EXTENSION(Ext, ...) \
640  defineOpenCLExtMacro(#Ext, __VA_ARGS__);
641 #include "clang/Basic/OpenCLExtensions.def"
642 
643  // Assume compiling for FULL profile
644  Builder.defineMacro("__opencl_c_int64");
645 }
646 
648  const LangOptions &LangOpts,
649  const FrontendOptions &FEOpts,
650  const PreprocessorOptions &PPOpts,
651  MacroBuilder &Builder) {
652  // Compiler version introspection macros.
653  Builder.defineMacro("__llvm__"); // LLVM Backend
654  Builder.defineMacro("__clang__"); // Clang Frontend
655 #define TOSTR2(X) #X
656 #define TOSTR(X) TOSTR2(X)
657  Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
658  Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
659  Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
660 #undef TOSTR
661 #undef TOSTR2
662  Builder.defineMacro("__clang_version__",
663  "\"" CLANG_VERSION_STRING " "
664  + getClangFullRepositoryVersion() + "\"");
665 
666  if (LangOpts.GNUCVersion != 0) {
667  // Major, minor, patch, are given two decimal places each, so 4.2.1 becomes
668  // 40201.
669  unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100;
670  unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100;
671  unsigned GNUCPatch = LangOpts.GNUCVersion % 100;
672  Builder.defineMacro("__GNUC__", Twine(GNUCMajor));
673  Builder.defineMacro("__GNUC_MINOR__", Twine(GNUCMinor));
674  Builder.defineMacro("__GNUC_PATCHLEVEL__", Twine(GNUCPatch));
675  Builder.defineMacro("__GXX_ABI_VERSION", "1002");
676 
677  if (LangOpts.CPlusPlus) {
678  Builder.defineMacro("__GNUG__", Twine(GNUCMajor));
679  Builder.defineMacro("__GXX_WEAK__");
680  }
681  }
682 
683  // Define macros for the C11 / C++11 memory orderings
684  Builder.defineMacro("__ATOMIC_RELAXED", "0");
685  Builder.defineMacro("__ATOMIC_CONSUME", "1");
686  Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
687  Builder.defineMacro("__ATOMIC_RELEASE", "3");
688  Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
689  Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
690 
691  // Define macros for the OpenCL memory scope.
692  // The values should match AtomicScopeOpenCLModel::ID enum.
693  static_assert(
694  static_cast<unsigned>(AtomicScopeOpenCLModel::WorkGroup) == 1 &&
695  static_cast<unsigned>(AtomicScopeOpenCLModel::Device) == 2 &&
696  static_cast<unsigned>(AtomicScopeOpenCLModel::AllSVMDevices) == 3 &&
697  static_cast<unsigned>(AtomicScopeOpenCLModel::SubGroup) == 4,
698  "Invalid OpenCL memory scope enum definition");
699  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0");
700  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1");
701  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2");
702  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3");
703  Builder.defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4");
704 
705  // Support for #pragma redefine_extname (Sun compatibility)
706  Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
707 
708  // Previously this macro was set to a string aiming to achieve compatibility
709  // with GCC 4.2.1. Now, just return the full Clang version
710  Builder.defineMacro("__VERSION__", "\"" +
711  Twine(getClangFullCPPVersion()) + "\"");
712 
713  // Initialize language-specific preprocessor defines.
714 
715  // Standard conforming mode?
716  if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
717  Builder.defineMacro("__STRICT_ANSI__");
718 
719  if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
720  Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
721 
722  if (LangOpts.ObjC) {
723  if (LangOpts.ObjCRuntime.isNonFragile()) {
724  Builder.defineMacro("__OBJC2__");
725 
726  if (LangOpts.ObjCExceptions)
727  Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
728  }
729 
730  if (LangOpts.getGC() != LangOptions::NonGC)
731  Builder.defineMacro("__OBJC_GC__");
732 
733  if (LangOpts.ObjCRuntime.isNeXTFamily())
734  Builder.defineMacro("__NEXT_RUNTIME__");
735 
736  if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::GNUstep) {
737  auto version = LangOpts.ObjCRuntime.getVersion();
738  std::string versionString = "1";
739  // Don't rely on the tuple argument, because we can be asked to target
740  // later ABIs than we actually support, so clamp these values to those
741  // currently supported
742  if (version >= VersionTuple(2, 0))
743  Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", "20");
744  else
745  Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__",
746  "1" + Twine(std::min(8U, version.getMinor().getValueOr(0))));
747  }
748 
749  if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
750  VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
751 
752  unsigned minor = 0;
753  if (tuple.getMinor().hasValue())
754  minor = tuple.getMinor().getValue();
755 
756  unsigned subminor = 0;
757  if (tuple.getSubminor().hasValue())
758  subminor = tuple.getSubminor().getValue();
759 
760  Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
761  Twine(tuple.getMajor() * 10000 + minor * 100 +
762  subminor));
763  }
764 
765  Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
766  Builder.defineMacro("IBOutletCollection(ClassName)",
767  "__attribute__((iboutletcollection(ClassName)))");
768  Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
769  Builder.defineMacro("IBInspectable", "");
770  Builder.defineMacro("IB_DESIGNABLE", "");
771  }
772 
773  // Define a macro that describes the Objective-C boolean type even for C
774  // and C++ since BOOL can be used from non Objective-C code.
775  Builder.defineMacro("__OBJC_BOOL_IS_BOOL",
776  Twine(TI.useSignedCharForObjCBool() ? "0" : "1"));
777 
778  if (LangOpts.CPlusPlus)
779  InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
780 
781  // darwin_constant_cfstrings controls this. This is also dependent
782  // on other things like the runtime I believe. This is set even for C code.
783  if (!LangOpts.NoConstantCFStrings)
784  Builder.defineMacro("__CONSTANT_CFSTRINGS__");
785 
786  if (LangOpts.ObjC)
787  Builder.defineMacro("OBJC_NEW_PROPERTIES");
788 
789  if (LangOpts.PascalStrings)
790  Builder.defineMacro("__PASCAL_STRINGS__");
791 
792  if (LangOpts.Blocks) {
793  Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
794  Builder.defineMacro("__BLOCKS__");
795  }
796 
797  if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
798  Builder.defineMacro("__EXCEPTIONS");
799  if (LangOpts.GNUCVersion && LangOpts.RTTI)
800  Builder.defineMacro("__GXX_RTTI");
801 
802  if (LangOpts.hasSjLjExceptions())
803  Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
804  else if (LangOpts.hasSEHExceptions())
805  Builder.defineMacro("__SEH__");
806  else if (LangOpts.hasDWARFExceptions() &&
807  (TI.getTriple().isThumb() || TI.getTriple().isARM()))
808  Builder.defineMacro("__ARM_DWARF_EH__");
809 
810  if (LangOpts.Deprecated)
811  Builder.defineMacro("__DEPRECATED");
812 
813  if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus)
814  Builder.defineMacro("__private_extern__", "extern");
815 
816  if (LangOpts.MicrosoftExt) {
817  if (LangOpts.WChar) {
818  // wchar_t supported as a keyword.
819  Builder.defineMacro("_WCHAR_T_DEFINED");
820  Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
821  }
822  }
823 
824  // Macros to help identify the narrow and wide character sets
825  // FIXME: clang currently ignores -fexec-charset=. If this changes,
826  // then this may need to be updated.
827  Builder.defineMacro("__clang_literal_encoding__", "\"UTF-8\"");
828  if (TI.getTypeWidth(TI.getWCharType()) >= 32) {
829  // FIXME: 32-bit wchar_t signals UTF-32. This may change
830  // if -fwide-exec-charset= is ever supported.
831  Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-32\"");
832  } else {
833  // FIXME: Less-than 32-bit wchar_t generally means UTF-16
834  // (e.g., Windows, 32-bit IBM). This may need to be
835  // updated if -fwide-exec-charset= is ever supported.
836  Builder.defineMacro("__clang_wide_literal_encoding__", "\"UTF-16\"");
837  }
838 
839  if (LangOpts.Optimize)
840  Builder.defineMacro("__OPTIMIZE__");
841  if (LangOpts.OptimizeSize)
842  Builder.defineMacro("__OPTIMIZE_SIZE__");
843 
844  if (LangOpts.FastMath)
845  Builder.defineMacro("__FAST_MATH__");
846 
847  // Initialize target-specific preprocessor defines.
848 
849  // __BYTE_ORDER__ was added in GCC 4.6. It's analogous
850  // to the macro __BYTE_ORDER (no trailing underscores)
851  // from glibc's <endian.h> header.
852  // We don't support the PDP-11 as a target, but include
853  // the define so it can still be compared against.
854  Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
855  Builder.defineMacro("__ORDER_BIG_ENDIAN__", "4321");
856  Builder.defineMacro("__ORDER_PDP_ENDIAN__", "3412");
857  if (TI.isBigEndian()) {
858  Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
859  Builder.defineMacro("__BIG_ENDIAN__");
860  } else {
861  Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
862  Builder.defineMacro("__LITTLE_ENDIAN__");
863  }
864 
865  if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
866  && TI.getIntWidth() == 32) {
867  Builder.defineMacro("_LP64");
868  Builder.defineMacro("__LP64__");
869  }
870 
871  if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
872  && TI.getIntWidth() == 32) {
873  Builder.defineMacro("_ILP32");
874  Builder.defineMacro("__ILP32__");
875  }
876 
877  // Define type sizing macros based on the target properties.
878  assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
879  Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
880 
881  DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
882  DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
883  DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
884  DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
885  DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
886  DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
887  DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder);
888  DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
889  DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
890 
891  DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
892  DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
893  DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
894  DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
895 
896  DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
897  DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
898  DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
899  DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
900  DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
901  DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
902  DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
903  DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
904  DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
905  TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
906  DefineTypeSizeof("__SIZEOF_SIZE_T__",
907  TI.getTypeWidth(TI.getSizeType()), TI, Builder);
908  DefineTypeSizeof("__SIZEOF_WCHAR_T__",
909  TI.getTypeWidth(TI.getWCharType()), TI, Builder);
910  DefineTypeSizeof("__SIZEOF_WINT_T__",
911  TI.getTypeWidth(TI.getWIntType()), TI, Builder);
912  if (TI.hasInt128Type())
913  DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
914 
915  DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
916  DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
917  Builder.defineMacro("__INTMAX_C_SUFFIX__",
919  DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
920  DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
921  Builder.defineMacro("__UINTMAX_C_SUFFIX__",
923  DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder);
924  DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
925  DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
926  DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
927  DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
928  DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
929  DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
930  DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
931  DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
932  DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
933  DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
934  DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
935  DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
936  DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
937  DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
938  DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
939  DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
940  DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
941 
942  DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder);
943  DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
944  DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
945  DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
946 
947  if (TI.hasFloat16Type())
948  DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16");
949  DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
950  DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
951  DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
952 
953  // Define a __POINTER_WIDTH__ macro for stdint.h.
954  Builder.defineMacro("__POINTER_WIDTH__",
955  Twine((int)TI.getPointerWidth(0)));
956 
957  // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
958  Builder.defineMacro("__BIGGEST_ALIGNMENT__",
959  Twine(TI.getSuitableAlign() / TI.getCharWidth()) );
960 
961  if (!LangOpts.CharIsSigned)
962  Builder.defineMacro("__CHAR_UNSIGNED__");
963 
965  Builder.defineMacro("__WCHAR_UNSIGNED__");
966 
968  Builder.defineMacro("__WINT_UNSIGNED__");
969 
970  // Define exact-width integer types for stdint.h
972 
973  if (TI.getShortWidth() > TI.getCharWidth())
975 
976  if (TI.getIntWidth() > TI.getShortWidth())
978 
979  if (TI.getLongWidth() > TI.getIntWidth())
981 
982  if (TI.getLongLongWidth() > TI.getLongWidth())
984 
988 
989  if (TI.getShortWidth() > TI.getCharWidth()) {
993  }
994 
995  if (TI.getIntWidth() > TI.getShortWidth()) {
999  }
1000 
1001  if (TI.getLongWidth() > TI.getIntWidth()) {
1005  }
1006 
1007  if (TI.getLongLongWidth() > TI.getLongWidth()) {
1011  }
1012 
1013  DefineLeastWidthIntType(8, true, TI, Builder);
1014  DefineLeastWidthIntType(8, false, TI, Builder);
1015  DefineLeastWidthIntType(16, true, TI, Builder);
1016  DefineLeastWidthIntType(16, false, TI, Builder);
1017  DefineLeastWidthIntType(32, true, TI, Builder);
1018  DefineLeastWidthIntType(32, false, TI, Builder);
1019  DefineLeastWidthIntType(64, true, TI, Builder);
1020  DefineLeastWidthIntType(64, false, TI, Builder);
1021 
1022  DefineFastIntType(8, true, TI, Builder);
1023  DefineFastIntType(8, false, TI, Builder);
1024  DefineFastIntType(16, true, TI, Builder);
1025  DefineFastIntType(16, false, TI, Builder);
1026  DefineFastIntType(32, true, TI, Builder);
1027  DefineFastIntType(32, false, TI, Builder);
1028  DefineFastIntType(64, true, TI, Builder);
1029  DefineFastIntType(64, false, TI, Builder);
1030 
1031  Builder.defineMacro("__USER_LABEL_PREFIX__", TI.getUserLabelPrefix());
1032 
1033  if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
1034  Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
1035  else
1036  Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
1037 
1038  if (LangOpts.GNUCVersion) {
1039  if (LangOpts.GNUInline || LangOpts.CPlusPlus)
1040  Builder.defineMacro("__GNUC_GNU_INLINE__");
1041  else
1042  Builder.defineMacro("__GNUC_STDC_INLINE__");
1043 
1044  // The value written by __atomic_test_and_set.
1045  // FIXME: This is target-dependent.
1046  Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
1047  }
1048 
1049  auto addLockFreeMacros = [&](const llvm::Twine &Prefix) {
1050  // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
1051  unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
1052 #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
1053  Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \
1054  getLockFreeValue(TI.get##Type##Width(), \
1055  TI.get##Type##Align(), \
1056  InlineWidthBits));
1058  DEFINE_LOCK_FREE_MACRO(CHAR, Char);
1059  if (LangOpts.Char8)
1060  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
1061  DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
1062  DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
1063  DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
1064  DEFINE_LOCK_FREE_MACRO(SHORT, Short);
1065  DEFINE_LOCK_FREE_MACRO(INT, Int);
1068  Builder.defineMacro(Prefix + "POINTER_LOCK_FREE",
1070  TI.getPointerAlign(0),
1071  InlineWidthBits));
1072 #undef DEFINE_LOCK_FREE_MACRO
1073  };
1074  addLockFreeMacros("__CLANG_ATOMIC_");
1075  if (LangOpts.GNUCVersion)
1076  addLockFreeMacros("__GCC_ATOMIC_");
1077 
1078  if (LangOpts.NoInlineDefine)
1079  Builder.defineMacro("__NO_INLINE__");
1080 
1081  if (unsigned PICLevel = LangOpts.PICLevel) {
1082  Builder.defineMacro("__PIC__", Twine(PICLevel));
1083  Builder.defineMacro("__pic__", Twine(PICLevel));
1084  if (LangOpts.PIE) {
1085  Builder.defineMacro("__PIE__", Twine(PICLevel));
1086  Builder.defineMacro("__pie__", Twine(PICLevel));
1087  }
1088  }
1089 
1090  // Macros to control C99 numerics and <float.h>
1091  Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
1092  Builder.defineMacro("__FLT_RADIX__", "2");
1093  Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
1094 
1095  if (LangOpts.getStackProtector() == LangOptions::SSPOn)
1096  Builder.defineMacro("__SSP__");
1097  else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
1098  Builder.defineMacro("__SSP_STRONG__", "2");
1099  else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
1100  Builder.defineMacro("__SSP_ALL__", "3");
1101 
1102  if (PPOpts.SetUpStaticAnalyzer)
1103  Builder.defineMacro("__clang_analyzer__");
1104 
1105  if (LangOpts.FastRelaxedMath)
1106  Builder.defineMacro("__FAST_RELAXED_MATH__");
1107 
1108  if (FEOpts.ProgramAction == frontend::RewriteObjC ||
1109  LangOpts.getGC() != LangOptions::NonGC) {
1110  Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
1111  Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))");
1112  Builder.defineMacro("__autoreleasing", "");
1113  Builder.defineMacro("__unsafe_unretained", "");
1114  } else if (LangOpts.ObjC) {
1115  Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
1116  Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
1117  Builder.defineMacro("__autoreleasing",
1118  "__attribute__((objc_ownership(autoreleasing)))");
1119  Builder.defineMacro("__unsafe_unretained",
1120  "__attribute__((objc_ownership(none)))");
1121  }
1122 
1123  // On Darwin, there are __double_underscored variants of the type
1124  // nullability qualifiers.
1125  if (TI.getTriple().isOSDarwin()) {
1126  Builder.defineMacro("__nonnull", "_Nonnull");
1127  Builder.defineMacro("__null_unspecified", "_Null_unspecified");
1128  Builder.defineMacro("__nullable", "_Nullable");
1129  }
1130 
1131  // Add a macro to differentiate between regular iOS/tvOS/watchOS targets and
1132  // the corresponding simulator targets.
1133  if (TI.getTriple().isOSDarwin() && TI.getTriple().isSimulatorEnvironment())
1134  Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1");
1135 
1136  // OpenMP definition
1137  // OpenMP 2.2:
1138  // In implementations that support a preprocessor, the _OPENMP
1139  // macro name is defined to have the decimal value yyyymm where
1140  // yyyy and mm are the year and the month designations of the
1141  // version of the OpenMP API that the implementation support.
1142  if (!LangOpts.OpenMPSimd) {
1143  switch (LangOpts.OpenMP) {
1144  case 0:
1145  break;
1146  case 31:
1147  Builder.defineMacro("_OPENMP", "201107");
1148  break;
1149  case 40:
1150  Builder.defineMacro("_OPENMP", "201307");
1151  break;
1152  case 45:
1153  Builder.defineMacro("_OPENMP", "201511");
1154  break;
1155  default:
1156  // Default version is OpenMP 5.0
1157  Builder.defineMacro("_OPENMP", "201811");
1158  break;
1159  }
1160  }
1161 
1162  // CUDA device path compilaton
1163  if (LangOpts.CUDAIsDevice && !LangOpts.HIP) {
1164  // The CUDA_ARCH value is set for the GPU target specified in the NVPTX
1165  // backend's target defines.
1166  Builder.defineMacro("__CUDA_ARCH__");
1167  }
1168 
1169  // We need to communicate this to our CUDA header wrapper, which in turn
1170  // informs the proper CUDA headers of this choice.
1171  if (LangOpts.CUDADeviceApproxTranscendentals || LangOpts.FastMath) {
1172  Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
1173  }
1174 
1175  // Define a macro indicating that the source file is being compiled with a
1176  // SYCL device compiler which doesn't produce host binary.
1177  if (LangOpts.SYCLIsDevice) {
1178  Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1");
1179  }
1180 
1181  // OpenCL definitions.
1182  if (LangOpts.OpenCL) {
1183  InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
1184 
1185  if (TI.getTriple().isSPIR())
1186  Builder.defineMacro("__IMAGE_SUPPORT__");
1187  }
1188 
1189  if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
1190  // For each extended integer type, g++ defines a macro mapping the
1191  // index of the type (0 in this case) in some list of extended types
1192  // to the type.
1193  Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128");
1194  Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
1195  }
1196 
1197  // Get other target #defines.
1198  TI.getTargetDefines(LangOpts, Builder);
1199 }
1200 
1201 /// InitializePreprocessor - Initialize the preprocessor getting it and the
1202 /// environment ready to process a single file. This returns true on error.
1203 ///
1205  Preprocessor &PP, const PreprocessorOptions &InitOpts,
1206  const PCHContainerReader &PCHContainerRdr,
1207  const FrontendOptions &FEOpts) {
1208  const LangOptions &LangOpts = PP.getLangOpts();
1209  std::string PredefineBuffer;
1210  PredefineBuffer.reserve(4080);
1211  llvm::raw_string_ostream Predefines(PredefineBuffer);
1212  MacroBuilder Builder(Predefines);
1213 
1214  // Emit line markers for various builtin sections of the file. We don't do
1215  // this in asm preprocessor mode, because "# 4" is not a line marker directive
1216  // in this mode.
1217  if (!PP.getLangOpts().AsmPreprocessor)
1218  Builder.append("# 1 \"<built-in>\" 3");
1219 
1220  // Install things like __POWERPC__, __GNUC__, etc into the macro table.
1221  if (InitOpts.UsePredefines) {
1222  // FIXME: This will create multiple definitions for most of the predefined
1223  // macros. This is not the right way to handle this.
1224  if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice || LangOpts.SYCLIsDevice) &&
1225  PP.getAuxTargetInfo())
1226  InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
1227  PP.getPreprocessorOpts(), Builder);
1228 
1229  InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts,
1230  PP.getPreprocessorOpts(), Builder);
1231 
1232  // Install definitions to make Objective-C++ ARC work well with various
1233  // C++ Standard Library implementations.
1234  if (LangOpts.ObjC && LangOpts.CPlusPlus &&
1235  (LangOpts.ObjCAutoRefCount || LangOpts.ObjCWeak)) {
1236  switch (InitOpts.ObjCXXARCStandardLibrary) {
1237  case ARCXX_nolib:
1238  case ARCXX_libcxx:
1239  break;
1240 
1241  case ARCXX_libstdcxx:
1242  AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
1243  break;
1244  }
1245  }
1246  }
1247 
1248  // Even with predefines off, some macros are still predefined.
1249  // These should all be defined in the preprocessor according to the
1250  // current language configuration.
1252  FEOpts, Builder);
1253 
1254  // Add on the predefines from the driver. Wrap in a #line directive to report
1255  // that they come from the command line.
1256  if (!PP.getLangOpts().AsmPreprocessor)
1257  Builder.append("# 1 \"<command line>\" 1");
1258 
1259  // Process #define's and #undef's in the order they are given.
1260  for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
1261  if (InitOpts.Macros[i].second) // isUndef
1262  Builder.undefineMacro(InitOpts.Macros[i].first);
1263  else
1264  DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
1265  PP.getDiagnostics());
1266  }
1267 
1268  // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
1269  if (!PP.getLangOpts().AsmPreprocessor)
1270  Builder.append("# 1 \"<built-in>\" 2");
1271 
1272  // If -imacros are specified, include them now. These are processed before
1273  // any -include directives.
1274  for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
1275  AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
1276 
1277  // Process -include-pch/-include-pth directives.
1278  if (!InitOpts.ImplicitPCHInclude.empty())
1279  AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
1280  InitOpts.ImplicitPCHInclude);
1281 
1282  // Process -include directives.
1283  for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
1284  const std::string &Path = InitOpts.Includes[i];
1285  AddImplicitInclude(Builder, Path);
1286  }
1287 
1288  // Instruct the preprocessor to skip the preamble.
1290  InitOpts.PrecompiledPreambleBytes.second);
1291 
1292  // Copy PredefinedBuffer into the Preprocessor.
1293  PP.setPredefines(Predefines.str());
1294 }
clang::TypeSpecifierWidth::LongLong
@ LongLong
clang::Preprocessor::setSkipMainFilePreamble
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
Definition: Preprocessor.h:1736
clang::LangOptions::hasSEHExceptions
bool hasSEHExceptions() const
Definition: LangOptions.h:460
clang::TargetInfo::getLongDoubleFormat
const llvm::fltSemantics & getLongDoubleFormat() const
Definition: TargetInfo.h:670
clang::AtomicScopeOpenCLModel::WorkGroup
@ WorkGroup
Definition: SyncScope.h:100
DefineBuiltinMacro
static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro, DiagnosticsEngine &Diags)
Definition: InitPreprocessor.cpp:39
clang::PreprocessorOptions::SetUpStaticAnalyzer
bool SetUpStaticAnalyzer
Set up preprocessor for RunAnalysis action.
Definition: PreprocessorOptions.h:211
clang::TransferrableTargetInfo::UnsignedChar
@ UnsignedChar
Definition: TargetInfo.h:122
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::DeclaratorContext::File
@ File
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PreprocessorOptions
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Definition: PreprocessorOptions.h:64
clang::TransferrableTargetInfo::SignedChar
@ SignedChar
Definition: TargetInfo.h:121
clang::TargetInfo::getTypeConstantSuffix
const char * getTypeConstantSuffix(IntType T) const
Return the constant suffix for the specified integer type enum.
Definition: TargetInfo.cpp:193
clang::FrontendOptions::ProgramAction
frontend::ActionKind ProgramAction
The frontend action to perform.
Definition: FrontendOptions.h:405
clang::TargetInfo::getDoubleFormat
const llvm::fltSemantics & getDoubleFormat() const
Definition: TargetInfo.h:664
clang::TargetInfo::getLongWidth
unsigned getLongWidth() const
getLongWidth/Align - Return the size of 'signed long' and 'unsigned long' for this target,...
Definition: TargetInfo.h:457
clang::TargetInfo::getSuitableAlign
unsigned getSuitableAlign() const
Return the alignment that is the largest alignment ever used for any scalar/SIMD data type on the tar...
Definition: TargetInfo.h:610
clang::LangOptions::SSPStrong
@ SSPStrong
Definition: LangOptions.h:64
clang::TargetInfo::getNewAlign
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with '::operator new(size_t)' or '...
Definition: TargetInfo.h:627
clang::ObjCRuntime::getKind
Kind getKind() const
Definition: ObjCRuntime.h:77
DefineType
static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:192
clang::TargetInfo::getUserLabelPrefix
const char * getUserLabelPrefix() const
Returns the default value of the USER_LABEL_PREFIX macro, which is the prefix given to user symbols b...
Definition: TargetInfo.h:775
TargetInfo.h
clang::TargetInfo::isTypeSigned
static bool isTypeSigned(IntType T)
Returns true if the type is signed; false otherwise.
Definition: TargetInfo.cpp:331
DefineExactWidthIntType
static void DefineExactWidthIntType(TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:208
clang::LangOptions::SSPReq
@ SSPReq
Definition: LangOptions.h:64
clang::TransferrableTargetInfo::UnsignedShort
@ UnsignedShort
Definition: TargetInfo.h:124
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo::getFloatEvalMethod
virtual unsigned getFloatEvalMethod() const
Return the value for the C99 FLT_EVAL_METHOD macro.
Definition: TargetInfo.h:705
clang::ARCXX_nolib
@ ARCXX_nolib
Definition: PreprocessorOptions.h:35
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::TargetInfo::hasFloat16Type
virtual bool hasFloat16Type() const
Determine whether the _Float16 type is supported on this target.
Definition: TargetInfo.h:596
TOSTR
#define TOSTR(X)
clang::TargetInfo::getCharWidth
unsigned getCharWidth() const
Definition: TargetInfo.h:439
clang::ASTReader::getOriginalSourceFile
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
Definition: ASTReader.h:1699
clang::TargetInfo::isBigEndian
bool isBigEndian() const
Definition: TargetInfo.h:1441
SourceManager.h
clang::TargetInfo::getLongLongWidth
unsigned getLongLongWidth() const
getLongLongWidth/Align - Return the size of 'signed long long' and 'unsigned long long' for this targ...
Definition: TargetInfo.h:462
PickFP
static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal, T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, T IEEEQuadVal)
PickFP - This is used to pick a value based on the FP semantics of the specified FP model.
Definition: InitPreprocessor.cpp:95
clang::LangOptions::hasDWARFExceptions
bool hasDWARFExceptions() const
Definition: LangOptions.h:464
clang::TransferrableTargetInfo::UnsignedLongLong
@ UnsignedLongLong
Definition: TargetInfo.h:130
clang::TargetInfo::hasInt128Type
virtual bool hasInt128Type() const
Determine whether the __int128 type is supported on this target.
Definition: TargetInfo.h:579
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::frontend::RewriteObjC
@ RewriteObjC
ObjC->C Rewriter.
Definition: FrontendOptions.h:121
clang::PreprocessorOptions::Includes
std::vector< std::string > Includes
Definition: PreprocessorOptions.h:67
clang::PCHContainerReader
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
Definition: PCHContainerOperations.h:57
clang::TargetInfo::getPtrDiffType
IntType getPtrDiffType(unsigned AddrSpace) const
Definition: TargetInfo.h:336
clang::TargetInfo::getUInt64Type
IntType getUInt64Type() const
Definition: TargetInfo.h:351
clang::AtomicScopeOpenCLModel::SubGroup
@ SubGroup
Definition: SyncScope.h:103
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:960
Preprocessor.h
AddImplicitIncludePCH
static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP, const PCHContainerReader &PCHContainerRdr, StringRef ImplicitIncludePCH)
Add an implicit #include using the original file used to generate a PCH file.
Definition: InitPreprocessor.cpp:80
clang::ObjCRuntime::getVersion
const VersionTuple & getVersion() const
Definition: ObjCRuntime.h:78
clang::TargetInfo::getMaxAtomicInlineWidth
unsigned getMaxAtomicInlineWidth() const
Return the maximum width lock-free atomic operation which can be inlined given the supported features...
Definition: TargetInfo.h:717
clang::TargetInfo::getLongDoubleWidth
unsigned getLongDoubleWidth() const
getLongDoubleWidth/Align/Format - Return the size/align/format of 'long double'.
Definition: TargetInfo.h:668
U
clang::TargetInfo::getSupportedOpenCLOpts
llvm::StringMap< bool > & getSupportedOpenCLOpts()
Get supported OpenCL extensions and optional core features.
Definition: TargetInfo.h:1533
clang::TargetInfo::useSignedCharForObjCBool
bool useSignedCharForObjCBool() const
Check if the Objective-C built-in boolean type should be signed char.
Definition: TargetInfo.h:787
AddImplicitInclude
static void AddImplicitInclude(MacroBuilder &Builder, StringRef File)
AddImplicitInclude - Add an implicit #include of the specified file to the predefines buffer.
Definition: InitPreprocessor.cpp:68
clang::TargetInfo::getIntPtrType
IntType getIntPtrType() const
Definition: TargetInfo.h:342
min
__DEVICE__ int min(int __a, int __b)
Definition: __clang_cuda_math.h:197
InitializeOpenCLFeatureTestMacros
void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI, const LangOptions &Opts, MacroBuilder &Builder)
InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target settings and language versio...
Definition: InitPreprocessor.cpp:626
clang::TargetInfo::getFloatWidth
unsigned getFloatWidth() const
getFloatWidth/Align/Format - Return the size/align/format of 'float'.
Definition: TargetInfo.h:652
clang::LangOptions::ObjCRuntime
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:323
clang::TargetInfo::isLittleEndian
bool isLittleEndian() const
Definition: TargetInfo.h:1442
FrontendOptions.h
clang::Preprocessor::setPredefines
void setPredefines(const char *P)
Set the predefines for this Preprocessor.
Definition: Preprocessor.h:1238
clang::TargetInfo::getChar32Type
IntType getChar32Type() const
Definition: TargetInfo.h:349
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
Version.h
clang::LangOptions::ThreadModelKind::POSIX
@ POSIX
POSIX Threads.
clang::TargetInfo::getPointerAlign
uint64_t getPointerAlign(unsigned AddrSpace) const
Definition: TargetInfo.h:420
clang::FrontendOptions
FrontendOptions - Options for controlling the behavior of the frontend.
Definition: FrontendOptions.h:228
Utils.h
MacroBuilder.h
clang::InitializePreprocessor
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts, const PCHContainerReader &PCHContainerRdr, const FrontendOptions &FEOpts)
InitializePreprocessor - Initialize the preprocessor getting it and the environment ready to process ...
Definition: InitPreprocessor.cpp:1204
DefineTypeWidth
static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:197
InitializePredefinedMacros
static void InitializePredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, const PreprocessorOptions &PPOpts, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:647
clang::Preprocessor::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:961
llvm::SmallString< 32 >
DEFINE_LOCK_FREE_MACRO
#define DEFINE_LOCK_FREE_MACRO(TYPE, Type)
clang::TargetInfo::getFloatFormat
const llvm::fltSemantics & getFloatFormat() const
Definition: TargetInfo.h:654
clang::getClangFullRepositoryVersion
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:60
clang::PreprocessorOptions::UsePredefines
bool UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
Definition: PreprocessorOptions.h:72
clang::LangOptions::hasSjLjExceptions
bool hasSjLjExceptions() const
Definition: LangOptions.h:456
clang::LangOptions::SYCL_2017
@ SYCL_2017
Definition: LangOptions.h:132
DefineExactWidthIntTypeSize
static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:233
clang::TargetInfo::getHalfFormat
const llvm::fltSemantics & getHalfFormat() const
Definition: TargetInfo.h:649
clang::TargetInfo::getLeastIntTypeByWidth
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
Definition: TargetInfo.cpp:267
clang::ARCXX_libcxx
@ ARCXX_libcxx
libc++
Definition: PreprocessorOptions.h:38
MacroBodyEndsInBackslash
static bool MacroBodyEndsInBackslash(StringRef MacroBody)
Definition: InitPreprocessor.cpp:30
clang::TargetInfo::getDoubleWidth
unsigned getDoubleWidth() const
getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
Definition: TargetInfo.h:662
getLockFreeValue
static const char * getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign, unsigned InlineWidth)
Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with the specified properties.
Definition: InitPreprocessor.cpp:279
clang::ObjCRuntime::isNeXTFamily
bool isNeXTFamily() const
Is this runtime basically of the NeXT family of runtimes?
Definition: ObjCRuntime.h:135
DefineTypeSize
static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth, StringRef ValSuffix, bool isSigned, MacroBuilder &Builder)
DefineTypeSize - Emit a macro to the predefines buffer that declares a macro named MacroName with the...
Definition: InitPreprocessor.cpp:166
clang::ObjCRuntime::ObjFW
@ ObjFW
'objfw' is the Objective-C runtime included in ObjFW
Definition: ObjCRuntime.h:59
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1130
clang::TargetInfo::getSizeType
IntType getSizeType() const
Definition: TargetInfo.h:317
GCCTypeClass::Bool
@ Bool
clang::isWhitespace
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: ' ', '\t',...
Definition: CharInfo.h:92
clang::TargetInfo::getUInt16Type
IntType getUInt16Type() const
Definition: TargetInfo.h:355
clang::TargetInfo::getTargetDefines
virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const =0
===-— Other target property query methods -----------------------—===//
clang::TargetInfo::getInt16Type
IntType getInt16Type() const
Definition: TargetInfo.h:354
clang::Preprocessor::getAuxTargetInfo
const TargetInfo * getAuxTargetInfo() const
Definition: Preprocessor.h:962
clang::TargetInfo::getUIntPtrType
IntType getUIntPtrType() const
Definition: TargetInfo.h:343
DefineLeastWidthIntType
static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:248
clang::TargetInfo::getTypeName
static const char * getTypeName(IntType T)
Return the user string for the specified integer type enum.
Definition: TargetInfo.cpp:175
InitializeCPlusPlusFeatureTestMacros
static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, MacroBuilder &Builder)
Initialize the predefined C++ language feature test macros defined in ISO/IEC JTC1/SC22/WG21 (C++) SD...
Definition: InitPreprocessor.cpp:515
clang::ObjCRuntime::GNUstep
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
Definition: ObjCRuntime.h:56
clang::LangOptions::NonGC
@ NonGC
Definition: LangOptions.h:63
clang::TransferrableTargetInfo::NoInt
@ NoInt
Definition: TargetInfo.h:120
clang::TargetInfo::getWIntType
IntType getWIntType() const
Definition: TargetInfo.h:347
clang::LangOptions::SYCL_2020
@ SYCL_2020
Definition: LangOptions.h:133
AddImplicitIncludeMacros
static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File)
Definition: InitPreprocessor.cpp:72
HeaderSearch.h
clang::PreprocessorOptions::PrecompiledPreambleBytes
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
Definition: PreprocessorOptions.h:125
AddObjCXXARCLibstdcxxDefines
static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts, MacroBuilder &Builder)
Add definitions required for a smooth interaction between Objective-C++ automated reference counting ...
Definition: InitPreprocessor.cpp:293
clang::LangOptions::SSPOn
@ SSPOn
Definition: LangOptions.h:64
clang::TargetInfo::getUIntMaxType
IntType getUIntMaxType() const
Definition: TargetInfo.h:333
clang::TargetInfo::getIntMaxType
IntType getIntMaxType() const
Definition: TargetInfo.h:332
clang::Preprocessor::getFileManager
FileManager & getFileManager() const
Definition: Preprocessor.h:963
DefineFloatMacros
static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, const llvm::fltSemantics *Sem, StringRef Ext)
Definition: InitPreprocessor.cpp:112
clang::PreprocessorOptions::ObjCXXARCStandardLibrary
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
Definition: PreprocessorOptions.h:178
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::Preprocessor::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:955
clang::TransferrableTargetInfo::IntType
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:119
clang::TargetInfo::getChar16Type
IntType getChar16Type() const
Definition: TargetInfo.h:348
DefineFastIntType
static void DefineFastIntType(unsigned TypeWidth, bool IsSigned, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:261
clang::TargetInfo::getShortWidth
unsigned getShortWidth() const
Return the size of 'signed short' and 'unsigned short' for this target, in bits.
Definition: TargetInfo.h:444
clang::AtomicScopeOpenCLModel::AllSVMDevices
@ AllSVMDevices
Definition: SyncScope.h:102
clang::ARCXX_libstdcxx
@ ARCXX_libstdcxx
libstdc++
Definition: PreprocessorOptions.h:41
clang::TargetInfo::getTypeWidth
unsigned getTypeWidth(IntType T) const
Return the width (in bits) of the specified integer type enum.
Definition: TargetInfo.cpp:236
clang
Definition: CalledOnceCheck.h:17
clang::TargetInfo::getTypeFormatModifier
static const char * getTypeFormatModifier(IntType T)
Return the printf format modifier for the specified integer type enum.
Definition: TargetInfo.cpp:218
clang::TargetInfo::getPointerWidth
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition: TargetInfo.h:417
FrontendDiagnostic.h
ASTReader.h
clang::TargetInfo::hasFeatureEnabled
virtual bool hasFeatureEnabled(const llvm::StringMap< bool > &Features, StringRef Name) const
Check if target has a given feature enabled.
Definition: TargetInfo.h:1253
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:957
clang::TransferrableTargetInfo::SignedInt
@ SignedInt
Definition: TargetInfo.h:125
clang::TransferrableTargetInfo::UnsignedLong
@ UnsignedLong
Definition: TargetInfo.h:128
clang::TransferrableTargetInfo::SignedLongLong
@ SignedLongLong
Definition: TargetInfo.h:129
clang::TargetInfo::getSigAtomicType
IntType getSigAtomicType() const
Definition: TargetInfo.h:358
clang::PreprocessorOptions::MacroIncludes
std::vector< std::string > MacroIncludes
Definition: PreprocessorOptions.h:68
DefineFmt
static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:182
clang::AtomicScopeOpenCLModel::Device
@ Device
Definition: SyncScope.h:101
clang::TargetInfo::getInt64Type
IntType getInt64Type() const
Definition: TargetInfo.h:350
clang::ObjCRuntime::isNonFragile
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Definition: ObjCRuntime.h:82
SyncScope.h
FileManager.h
clang::TransferrableTargetInfo::SignedShort
@ SignedShort
Definition: TargetInfo.h:123
PreprocessorOptions.h
clang::OpenCLOptions::isOpenCLOptionAvailableIn
static bool isOpenCLOptionAvailableIn(const LangOptions &LO, Args &&... args)
Definition: OpenCLOptions.h:195
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::TypeSpecifierWidth::Short
@ Short
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::getClangFullCPPVersion
std::string getClangFullCPPVersion()
Retrieves a string representing the complete clang version suitable for use in the CPP VERSION macro,...
Definition: Version.cpp:108
clang::TargetInfo::getWCharType
IntType getWCharType() const
Definition: TargetInfo.h:346
InitializeStandardPredefinedMacros
static void InitializeStandardPredefinedMacros(const TargetInfo &TI, const LangOptions &LangOpts, const FrontendOptions &FEOpts, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:348
clang::PreprocessorOptions::Macros
std::vector< std::pair< std::string, bool > > Macros
Definition: PreprocessorOptions.h:66
clang::TransferrableTargetInfo::UnsignedInt
@ UnsignedInt
Definition: TargetInfo.h:126
clang::TypeSpecifierWidth::Long
@ Long
DefineTypeSizeof
static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth, const TargetInfo &TI, MacroBuilder &Builder)
Definition: InitPreprocessor.cpp:202
clang::TargetInfo::getIntWidth
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
Definition: TargetInfo.h:452
clang::PreprocessorOptions::ImplicitPCHInclude
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Definition: PreprocessorOptions.h:96
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1523
clang::TransferrableTargetInfo::SignedLong
@ SignedLong
Definition: TargetInfo.h:127