]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Frontend/InitPreprocessor.cpp
Merge clang 3.5.0 release from ^/vendor/clang/dist, resolve conflicts,
[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 static void AddImplicitInclude(MacroBuilder &Builder, StringRef File,
69                                FileManager &FileMgr) {
70   Builder.append(Twine("#include \"") +
71                  HeaderSearch::NormalizeDashIncludePath(File, FileMgr) + "\"");
72 }
73
74 static void AddImplicitIncludeMacros(MacroBuilder &Builder,
75                                      StringRef File,
76                                      FileManager &FileMgr) {
77   Builder.append(Twine("#__include_macros \"") +
78                  HeaderSearch::NormalizeDashIncludePath(File, FileMgr) + "\"");
79   // Marker token to stop the __include_macros fetch loop.
80   Builder.append("##"); // ##?
81 }
82
83 /// AddImplicitIncludePTH - Add an implicit \#include using the original file
84 /// used to generate a PTH cache.
85 static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
86                                   StringRef ImplicitIncludePTH) {
87   PTHManager *P = PP.getPTHManager();
88   // Null check 'P' in the corner case where it couldn't be created.
89   const char *OriginalFile = P ? P->getOriginalSourceFile() : nullptr;
90
91   if (!OriginalFile) {
92     PP.getDiagnostics().Report(diag::err_fe_pth_file_has_no_source_header)
93       << ImplicitIncludePTH;
94     return;
95   }
96
97   AddImplicitInclude(Builder, OriginalFile, PP.getFileManager());
98 }
99
100 /// \brief Add an implicit \#include using the original file used to generate
101 /// a PCH file.
102 static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP,
103                                   StringRef ImplicitIncludePCH) {
104   std::string OriginalFile =
105     ASTReader::getOriginalSourceFile(ImplicitIncludePCH, PP.getFileManager(),
106                                      PP.getDiagnostics());
107   if (OriginalFile.empty())
108     return;
109
110   AddImplicitInclude(Builder, OriginalFile, PP.getFileManager());
111 }
112
113 /// PickFP - This is used to pick a value based on the FP semantics of the
114 /// specified FP model.
115 template <typename T>
116 static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal,
117                 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
118                 T IEEEQuadVal) {
119   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle)
120     return IEEESingleVal;
121   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble)
122     return IEEEDoubleVal;
123   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended)
124     return X87DoubleExtendedVal;
125   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble)
126     return PPCDoubleDoubleVal;
127   assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad);
128   return IEEEQuadVal;
129 }
130
131 static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
132                               const llvm::fltSemantics *Sem, StringRef Ext) {
133   const char *DenormMin, *Epsilon, *Max, *Min;
134   DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324",
135                      "3.64519953188247460253e-4951",
136                      "4.94065645841246544176568792868221e-324",
137                      "6.47517511943802511092443895822764655e-4966");
138   int Digits = PickFP(Sem, 6, 15, 18, 31, 33);
139   Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16",
140                    "1.08420217248550443401e-19",
141                    "4.94065645841246544176568792868221e-324",
142                    "1.92592994438723585305597794258492732e-34");
143   int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113);
144   int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931);
145   int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932);
146   int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381);
147   int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384);
148   Min = PickFP(Sem, "1.17549435e-38", "2.2250738585072014e-308",
149                "3.36210314311209350626e-4932",
150                "2.00416836000897277799610805135016e-292",
151                "3.36210314311209350626267781732175260e-4932");
152   Max = PickFP(Sem, "3.40282347e+38", "1.7976931348623157e+308",
153                "1.18973149535723176502e+4932",
154                "1.79769313486231580793728971405301e+308",
155                "1.18973149535723176508575932662800702e+4932");
156
157   SmallString<32> DefPrefix;
158   DefPrefix = "__";
159   DefPrefix += Prefix;
160   DefPrefix += "_";
161
162   Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext);
163   Builder.defineMacro(DefPrefix + "HAS_DENORM__");
164   Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits));
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.CPlusPlus1y)
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++11 features.
416   if (LangOpts.CPlusPlus11) {
417     Builder.defineMacro("__cpp_unicode_characters", "200704");
418     Builder.defineMacro("__cpp_raw_strings", "200710");
419     Builder.defineMacro("__cpp_unicode_literals", "200710");
420     Builder.defineMacro("__cpp_user_defined_literals", "200809");
421     Builder.defineMacro("__cpp_lambdas", "200907");
422     Builder.defineMacro("__cpp_constexpr",
423                         LangOpts.CPlusPlus1y ? "201304" : "200704");
424     Builder.defineMacro("__cpp_static_assert", "200410");
425     Builder.defineMacro("__cpp_decltype", "200707");
426     Builder.defineMacro("__cpp_attributes", "200809");
427     Builder.defineMacro("__cpp_rvalue_references", "200610");
428     Builder.defineMacro("__cpp_variadic_templates", "200704");
429   }
430
431   // C++14 features.
432   if (LangOpts.CPlusPlus1y) {
433     Builder.defineMacro("__cpp_binary_literals", "201304");
434     Builder.defineMacro("__cpp_init_captures", "201304");
435     Builder.defineMacro("__cpp_generic_lambdas", "201304");
436     Builder.defineMacro("__cpp_decltype_auto", "201304");
437     Builder.defineMacro("__cpp_return_type_deduction", "201304");
438     Builder.defineMacro("__cpp_aggregate_nsdmi", "201304");
439     Builder.defineMacro("__cpp_variable_templates", "201304");
440   }
441 }
442
443 static void InitializePredefinedMacros(const TargetInfo &TI,
444                                        const LangOptions &LangOpts,
445                                        const FrontendOptions &FEOpts,
446                                        MacroBuilder &Builder) {
447   // Compiler version introspection macros.
448   Builder.defineMacro("__llvm__");  // LLVM Backend
449   Builder.defineMacro("__clang__"); // Clang Frontend
450 #define TOSTR2(X) #X
451 #define TOSTR(X) TOSTR2(X)
452   Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR));
453   Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR));
454 #ifdef CLANG_VERSION_PATCHLEVEL
455   Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL));
456 #else
457   Builder.defineMacro("__clang_patchlevel__", "0");
458 #endif
459   Builder.defineMacro("__clang_version__", 
460                       "\"" CLANG_VERSION_STRING " "
461                       + getClangFullRepositoryVersion() + "\"");
462 #undef TOSTR
463 #undef TOSTR2
464   if (!LangOpts.MSVCCompat) {
465     // Currently claim to be compatible with GCC 4.2.1-5621, but only if we're
466     // not compiling for MSVC compatibility
467     Builder.defineMacro("__GNUC_MINOR__", "2");
468     Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
469     Builder.defineMacro("__GNUC__", "4");
470     Builder.defineMacro("__GXX_ABI_VERSION", "1002");
471   }
472
473   // Define macros for the C11 / C++11 memory orderings
474   Builder.defineMacro("__ATOMIC_RELAXED", "0");
475   Builder.defineMacro("__ATOMIC_CONSUME", "1");
476   Builder.defineMacro("__ATOMIC_ACQUIRE", "2");
477   Builder.defineMacro("__ATOMIC_RELEASE", "3");
478   Builder.defineMacro("__ATOMIC_ACQ_REL", "4");
479   Builder.defineMacro("__ATOMIC_SEQ_CST", "5");
480
481   // Support for #pragma redefine_extname (Sun compatibility)
482   Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1");
483
484   // As sad as it is, enough software depends on the __VERSION__ for version
485   // checks that it is necessary to report 4.2.1 (the base GCC version we claim
486   // compatibility with) first.
487   Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible " + 
488                       Twine(getClangFullCPPVersion()) + "\"");
489
490   // Initialize language-specific preprocessor defines.
491
492   // Standard conforming mode?
493   if (!LangOpts.GNUMode && !LangOpts.MSVCCompat)
494     Builder.defineMacro("__STRICT_ANSI__");
495
496   if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus11)
497     Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
498
499   if (LangOpts.ObjC1) {
500     if (LangOpts.ObjCRuntime.isNonFragile()) {
501       Builder.defineMacro("__OBJC2__");
502       
503       if (LangOpts.ObjCExceptions)
504         Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
505     }
506
507     if (LangOpts.getGC() != LangOptions::NonGC)
508       Builder.defineMacro("__OBJC_GC__");
509
510     if (LangOpts.ObjCRuntime.isNeXTFamily())
511       Builder.defineMacro("__NEXT_RUNTIME__");
512
513     if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
514       VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
515
516       unsigned minor = 0;
517       if (tuple.getMinor().hasValue())
518         minor = tuple.getMinor().getValue();
519
520       unsigned subminor = 0;
521       if (tuple.getSubminor().hasValue())
522         subminor = tuple.getSubminor().getValue();
523
524       Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
525                           Twine(tuple.getMajor() * 10000 + minor * 100 +
526                                 subminor));
527     }
528
529     Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))");
530     Builder.defineMacro("IBOutletCollection(ClassName)",
531                         "__attribute__((iboutletcollection(ClassName)))");
532     Builder.defineMacro("IBAction", "void)__attribute__((ibaction)");
533   }
534
535   if (LangOpts.CPlusPlus)
536     InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder);
537
538   // darwin_constant_cfstrings controls this. This is also dependent
539   // on other things like the runtime I believe.  This is set even for C code.
540   if (!LangOpts.NoConstantCFStrings)
541       Builder.defineMacro("__CONSTANT_CFSTRINGS__");
542
543   if (LangOpts.ObjC2)
544     Builder.defineMacro("OBJC_NEW_PROPERTIES");
545
546   if (LangOpts.PascalStrings)
547     Builder.defineMacro("__PASCAL_STRINGS__");
548
549   if (LangOpts.Blocks) {
550     Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
551     Builder.defineMacro("__BLOCKS__");
552   }
553
554   if (!LangOpts.MSVCCompat && LangOpts.CXXExceptions)
555     Builder.defineMacro("__EXCEPTIONS");
556   if (!LangOpts.MSVCCompat && LangOpts.RTTI)
557     Builder.defineMacro("__GXX_RTTI");
558   if (LangOpts.SjLjExceptions)
559     Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
560
561   if (LangOpts.Deprecated)
562     Builder.defineMacro("__DEPRECATED");
563
564   if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus) {
565     Builder.defineMacro("__GNUG__", "4");
566     Builder.defineMacro("__GXX_WEAK__");
567     Builder.defineMacro("__private_extern__", "extern");
568   }
569
570   if (LangOpts.MicrosoftExt) {
571     if (LangOpts.WChar) {
572       // wchar_t supported as a keyword.
573       Builder.defineMacro("_WCHAR_T_DEFINED");
574       Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
575     }
576   }
577
578   if (LangOpts.Optimize)
579     Builder.defineMacro("__OPTIMIZE__");
580   if (LangOpts.OptimizeSize)
581     Builder.defineMacro("__OPTIMIZE_SIZE__");
582
583   if (LangOpts.FastMath)
584     Builder.defineMacro("__FAST_MATH__");
585
586   // Initialize target-specific preprocessor defines.
587
588   // __BYTE_ORDER__ was added in GCC 4.6. It's analogous
589   // to the macro __BYTE_ORDER (no trailing underscores)
590   // from glibc's <endian.h> header.
591   // We don't support the PDP-11 as a target, but include
592   // the define so it can still be compared against.
593   Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234");
594   Builder.defineMacro("__ORDER_BIG_ENDIAN__",    "4321");
595   Builder.defineMacro("__ORDER_PDP_ENDIAN__",    "3412");
596   if (TI.isBigEndian()) {
597     Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__");
598     Builder.defineMacro("__BIG_ENDIAN__");
599   } else {
600     Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__");
601     Builder.defineMacro("__LITTLE_ENDIAN__");
602   }
603
604   if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 64
605       && TI.getIntWidth() == 32) {
606     Builder.defineMacro("_LP64");
607     Builder.defineMacro("__LP64__");
608   }
609
610   if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 32
611       && TI.getIntWidth() == 32) {
612     Builder.defineMacro("_ILP32");
613     Builder.defineMacro("__ILP32__");
614   }
615
616   // Define type sizing macros based on the target properties.
617   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
618   Builder.defineMacro("__CHAR_BIT__", "8");
619
620   DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder);
621   DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
622   DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
623   DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
624   DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
625   DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
626   DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
627   DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder);
628
629   if (!LangOpts.MSVCCompat) {
630     DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder);
631     DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder);
632     DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder);
633     DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder);
634   }
635
636   DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder);
637   DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder);
638   DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder);
639   DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder);
640   DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder);
641   DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder);
642   DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder);
643   DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder);
644   DefineTypeSizeof("__SIZEOF_PTRDIFF_T__",
645                    TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder);
646   DefineTypeSizeof("__SIZEOF_SIZE_T__",
647                    TI.getTypeWidth(TI.getSizeType()), TI, Builder);
648   DefineTypeSizeof("__SIZEOF_WCHAR_T__",
649                    TI.getTypeWidth(TI.getWCharType()), TI, Builder);
650   DefineTypeSizeof("__SIZEOF_WINT_T__",
651                    TI.getTypeWidth(TI.getWIntType()), TI, Builder);
652   if (TI.hasInt128Type())
653     DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder);
654
655   DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
656   DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder);
657   Builder.defineMacro("__INTMAX_C_SUFFIX__",
658                       TI.getTypeConstantSuffix(TI.getIntMaxType()));
659   DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
660   DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder);
661   Builder.defineMacro("__UINTMAX_C_SUFFIX__",
662                       TI.getTypeConstantSuffix(TI.getUIntMaxType()));
663   DefineTypeWidth("__INTMAX_WIDTH__",  TI.getIntMaxType(), TI, Builder);
664   DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
665   DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder);
666   DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
667   DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
668   DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder);
669   DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
670   DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
671   DefineFmt("__SIZE", TI.getSizeType(), TI, Builder);
672   DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
673   DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
674   DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
675   DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
676   DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
677   DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
678   DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder);
679   DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder);
680   DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder);
681
682   if (!LangOpts.MSVCCompat) {
683     DefineTypeWidth("__UINTMAX_WIDTH__",  TI.getUIntMaxType(), TI, Builder);
684     DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder);
685     DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder);
686     DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder);
687   }
688
689   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
690   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
691   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
692
693   // Define a __POINTER_WIDTH__ macro for stdint.h.
694   Builder.defineMacro("__POINTER_WIDTH__",
695                       Twine((int)TI.getPointerWidth(0)));
696
697   if (!LangOpts.CharIsSigned)
698     Builder.defineMacro("__CHAR_UNSIGNED__");
699
700   if (!TargetInfo::isTypeSigned(TI.getWCharType()))
701     Builder.defineMacro("__WCHAR_UNSIGNED__");
702
703   if (!TargetInfo::isTypeSigned(TI.getWIntType()))
704     Builder.defineMacro("__WINT_UNSIGNED__");
705
706   // Define exact-width integer types for stdint.h
707   DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder);
708
709   if (TI.getShortWidth() > TI.getCharWidth())
710     DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
711
712   if (TI.getIntWidth() > TI.getShortWidth())
713     DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
714
715   if (TI.getLongWidth() > TI.getIntWidth())
716     DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
717
718   if (TI.getLongLongWidth() > TI.getLongWidth())
719     DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
720
721   if (!LangOpts.MSVCCompat) {
722     DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder);
723     DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder);
724     DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder);
725
726     if (TI.getShortWidth() > TI.getCharWidth()) {
727       DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder);
728       DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder);
729       DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder);
730     }
731
732     if (TI.getIntWidth() > TI.getShortWidth()) {
733       DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder);
734       DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder);
735       DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder);
736     }
737
738     if (TI.getLongWidth() > TI.getIntWidth()) {
739       DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder);
740       DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder);
741       DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder);
742     }
743
744     if (TI.getLongLongWidth() > TI.getLongWidth()) {
745       DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder);
746       DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder);
747       DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder);
748     }
749
750     DefineLeastWidthIntType(8, true, TI, Builder);
751     DefineLeastWidthIntType(8, false, TI, Builder);
752     DefineLeastWidthIntType(16, true, TI, Builder);
753     DefineLeastWidthIntType(16, false, TI, Builder);
754     DefineLeastWidthIntType(32, true, TI, Builder);
755     DefineLeastWidthIntType(32, false, TI, Builder);
756     DefineLeastWidthIntType(64, true, TI, Builder);
757     DefineLeastWidthIntType(64, false, TI, Builder);
758
759     DefineFastIntType(8, true, TI, Builder);
760     DefineFastIntType(8, false, TI, Builder);
761     DefineFastIntType(16, true, TI, Builder);
762     DefineFastIntType(16, false, TI, Builder);
763     DefineFastIntType(32, true, TI, Builder);
764     DefineFastIntType(32, false, TI, Builder);
765     DefineFastIntType(64, true, TI, Builder);
766     DefineFastIntType(64, false, TI, Builder);
767   }
768
769   if (const char *Prefix = TI.getUserLabelPrefix())
770     Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
771
772   if (LangOpts.FastMath || LangOpts.FiniteMathOnly)
773     Builder.defineMacro("__FINITE_MATH_ONLY__", "1");
774   else
775     Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
776
777   if (!LangOpts.MSVCCompat) {
778     if (LangOpts.GNUInline)
779       Builder.defineMacro("__GNUC_GNU_INLINE__");
780     else
781       Builder.defineMacro("__GNUC_STDC_INLINE__");
782
783     // The value written by __atomic_test_and_set.
784     // FIXME: This is target-dependent.
785     Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1");
786
787     // Used by libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
788     unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth();
789 #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
790     Builder.defineMacro("__GCC_ATOMIC_" #TYPE "_LOCK_FREE", \
791                         getLockFreeValue(TI.get##Type##Width(), \
792                                          TI.get##Type##Align(), \
793                                          InlineWidthBits));
794     DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
795     DEFINE_LOCK_FREE_MACRO(CHAR, Char);
796     DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
797     DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
798     DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
799     DEFINE_LOCK_FREE_MACRO(SHORT, Short);
800     DEFINE_LOCK_FREE_MACRO(INT, Int);
801     DEFINE_LOCK_FREE_MACRO(LONG, Long);
802     DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
803     Builder.defineMacro("__GCC_ATOMIC_POINTER_LOCK_FREE",
804                         getLockFreeValue(TI.getPointerWidth(0),
805                                          TI.getPointerAlign(0),
806                                          InlineWidthBits));
807 #undef DEFINE_LOCK_FREE_MACRO
808   }
809
810   if (LangOpts.NoInlineDefine)
811     Builder.defineMacro("__NO_INLINE__");
812
813   if (unsigned PICLevel = LangOpts.PICLevel) {
814     Builder.defineMacro("__PIC__", Twine(PICLevel));
815     Builder.defineMacro("__pic__", Twine(PICLevel));
816   }
817   if (unsigned PIELevel = LangOpts.PIELevel) {
818     Builder.defineMacro("__PIE__", Twine(PIELevel));
819     Builder.defineMacro("__pie__", Twine(PIELevel));
820   }
821
822   // Macros to control C99 numerics and <float.h>
823   Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
824   Builder.defineMacro("__FLT_RADIX__", "2");
825   int Dig = PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36);
826   Builder.defineMacro("__DECIMAL_DIG__", Twine(Dig));
827
828   if (LangOpts.getStackProtector() == LangOptions::SSPOn)
829     Builder.defineMacro("__SSP__");
830   else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
831     Builder.defineMacro("__SSP_STRONG__", "2");
832   else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
833     Builder.defineMacro("__SSP_ALL__", "3");
834
835   if (FEOpts.ProgramAction == frontend::RewriteObjC)
836     Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))");
837
838   // Define a macro that exists only when using the static analyzer.
839   if (FEOpts.ProgramAction == frontend::RunAnalysis)
840     Builder.defineMacro("__clang_analyzer__");
841
842   if (LangOpts.FastRelaxedMath)
843     Builder.defineMacro("__FAST_RELAXED_MATH__");
844
845   if (LangOpts.ObjCAutoRefCount) {
846     Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))");
847     Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))");
848     Builder.defineMacro("__autoreleasing",
849                         "__attribute__((objc_ownership(autoreleasing)))");
850     Builder.defineMacro("__unsafe_unretained",
851                         "__attribute__((objc_ownership(none)))");
852   }
853
854   // OpenMP definition
855   if (LangOpts.OpenMP) {
856     // OpenMP 2.2:
857     //   In implementations that support a preprocessor, the _OPENMP
858     //   macro name is defined to have the decimal value yyyymm where
859     //   yyyy and mm are the year and the month designations of the
860     //   version of the OpenMP API that the implementation support.
861     Builder.defineMacro("_OPENMP", "201307");
862   }
863
864   // Get other target #defines.
865   TI.getTargetDefines(LangOpts, Builder);
866 }
867
868 /// InitializePreprocessor - Initialize the preprocessor getting it and the
869 /// environment ready to process a single file. This returns true on error.
870 ///
871 void clang::InitializePreprocessor(Preprocessor &PP,
872                                    const PreprocessorOptions &InitOpts,
873                                    const FrontendOptions &FEOpts) {
874   const LangOptions &LangOpts = PP.getLangOpts();
875   std::string PredefineBuffer;
876   PredefineBuffer.reserve(4080);
877   llvm::raw_string_ostream Predefines(PredefineBuffer);
878   MacroBuilder Builder(Predefines);
879
880   // Emit line markers for various builtin sections of the file.  We don't do
881   // this in asm preprocessor mode, because "# 4" is not a line marker directive
882   // in this mode.
883   if (!PP.getLangOpts().AsmPreprocessor)
884     Builder.append("# 1 \"<built-in>\" 3");
885
886   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
887   if (InitOpts.UsePredefines) {
888     InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, Builder);
889
890     // Install definitions to make Objective-C++ ARC work well with various
891     // C++ Standard Library implementations.
892     if (LangOpts.ObjC1 && LangOpts.CPlusPlus && LangOpts.ObjCAutoRefCount) {
893       switch (InitOpts.ObjCXXARCStandardLibrary) {
894       case ARCXX_nolib:
895         case ARCXX_libcxx:
896         break;
897
898       case ARCXX_libstdcxx:
899         AddObjCXXARCLibstdcxxDefines(LangOpts, Builder);
900         break;
901       }
902     }
903   }
904   
905   // Even with predefines off, some macros are still predefined.
906   // These should all be defined in the preprocessor according to the
907   // current language configuration.
908   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
909                                      FEOpts, Builder);
910
911   // Add on the predefines from the driver.  Wrap in a #line directive to report
912   // that they come from the command line.
913   if (!PP.getLangOpts().AsmPreprocessor)
914     Builder.append("# 1 \"<command line>\" 1");
915
916   // Process #define's and #undef's in the order they are given.
917   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
918     if (InitOpts.Macros[i].second)  // isUndef
919       Builder.undefineMacro(InitOpts.Macros[i].first);
920     else
921       DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
922                          PP.getDiagnostics());
923   }
924
925   // If -imacros are specified, include them now.  These are processed before
926   // any -include directives.
927   for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
928     AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i],
929                              PP.getFileManager());
930
931   // Process -include-pch/-include-pth directives.
932   if (!InitOpts.ImplicitPCHInclude.empty())
933     AddImplicitIncludePCH(Builder, PP, InitOpts.ImplicitPCHInclude);
934   if (!InitOpts.ImplicitPTHInclude.empty())
935     AddImplicitIncludePTH(Builder, PP, InitOpts.ImplicitPTHInclude);
936
937   // Process -include directives.
938   for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
939     const std::string &Path = InitOpts.Includes[i];
940     AddImplicitInclude(Builder, Path, PP.getFileManager());
941   }
942
943   // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
944   if (!PP.getLangOpts().AsmPreprocessor)
945     Builder.append("# 1 \"<built-in>\" 2");
946
947   // Instruct the preprocessor to skip the preamble.
948   PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first,
949                              InitOpts.PrecompiledPreambleBytes.second);
950                           
951   // Copy PredefinedBuffer into the Preprocessor.
952   PP.setPredefines(Predefines.str());
953 }