]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Frontend/InitPreprocessor.cpp
MFV r294808: 6421 Add missing multilist_destroy calls to arc_fini
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Frontend / InitPreprocessor.cpp
1 //===--- InitPreprocessor.cpp - PP initialization code. ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the clang::InitializePreprocessor function.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/Frontend/Utils.h"
15 #include "clang/Basic/FileManager.h"
16 #include "clang/Basic/MacroBuilder.h"
17 #include "clang/Basic/SourceManager.h"
18 #include "clang/Basic/TargetInfo.h"
19 #include "clang/Basic/Version.h"
20 #include "clang/Frontend/FrontendDiagnostic.h"
21 #include "clang/Frontend/FrontendOptions.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 #include "llvm/Support/FileSystem.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/Path.h"
30 using namespace clang;
31
32 static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
33   while (!MacroBody.empty() && isWhitespace(MacroBody.back()))
34     MacroBody = MacroBody.drop_back();
35   return !MacroBody.empty() && MacroBody.back() == '\\';
36 }
37
38 // Append a #define line to Buf for Macro.  Macro should be of the form XXX,
39 // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
40 // "#define XXX Y z W".  To get a #define with no value, use "XXX=".
41 static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
42                                DiagnosticsEngine &Diags) {
43   std::pair<StringRef, StringRef> MacroPair = Macro.split('=');
44   StringRef MacroName = MacroPair.first;
45   StringRef MacroBody = MacroPair.second;
46   if (MacroName.size() != Macro.size()) {
47     // Per GCC -D semantics, the macro ends at \n if it exists.
48     StringRef::size_type End = MacroBody.find_first_of("\n\r");
49     if (End != StringRef::npos)
50       Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
51         << MacroName;
52     MacroBody = MacroBody.substr(0, End);
53     // We handle macro bodies which end in a backslash by appending an extra
54     // backslash+newline.  This makes sure we don't accidentally treat the
55     // backslash as a line continuation marker.
56     if (MacroBodyEndsInBackslash(MacroBody))
57       Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
58     else
59       Builder.defineMacro(MacroName, MacroBody);
60   } else {
61     // Push "macroname 1".
62     Builder.defineMacro(Macro);
63   }
64 }
65
66 /// AddImplicitInclude - Add an implicit \#include of the specified file to the
67 /// predefines buffer.
68 /// As these includes are generated by -include arguments the header search
69 /// logic is going to search relatively to the current working directory.
70 static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) {
71   Builder.append(Twine("#include \"") + File + "\"");
72 }
73
74 static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
75   Builder.append(Twine("#__include_macros \"") + File + "\"");
76   // Marker token to stop the __include_macros fetch loop.
77   Builder.append("##"); // ##?
78 }
79
80 /// AddImplicitIncludePTH - Add an implicit \#include using the original file
81 /// used to generate a PTH cache.
82 static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
83                                   StringRef ImplicitIncludePTH) {
84   PTHManager *P = PP.getPTHManager();
85   // Null check 'P' in the corner case where it couldn't be created.
86   const char *OriginalFile = P ? P->getOriginalSourceFile() : nullptr;
87
88   if (!OriginalFile) {
89     PP.getDiagnostics().Report(diag::err_fe_pth_file_has_no_source_header)
90       << ImplicitIncludePTH;
91     return;
92   }
93
94   AddImplicitInclude(Builder, OriginalFile);
95 }
96
97 /// \brief Add an implicit \#include using the original file used to generate
98 /// a PCH file.
99 static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
100                                   const PCHContainerReader &PCHContainerRdr,
101                                   StringRef ImplicitIncludePCH) {
102   std::string OriginalFile =
103       ASTReader::getOriginalSourceFile(ImplicitIncludePCH, PP.getFileManager(),
104                                        PCHContainerRdr, PP.getDiagnostics());
105   if (OriginalFile.empty())
106     return;
107
108   AddImplicitInclude(Builder, OriginalFile);
109 }
110
111 /// PickFP - This is used to pick a value based on the FP semantics of the
112 /// specified FP model.
113 template <typename T>
114 static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal,
115                 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
116                 T IEEEQuadVal) {
117   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle)
118     return IEEESingleVal;
119   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble)
120     return IEEEDoubleVal;
121   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended)
122     return X87DoubleExtendedVal;
123   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble)
124     return PPCDoubleDoubleVal;
125   assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad);
126   return IEEEQuadVal;
127 }
128
129 static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
130                               const llvm::fltSemantics *Sem, StringRef Ext) {
131   const char *DenormMin, *Epsilon, *Max, *Min;
132   DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324",
133                      "3.64519953188247460253e-4951",
134                      "4.94065645841246544176568792868221e-324",
135                      "6.47517511943802511092443895822764655e-4966");
136   int Digits = PickFP(Sem, 6, 15, 18, 31, 33);
137   int DecimalDigits = PickFP(Sem, 9, 17, 21, 33, 36);
138   Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16",
139                    "1.08420217248550443401e-19",
140                    "4.94065645841246544176568792868221e-324",
141                    "1.92592994438723585305597794258492732e-34");
142   int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113);
143   int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931);
144   int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932);
145   int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381);
146   int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384);
147   Min = PickFP(Sem, "1.17549435e-38", "2.2250738585072014e-308",
148                "3.36210314311209350626e-4932",
149                "2.00416836000897277799610805135016e-292",
150                "3.36210314311209350626267781732175260e-4932");
151   Max = PickFP(Sem, "3.40282347e+38", "1.7976931348623157e+308",
152                "1.18973149535723176502e+4932",
153                "1.79769313486231580793728971405301e+308",
154                "1.18973149535723176508575932662800702e+4932");
155
156   SmallString<32> DefPrefix;
157   DefPrefix = "__";
158   DefPrefix += Prefix;
159   DefPrefix += "_";
160
161   Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
162   Builder.defineMacro(DefPrefix + "HAS_DENORM__");
163   Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
164   Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits));
165   Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext);
166   Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
167   Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
168   Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits));
169
170   Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp));
171   Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp));
172   Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext);
173
174   Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")");
175   Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")");
176   Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext);
177 }
178
179
180 /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
181 /// named MacroName with the max value for a type with width 'TypeWidth' a
182 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
183 static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth,
184                            StringRef ValSuffix, bool isSigned,
185                            MacroBuilder &Builder) {
186   llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth)
187                                 : llvm::APInt::getMaxValue(TypeWidth);
188   Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix);
189 }
190
191 /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine
192 /// the width, suffix, and signedness of the given type
193 static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
194                            const TargetInfo &TI, MacroBuilder &Builder) {
195   DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty), 
196                  TI.isTypeSigned(Ty), Builder);
197 }
198
199 static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty,
200                       const TargetInfo &TI, MacroBuilder &Builder) {
201   bool IsSigned = TI.isTypeSigned(Ty);
202   StringRef FmtModifier = TI.getTypeFormatModifier(Ty);
203   for (const char *Fmt = IsSigned ? "di" : "ouxX"; *Fmt; ++Fmt) {
204     Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__",
205                         Twine("\"") + FmtModifier + Twine(*Fmt) + "\"");
206   }
207 }
208
209 static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty,
210                        MacroBuilder &Builder) {
211   Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
212 }
213
214 static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty,
215                             const TargetInfo &TI, MacroBuilder &Builder) {
216   Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty)));
217 }
218
219 static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth,
220                              const TargetInfo &TI, MacroBuilder &Builder) {
221   Builder.defineMacro(MacroName,
222                       Twine(BitWidth / TI.getCharWidth()));
223 }
224
225 static void DefineExactWidthIntType(TargetInfo::IntType Ty,
226                                     const TargetInfo &TI,
227                                     MacroBuilder &Builder) {
228   int TypeWidth = TI.getTypeWidth(Ty);
229   bool IsSigned = TI.isTypeSigned(Ty);
230
231   // Use the target specified int64 type, when appropriate, so that [u]int64_t
232   // ends up being defined in terms of the correct type.
233   if (TypeWidth == 64)
234     Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
235
236   const char *Prefix = IsSigned ? "__INT" : "__UINT";
237
238   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
239   DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
240
241   StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty));
242   Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix);
243 }
244
245 static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
246                                         const TargetInfo &TI,
247                                         MacroBuilder &Builder) {
248   int TypeWidth = TI.getTypeWidth(Ty);
249   bool IsSigned = TI.isTypeSigned(Ty);
250
251   // Use the target specified int64 type, when appropriate, so that [u]int64_t
252   // ends up being defined in terms of the correct type.
253   if (TypeWidth == 64)
254     Ty = IsSigned ? TI.getInt64Type() : TI.getUInt64Type();
255
256   const char *Prefix = IsSigned ? "__INT" : "__UINT";
257   DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
258 }
259
260 static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
261                                     const TargetInfo &TI,
262                                     MacroBuilder &Builder) {
263   TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
264   if (Ty == TargetInfo::NoInt)
265     return;
266
267   const char *Prefix = IsSigned ? "__INT_LEAST" : "__UINT_LEAST";
268   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
269   DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
270   DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
271 }
272
273 static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
274                               const TargetInfo &TI, MacroBuilder &Builder) {
275   // stdint.h currently defines the fast int types as equivalent to the least
276   // types.
277   TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned);
278   if (Ty == TargetInfo::NoInt)
279     return;
280
281   const char *Prefix = IsSigned ? "__INT_FAST" : "__UINT_FAST";
282   DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder);
283   DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder);
284
285   DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder);
286 }
287
288
289 /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
290 /// the specified properties.
291 static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
292                                     unsigned InlineWidth) {
293   // Fully-aligned, power-of-2 sizes no larger than the inline
294   // width will be inlined as lock-free operations.
295   if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
296       TypeWidth <= InlineWidth)
297     return "2"; // "always lock free"
298   // We cannot be certain what operations the lib calls might be
299   // able to implement as lock-free on future processors.
300   return "1"; // "sometimes lock free"
301 }
302
303 /// \brief Add definitions required for a smooth interaction between
304 /// Objective-C++ automated reference counting and libstdc++ (4.2).
305 static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts, 
306                                          MacroBuilder &Builder) {
307   Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR");
308   
309   std::string Result;
310   {
311     // Provide specializations for the __is_scalar type trait so that 
312     // lifetime-qualified objects are not considered "scalar" types, which
313     // libstdc++ uses as an indicator of the presence of trivial copy, assign,
314     // default-construct, and destruct semantics (none of which hold for
315     // lifetime-qualified objects in ARC).
316     llvm::raw_string_ostream Out(Result);
317     
318     Out << "namespace std {\n"
319         << "\n"
320         << "struct __true_type;\n"
321         << "struct __false_type;\n"
322         << "\n";
323     
324     Out << "template<typename _Tp> struct __is_scalar;\n"
325         << "\n";
326       
327     Out << "template<typename _Tp>\n"
328         << "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n"
329         << "  enum { __value = 0 };\n"
330         << "  typedef __false_type __type;\n"
331         << "};\n"
332         << "\n";
333       
334     if (LangOpts.ObjCARCWeak) {
335       Out << "template<typename _Tp>\n"
336           << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n"
337           << "  enum { __value = 0 };\n"
338           << "  typedef __false_type __type;\n"
339           << "};\n"
340           << "\n";
341     }
342     
343     Out << "template<typename _Tp>\n"
344         << "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))"
345         << " _Tp> {\n"
346         << "  enum { __value = 0 };\n"
347         << "  typedef __false_type __type;\n"
348         << "};\n"
349         << "\n";
350       
351     Out << "}\n";
352   }
353   Builder.append(Result);
354 }
355
356 static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
357                                                const LangOptions &LangOpts,
358                                                const FrontendOptions &FEOpts,
359                                                MacroBuilder &Builder) {
360   if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP)
361     Builder.defineMacro("__STDC__");
362   if (LangOpts.Freestanding)
363     Builder.defineMacro("__STDC_HOSTED__", "0");
364   else
365     Builder.defineMacro("__STDC_HOSTED__");
366
367   if (!LangOpts.CPlusPlus) {
368     if (LangOpts.C11)
369       Builder.defineMacro("__STDC_VERSION__", "201112L");
370     else if (LangOpts.C99)
371       Builder.defineMacro("__STDC_VERSION__", "199901L");
372     else if (!LangOpts.GNUMode && LangOpts.Digraphs)
373       Builder.defineMacro("__STDC_VERSION__", "199409L");
374   } else {
375     // FIXME: Use correct value for C++17.
376     if (LangOpts.CPlusPlus1z)
377       Builder.defineMacro("__cplusplus", "201406L");
378     // C++1y [cpp.predefined]p1:
379     //   The name __cplusplus is defined to the value 201402L when compiling a
380     //   C++ translation unit.
381     else if (LangOpts.CPlusPlus14)
382       Builder.defineMacro("__cplusplus", "201402L");
383     // C++11 [cpp.predefined]p1:
384     //   The name __cplusplus is defined to the value 201103L when compiling a
385     //   C++ translation unit.
386     else if (LangOpts.CPlusPlus11)
387       Builder.defineMacro("__cplusplus", "201103L");
388     // C++03 [cpp.predefined]p1:
389     //   The name __cplusplus is defined to the value 199711L when compiling a
390     //   C++ translation unit.
391     else
392       Builder.defineMacro("__cplusplus", "199711L");
393   }
394
395   // In C11 these are environment macros. In C++11 they are only defined
396   // as part of <cuchar>. To prevent breakage when mixing C and C++
397   // code, define these macros unconditionally. We can define them
398   // unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit
399   // and 32-bit character literals.
400   Builder.defineMacro("__STDC_UTF_16__", "1");
401   Builder.defineMacro("__STDC_UTF_32__", "1");
402
403   if (LangOpts.ObjC1)
404     Builder.defineMacro("__OBJC__");
405
406   // Not "standard" per se, but available even with the -undef flag.
407   if (LangOpts.AsmPreprocessor)
408     Builder.defineMacro("__ASSEMBLER__");
409 }
410
411 /// Initialize the predefined C++ language feature test macros defined in
412 /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations".
413 static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
414                                                  MacroBuilder &Builder) {
415   // C++98 features.
416   if (LangOpts.RTTI)
417     Builder.defineMacro("__cpp_rtti", "199711");
418   if (LangOpts.CXXExceptions)
419     Builder.defineMacro("__cpp_exceptions", "199711");
420
421   // C++11 features.
422   if (LangOpts.CPlusPlus11) {
423     Builder.defineMacro("__cpp_unicode_characters", "200704");
424     Builder.defineMacro("__cpp_raw_strings", "200710");
425     Builder.defineMacro("__cpp_unicode_literals", "200710");
426     Builder.defineMacro("__cpp_user_defined_literals", "200809");
427     Builder.defineMacro("__cpp_lambdas", "200907");
428     Builder.defineMacro("__cpp_constexpr",
429                         LangOpts.CPlusPlus14 ? "201304" : "200704");
430     Builder.defineMacro("__cpp_range_based_for", "200907");
431     Builder.defineMacro("__cpp_static_assert", "200410");
432     Builder.defineMacro("__cpp_decltype", "200707");
433     Builder.defineMacro("__cpp_attributes", "200809");
434     Builder.defineMacro("__cpp_rvalue_references", "200610");
435     Builder.defineMacro("__cpp_variadic_templates", "200704");
436     Builder.defineMacro("__cpp_initializer_lists", "200806");
437     Builder.defineMacro("__cpp_delegating_constructors", "200604");
438     Builder.defineMacro("__cpp_nsdmi", "200809");
439     Builder.defineMacro("__cpp_inheriting_constructors", "200802");
440     Builder.defineMacro("__cpp_ref_qualifiers", "200710");
441     Builder.defineMacro("__cpp_alias_templates", "200704");
442   }
443
444   // C++14 features.
445   if (LangOpts.CPlusPlus14) {
446     Builder.defineMacro("__cpp_binary_literals", "201304");
447     Builder.defineMacro("__cpp_digit_separators", "201309");
448     Builder.defineMacro("__cpp_init_captures", "201304");
449     Builder.defineMacro("__cpp_generic_lambdas", "201304");
450     Builder.defineMacro("__cpp_decltype_auto", "201304");
451     Builder.defineMacro("__cpp_return_type_deduction", "201304");
452     Builder.defineMacro("__cpp_aggregate_nsdmi", "201304");
453     Builder.defineMacro("__cpp_variable_templates", "201304");
454   }
455   if (LangOpts.SizedDeallocation)
456     Builder.defineMacro("__cpp_sized_deallocation", "201309");
457   if (LangOpts.ConceptsTS)
458     Builder.defineMacro("__cpp_experimental_concepts", "1");
459 }
460
461 static void InitializePredefinedMacros(const TargetInfo &TI,
462                                        const LangOptions &LangOpts,
463                                        const FrontendOptions &FEOpts,
464                                        MacroBuilder &Builder) {
465   // Compiler version introspection macros.
466   Builder.defineMacro("__llvm__");  // LLVM Backend
467   Builder.defineMacro("__clang__"); // Clang Frontend
468 #define TOSTR2(X) #X
469 #define TOSTR(X) TOSTR2(X)
470   Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
471   Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
472 #ifdef CLANG_VERSION_PATCHLEVEL
473   Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
474 #else
475   Builder.defineMacro("__clang_patchlevel__", "0");
476 #endif
477   Builder.defineMacro("__clang_version__", 
478                       "\"" CLANG_VERSION_STRING " "
479                       + getClangFullRepositoryVersion() + "\"");
480 #undef TOSTR
481 #undef TOSTR2
482   if (!LangOpts.MSVCCompat) {
483     // Currently claim to be compatible with GCC 4.2.1-5621, but only if we're
484     // not compiling for MSVC compatibility
485     Builder.defineMacro("__GNUC_MINOR__", "2");
486     Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
487     Builder.defineMacro("__GNUC__", "4");
488     Builder.defineMacro("__GXX_ABI_VERSION", "1002");
489   }
490
491   // Define macros for the C11 / C++11 memory orderings
492   Builder.defineMacro("__ATOMIC_RELAXED", "0");
493   Builder.defineMacro("__ATOMIC_CONSUME", "1");
494   Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
495   Builder.defineMacro("__ATOMIC_RELEASE", "3");
496   Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
497   Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
498
499   // Support for #pragma redefine_extname (Sun compatibility)
500   Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
501
502   // As sad as it is, enough software depends on the __VERSION__ for version
503   // checks that it is necessary to report 4.2.1 (the base GCC version we claim
504   // compatibility with) first.
505   Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible " + 
506                       Twine(getClangFullCPPVersion()) + "\"");
507
508   // Initialize language-specific preprocessor defines.
509
510   // Standard conforming mode?
511   if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
512     Builder.defineMacro("__STRICT_ANSI__");
513
514   if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus11)
515     Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
516
517   if (LangOpts.ObjC1) {
518     if (LangOpts.ObjCRuntime.isNonFragile()) {
519       Builder.defineMacro("__OBJC2__");
520       
521       if (LangOpts.ObjCExceptions)
522         Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
523     }
524
525     if (LangOpts.getGC() != LangOptions::NonGC)
526       Builder.defineMacro("__OBJC_GC__");
527
528     if (LangOpts.ObjCRuntime.isNeXTFamily())
529       Builder.defineMacro("__NEXT_RUNTIME__");
530
531     if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
532       VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
533
534       unsigned minor = 0;
535       if (tuple.getMinor().hasValue())
536         minor = tuple.getMinor().getValue();
537
538       unsigned subminor = 0;
539       if (tuple.getSubminor().hasValue())
540         subminor = tuple.getSubminor().getValue();
541
542       Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
543                           Twine(tuple.getMajor() * 10000 + minor * 100 +
544                                 subminor));
545     }
546
547     Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
548     Builder.defineMacro("IBOutletCollection(ClassName)",
549                         "__attribute__((iboutletcollection(ClassName)))");
550     Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
551     Builder.defineMacro("IBInspectable", "");
552     Builder.defineMacro("IB_DESIGNABLE", "");
553   }
554
555   if (LangOpts.CPlusPlus)
556     InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
557
558   // darwin_constant_cfstrings controls this. This is also dependent
559   // on other things like the runtime I believe.  This is set even for C code.
560   if (!LangOpts.NoConstantCFStrings)
561       Builder.defineMacro("__CONSTANT_CFSTRINGS__");
562
563   if (LangOpts.ObjC2)
564     Builder.defineMacro("OBJC_NEW_PROPERTIES");
565
566   if (LangOpts.PascalStrings)
567     Builder.defineMacro("__PASCAL_STRINGS__");
568
569   if (LangOpts.Blocks) {
570     Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
571     Builder.defineMacro("__BLOCKS__");
572   }
573
574   if (!LangOpts.MSVCCompat && LangOpts.Exceptions)
575     Builder.defineMacro("__EXCEPTIONS");
576   if (!LangOpts.MSVCCompat && LangOpts.RTTI)
577     Builder.defineMacro("__GXX_RTTI");
578   if (LangOpts.SjLjExceptions)
579     Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
580
581   if (LangOpts.Deprecated)
582     Builder.defineMacro("__DEPRECATED");
583
584   if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus) {
585     Builder.defineMacro("__GNUG__", "4");
586     Builder.defineMacro("__GXX_WEAK__");
587     Builder.defineMacro("__private_extern__", "extern");
588   }
589
590   if (LangOpts.MicrosoftExt) {
591     if (LangOpts.WChar) {
592       // wchar_t supported as a keyword.
593       Builder.defineMacro("_WCHAR_T_DEFINED");
594       Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
595     }
596   }
597
598   if (LangOpts.Optimize)
599     Builder.defineMacro("__OPTIMIZE__");
600   if (LangOpts.OptimizeSize)
601     Builder.defineMacro("__OPTIMIZE_SIZE__");
602
603   if (LangOpts.FastMath)
604     Builder.defineMacro("__FAST_MATH__");
605
606   // Initialize target-specific preprocessor defines.
607
608   // __BYTE_ORDER__ was added in GCC 4.6. It's analogous
609   // to the macro __BYTE_ORDER (no trailing underscores)
610   // from glibc's <endian.h> header.
611   // We don't support the PDP-11 as a target, but include
612   // the define so it can still be compared against.
613   Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
614   Builder.defineMacro("__ORDER_BIG_ENDIAN__",    "4321");
615   Builder.defineMacro("__ORDER_PDP_ENDIAN__",    "3412");
616   if (TI.isBigEndian()) {
617     Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
618     Builder.defineMacro("__BIG_ENDIAN__");
619   } else {
620     Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
621     Builder.defineMacro("__LITTLE_ENDIAN__");
622   }
623
624   if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
625       && TI.getIntWidth() == 32) {
626     Builder.defineMacro("_LP64");
627     Builder.defineMacro("__LP64__");
628   }
629
630   if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
631       && TI.getIntWidth() == 32) {
632     Builder.defineMacro("_ILP32");
633     Builder.defineMacro("__ILP32__");
634   }
635
636   // Define type sizing macros based on the target properties.
637   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
638   Builder.defineMacro("__CHAR_BIT__", "8");
639
640   DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
641   DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
642   DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
643   DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
644   DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
645   DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
646   DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
647   DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
648
649   DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
650   DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
651   DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
652   DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
653
654   DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
655   DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
656   DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
657   DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
658   DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
659   DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
660   DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
661   DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
662   DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
663                    TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
664   DefineTypeSizeof("__SIZEOF_SIZE_T__",
665                    TI.getTypeWidth(TI.getSizeType()), TI, Builder);
666   DefineTypeSizeof("__SIZEOF_WCHAR_T__",
667                    TI.getTypeWidth(TI.getWCharType()), TI, Builder);
668   DefineTypeSizeof("__SIZEOF_WINT_T__",
669                    TI.getTypeWidth(TI.getWIntType()), TI, Builder);
670   if (TI.hasInt128Type())
671     DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
672
673   DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
674   DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
675   Builder.defineMacro("__INTMAX_C_SUFFIX__",
676                       TI.getTypeConstantSuffix(TI.getIntMaxType()));
677   DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
678   DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
679   Builder.defineMacro("__UINTMAX_C_SUFFIX__",
680                       TI.getTypeConstantSuffix(TI.getUIntMaxType()));
681   DefineTypeWidth("__INTMAX_WIDTH__",  TI.getIntMaxType(), TI, Builder);
682   DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
683   DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
684   DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
685   DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
686   DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
687   DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
688   DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
689   DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
690   DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
691   DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
692   DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
693   DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
694   DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
695   DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
696   DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
697   DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
698   DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
699
700   DefineTypeWidth("__UINTMAX_WIDTH__",  TI.getUIntMaxType(), TI, Builder);
701   DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
702   DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
703   DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
704
705   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
706   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
707   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
708
709   // Define a __POINTER_WIDTH__ macro for stdint.h.
710   Builder.defineMacro("__POINTER_WIDTH__",
711                       Twine((int)TI.getPointerWidth(0)));
712
713   // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
714   Builder.defineMacro("__BIGGEST_ALIGNMENT__",
715                       Twine(TI.getSuitableAlign() / TI.getCharWidth()) );
716
717   if (!LangOpts.CharIsSigned)
718     Builder.defineMacro("__CHAR_UNSIGNED__");
719
720   if (!TargetInfo::isTypeSigned(TI.getWCharType()))
721     Builder.defineMacro("__WCHAR_UNSIGNED__");
722
723   if (!TargetInfo::isTypeSigned(TI.getWIntType()))
724     Builder.defineMacro("__WINT_UNSIGNED__");
725
726   // Define exact-width integer types for stdint.h
727   DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder);
728
729   if (TI.getShortWidth() > TI.getCharWidth())
730     DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
731
732   if (TI.getIntWidth() > TI.getShortWidth())
733     DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
734
735   if (TI.getLongWidth() > TI.getIntWidth())
736     DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
737
738   if (TI.getLongLongWidth() > TI.getLongWidth())
739     DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
740
741   DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
742   DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
743   DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
744
745   if (TI.getShortWidth() > TI.getCharWidth()) {
746     DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
747     DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
748     DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
749   }
750
751   if (TI.getIntWidth() > TI.getShortWidth()) {
752     DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
753     DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
754     DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
755   }
756
757   if (TI.getLongWidth() > TI.getIntWidth()) {
758     DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
759     DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
760     DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
761   }
762
763   if (TI.getLongLongWidth() > TI.getLongWidth()) {
764     DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
765     DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
766     DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
767   }
768
769   DefineLeastWidthIntType(8, true, TI, Builder);
770   DefineLeastWidthIntType(8, false, TI, Builder);
771   DefineLeastWidthIntType(16, true, TI, Builder);
772   DefineLeastWidthIntType(16, false, TI, Builder);
773   DefineLeastWidthIntType(32, true, TI, Builder);
774   DefineLeastWidthIntType(32, false, TI, Builder);
775   DefineLeastWidthIntType(64, true, TI, Builder);
776   DefineLeastWidthIntType(64, false, TI, Builder);
777
778   DefineFastIntType(8, true, TI, Builder);
779   DefineFastIntType(8, false, TI, Builder);
780   DefineFastIntType(16, true, TI, Builder);
781   DefineFastIntType(16, false, TI, Builder);
782   DefineFastIntType(32, true, TI, Builder);
783   DefineFastIntType(32, false, TI, Builder);
784   DefineFastIntType(64, true, TI, Builder);
785   DefineFastIntType(64, false, TI, Builder);
786
787   if (const char *Prefix = TI.getUserLabelPrefix())
788     Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
789
790   if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
791     Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
792   else
793     Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
794
795   if (!LangOpts.MSVCCompat) {
796     if (LangOpts.GNUInline || LangOpts.CPlusPlus)
797       Builder.defineMacro("__GNUC_GNU_INLINE__");
798     else
799       Builder.defineMacro("__GNUC_STDC_INLINE__");
800
801     // The value written by __atomic_test_and_set.
802     // FIXME: This is target-dependent.
803     Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
804
805     // Used by libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
806     unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
807 #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
808     Builder.defineMacro("__GCC_ATOMIC_" #TYPE "_LOCK_FREE", \
809                         getLockFreeValue(TI.get##Type##Width(), \
810                                          TI.get##Type##Align(), \
811                                          InlineWidthBits));
812     DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
813     DEFINE_LOCK_FREE_MACRO(CHAR, Char);
814     DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
815     DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
816     DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
817     DEFINE_LOCK_FREE_MACRO(SHORT, Short);
818     DEFINE_LOCK_FREE_MACRO(INT, Int);
819     DEFINE_LOCK_FREE_MACRO(LONG, Long);
820     DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
821     Builder.defineMacro("__GCC_ATOMIC_POINTER_LOCK_FREE",
822                         getLockFreeValue(TI.getPointerWidth(0),
823                                          TI.getPointerAlign(0),
824                                          InlineWidthBits));
825 #undef DEFINE_LOCK_FREE_MACRO
826   }
827
828   if (LangOpts.NoInlineDefine)
829     Builder.defineMacro("__NO_INLINE__");
830
831   if (unsigned PICLevel = LangOpts.PICLevel) {
832     Builder.defineMacro("__PIC__", Twine(PICLevel));
833     Builder.defineMacro("__pic__", Twine(PICLevel));
834   }
835   if (unsigned PIELevel = LangOpts.PIELevel) {
836     Builder.defineMacro("__PIE__", Twine(PIELevel));
837     Builder.defineMacro("__pie__", Twine(PIELevel));
838   }
839
840   // Macros to control C99 numerics and <float.h>
841   Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
842   Builder.defineMacro("__FLT_RADIX__", "2");
843   Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");
844
845   if (LangOpts.getStackProtector() == LangOptions::SSPOn)
846     Builder.defineMacro("__SSP__");
847   else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
848     Builder.defineMacro("__SSP_STRONG__", "2");
849   else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
850     Builder.defineMacro("__SSP_ALL__", "3");
851
852   if (FEOpts.ProgramAction == frontend::RewriteObjC)
853     Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
854
855   // Define a macro that exists only when using the static analyzer.
856   if (FEOpts.ProgramAction == frontend::RunAnalysis)
857     Builder.defineMacro("__clang_analyzer__");
858
859   if (LangOpts.FastRelaxedMath)
860     Builder.defineMacro("__FAST_RELAXED_MATH__");
861
862   if (LangOpts.ObjCAutoRefCount) {
863     Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
864     Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
865     Builder.defineMacro("__autoreleasing",
866                         "__attribute__((objc_ownership(autoreleasing)))");
867     Builder.defineMacro("__unsafe_unretained",
868                         "__attribute__((objc_ownership(none)))");
869   }
870
871   // On Darwin, there are __double_underscored variants of the type
872   // nullability qualifiers.
873   if (TI.getTriple().isOSDarwin()) {
874     Builder.defineMacro("__nonnull", "_Nonnull");
875     Builder.defineMacro("__null_unspecified", "_Null_unspecified");
876     Builder.defineMacro("__nullable", "_Nullable");
877   }
878
879   // OpenMP definition
880   if (LangOpts.OpenMP) {
881     // OpenMP 2.2:
882     //   In implementations that support a preprocessor, the _OPENMP
883     //   macro name is defined to have the decimal value yyyymm where
884     //   yyyy and mm are the year and the month designations of the
885     //   version of the OpenMP API that the implementation support.
886     Builder.defineMacro("_OPENMP", "201307");
887   }
888
889   // CUDA device path compilaton
890   if (LangOpts.CUDAIsDevice) {
891     // The CUDA_ARCH value is set for the GPU target specified in the NVPTX
892     // backend's target defines.
893     Builder.defineMacro("__CUDA_ARCH__");
894   }
895
896   // Get other target #defines.
897   TI.getTargetDefines(LangOpts, Builder);
898 }
899
900 /// InitializePreprocessor - Initialize the preprocessor getting it and the
901 /// environment ready to process a single file. This returns true on error.
902 ///
903 void clang::InitializePreprocessor(
904     Preprocessor &PP, const PreprocessorOptions &InitOpts,
905     const PCHContainerReader &PCHContainerRdr,
906     const FrontendOptions &FEOpts) {
907   const LangOptions &LangOpts = PP.getLangOpts();
908   std::string PredefineBuffer;
909   PredefineBuffer.reserve(4080);
910   llvm::raw_string_ostream Predefines(PredefineBuffer);
911   MacroBuilder Builder(Predefines);
912
913   // Emit line markers for various builtin sections of the file.  We don't do
914   // this in asm preprocessor mode, because "# 4" is not a line marker directive
915   // in this mode.
916   if (!PP.getLangOpts().AsmPreprocessor)
917     Builder.append("# 1 \"<built-in>\" 3");
918
919   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
920   if (InitOpts.UsePredefines) {
921     InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder);
922
923     // Install definitions to make Objective-C++ ARC work well with various
924     // C++ Standard Library implementations.
925     if (LangOpts.ObjC1 && LangOpts.CPlusPlus && LangOpts.ObjCAutoRefCount) {
926       switch (InitOpts.ObjCXXARCStandardLibrary) {
927       case ARCXX_nolib:
928         case ARCXX_libcxx:
929         break;
930
931       case ARCXX_libstdcxx:
932         AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
933         break;
934       }
935     }
936   }
937   
938   // Even with predefines off, some macros are still predefined.
939   // These should all be defined in the preprocessor according to the
940   // current language configuration.
941   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
942                                      FEOpts, Builder);
943
944   // Add on the predefines from the driver.  Wrap in a #line directive to report
945   // that they come from the command line.
946   if (!PP.getLangOpts().AsmPreprocessor)
947     Builder.append("# 1 \"<command line>\" 1");
948
949   // Process #define's and #undef's in the order they are given.
950   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
951     if (InitOpts.Macros[i].second)  // isUndef
952       Builder.undefineMacro(InitOpts.Macros[i].first);
953     else
954       DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
955                          PP.getDiagnostics());
956   }
957
958   // If -imacros are specified, include them now.  These are processed before
959   // any -include directives.
960   for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
961     AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
962
963   // Process -include-pch/-include-pth directives.
964   if (!InitOpts.ImplicitPCHInclude.empty())
965     AddImplicitIncludePCH(Builder, PP, PCHContainerRdr,
966                           InitOpts.ImplicitPCHInclude);
967   if (!InitOpts.ImplicitPTHInclude.empty())
968     AddImplicitIncludePTH(Builder, PP, InitOpts.ImplicitPTHInclude);
969
970   // Process -include directives.
971   for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
972     const std::string &Path = InitOpts.Includes[i];
973     AddImplicitInclude(Builder, Path);
974   }
975
976   // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
977   if (!PP.getLangOpts().AsmPreprocessor)
978     Builder.append("# 1 \"<built-in>\" 2");
979
980   // Instruct the preprocessor to skip the preamble.
981   PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
982                              InitOpts.PrecompiledPreambleBytes.second);
983                           
984   // Copy PredefinedBuffer into the Preprocessor.
985   PP.setPredefines(Predefines.str());
986 }