xref: /llvm-project/clang/lib/Frontend/InitPreprocessor.cpp (revision d281a7146a15f4fe308b5d506a2d32c29c3ca2a0)
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/TargetInfo.h"
16 #include "clang/Frontend/FrontendDiagnostic.h"
17 #include "clang/Frontend/PreprocessorOptions.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Basic/FileManager.h"
20 #include "clang/Basic/SourceManager.h"
21 #include "llvm/ADT/APFloat.h"
22 #include "llvm/Support/MemoryBuffer.h"
23 #include "llvm/System/Path.h"
24 using namespace clang;
25 
26 // Append a #define line to Buf for Macro.  Macro should be of the form XXX,
27 // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
28 // "#define XXX Y z W".  To get a #define with no value, use "XXX=".
29 static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
30                                Diagnostic &Diags) {
31   std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('=');
32   llvm::StringRef MacroName = MacroPair.first;
33   llvm::StringRef MacroBody = MacroPair.second;
34   if (MacroName.size() != Macro.size()) {
35     // Per GCC -D semantics, the macro ends at \n if it exists.
36     llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r");
37     if (End != llvm::StringRef::npos)
38       Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
39         << MacroName;
40     Builder.defineMacro(MacroName, MacroBody.substr(0, End));
41   } else {
42     // Push "macroname 1".
43     Builder.defineMacro(Macro);
44   }
45 }
46 
47 std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
48   // Implicit include paths should be resolved relative to the current
49   // working directory first, and then use the regular header search
50   // mechanism. The proper way to handle this is to have the
51   // predefines buffer located at the current working directory, but
52   // it has not file entry. For now, workaround this by using an
53   // absolute path if we find the file here, and otherwise letting
54   // header search handle it.
55   llvm::sys::Path Path(File);
56   Path.makeAbsolute();
57   if (!Path.exists())
58     Path = File;
59 
60   return Lexer::Stringify(Path.str());
61 }
62 
63 /// AddImplicitInclude - Add an implicit #include of the specified file to the
64 /// predefines buffer.
65 static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File) {
66   Builder.append("#include \"" +
67                  llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
68 }
69 
70 static void AddImplicitIncludeMacros(MacroBuilder &Builder,
71                                      llvm::StringRef File) {
72   Builder.append("#__include_macros \"" +
73                  llvm::Twine(NormalizeDashIncludePath(File)) + "\"");
74   // Marker token to stop the __include_macros fetch loop.
75   Builder.append("##"); // ##?
76 }
77 
78 /// AddImplicitIncludePTH - Add an implicit #include using the original file
79 ///  used to generate a PTH cache.
80 static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP,
81                                   llvm::StringRef ImplicitIncludePTH) {
82   PTHManager *P = PP.getPTHManager();
83   assert(P && "No PTHManager.");
84   const char *OriginalFile = P->getOriginalSourceFile();
85 
86   if (!OriginalFile) {
87     PP.getDiagnostics().Report(diag::err_fe_pth_file_has_no_source_header)
88       << ImplicitIncludePTH;
89     return;
90   }
91 
92   AddImplicitInclude(Builder, OriginalFile);
93 }
94 
95 /// PickFP - This is used to pick a value based on the FP semantics of the
96 /// specified FP model.
97 template <typename T>
98 static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal,
99                 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
100                 T IEEEQuadVal) {
101   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle)
102     return IEEESingleVal;
103   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble)
104     return IEEEDoubleVal;
105   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended)
106     return X87DoubleExtendedVal;
107   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble)
108     return PPCDoubleDoubleVal;
109   assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad);
110   return IEEEQuadVal;
111 }
112 
113 static void DefineFloatMacros(MacroBuilder &Builder, llvm::StringRef Prefix,
114                               const llvm::fltSemantics *Sem) {
115   const char *DenormMin, *Epsilon, *Max, *Min;
116   DenormMin = PickFP(Sem, "1.40129846e-45F", "4.9406564584124654e-324",
117                      "3.64519953188247460253e-4951L",
118                      "4.94065645841246544176568792868221e-324L",
119                      "6.47517511943802511092443895822764655e-4966L");
120   int Digits = PickFP(Sem, 6, 15, 18, 31, 33);
121   Epsilon = PickFP(Sem, "1.19209290e-7F", "2.2204460492503131e-16",
122                    "1.08420217248550443401e-19L",
123                    "4.94065645841246544176568792868221e-324L",
124                    "1.92592994438723585305597794258492732e-34L");
125   int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113);
126   int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931);
127   int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932);
128   int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381);
129   int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384);
130   Min = PickFP(Sem, "1.17549435e-38F", "2.2250738585072014e-308",
131                "3.36210314311209350626e-4932L",
132                "2.00416836000897277799610805135016e-292L",
133                "3.36210314311209350626267781732175260e-4932L");
134   Max = PickFP(Sem, "3.40282347e+38F", "1.7976931348623157e+308",
135                "1.18973149535723176502e+4932L",
136                "1.79769313486231580793728971405301e+308L",
137                "1.18973149535723176508575932662800702e+4932L");
138 
139   llvm::Twine DefPrefix = "__" + Prefix + "_";
140 
141   Builder.defineMacro(DefPrefix + "DENORM_MIN__", DenormMin);
142   Builder.defineMacro(DefPrefix + "HAS_DENORM__");
143   Builder.defineMacro(DefPrefix + "DIG__", llvm::Twine(Digits));
144   Builder.defineMacro(DefPrefix + "EPSILON__", llvm::Twine(Epsilon));
145   Builder.defineMacro(DefPrefix + "HAS_INFINITY__");
146   Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__");
147   Builder.defineMacro(DefPrefix + "MANT_DIG__", llvm::Twine(MantissaDigits));
148 
149   Builder.defineMacro(DefPrefix + "MAX_10_EXP__", llvm::Twine(Max10Exp));
150   Builder.defineMacro(DefPrefix + "MAX_EXP__", llvm::Twine(MaxExp));
151   Builder.defineMacro(DefPrefix + "MAX__", llvm::Twine(Max));
152 
153   Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+llvm::Twine(Min10Exp)+")");
154   Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+llvm::Twine(MinExp)+")");
155   Builder.defineMacro(DefPrefix + "MIN__", llvm::Twine(Min));
156 }
157 
158 
159 /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
160 /// named MacroName with the max value for a type with width 'TypeWidth' a
161 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
162 static void DefineTypeSize(llvm::StringRef MacroName, unsigned TypeWidth,
163                            llvm::StringRef ValSuffix, bool isSigned,
164                            MacroBuilder& Builder) {
165   long long MaxVal;
166   if (isSigned)
167     MaxVal = (1LL << (TypeWidth - 1)) - 1;
168   else
169     MaxVal = ~0LL >> (64-TypeWidth);
170 
171   Builder.defineMacro(MacroName, llvm::Twine(MaxVal) + 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(llvm::StringRef 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 DefineType(const llvm::Twine &MacroName, TargetInfo::IntType Ty,
183                        MacroBuilder &Builder) {
184   Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty));
185 }
186 
187 static void DefineTypeWidth(llvm::StringRef MacroName, TargetInfo::IntType Ty,
188                             const TargetInfo &TI, MacroBuilder &Builder) {
189   Builder.defineMacro(MacroName, llvm::Twine(TI.getTypeWidth(Ty)));
190 }
191 
192 static void DefineExactWidthIntType(TargetInfo::IntType Ty,
193                                const TargetInfo &TI, MacroBuilder &Builder) {
194   int TypeWidth = TI.getTypeWidth(Ty);
195   DefineType("__INT" + llvm::Twine(TypeWidth) + "_TYPE__", Ty, Builder);
196 
197   llvm::StringRef ConstSuffix(TargetInfo::getTypeConstantSuffix(Ty));
198   if (!ConstSuffix.empty())
199     Builder.defineMacro("__INT" + llvm::Twine(TypeWidth) + "_C_SUFFIX__",
200                         ConstSuffix);
201 }
202 
203 static void InitializePredefinedMacros(const TargetInfo &TI,
204                                        const LangOptions &LangOpts,
205                                        MacroBuilder &Builder) {
206   // Compiler version introspection macros.
207   Builder.defineMacro("__llvm__");  // LLVM Backend
208   Builder.defineMacro("__clang__"); // Clang Frontend
209 
210   // Currently claim to be compatible with GCC 4.2.1-5621.
211   Builder.defineMacro("__GNUC_MINOR__", "2");
212   Builder.defineMacro("__GNUC_PATCHLEVEL__", "1");
213   Builder.defineMacro("__GNUC__", "4");
214   Builder.defineMacro("__GXX_ABI_VERSION", "1002");
215   Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible Clang Compiler\"");
216 
217   // Initialize language-specific preprocessor defines.
218 
219   // These should all be defined in the preprocessor according to the
220   // current language configuration.
221   if (!LangOpts.Microsoft)
222     Builder.defineMacro("__STDC__");
223   if (LangOpts.AsmPreprocessor)
224     Builder.defineMacro("__ASSEMBLER__");
225 
226   if (!LangOpts.CPlusPlus) {
227     if (LangOpts.C99)
228       Builder.defineMacro("__STDC_VERSION__", "199901L");
229     else if (!LangOpts.GNUMode && LangOpts.Digraphs)
230       Builder.defineMacro("__STDC_VERSION__", "199409L");
231   }
232 
233   // Standard conforming mode?
234   if (!LangOpts.GNUMode)
235     Builder.defineMacro("__STRICT_ANSI__");
236 
237   if (LangOpts.CPlusPlus0x)
238     Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
239 
240   if (LangOpts.Freestanding)
241     Builder.defineMacro("__STDC_HOSTED__", "0");
242   else
243     Builder.defineMacro("__STDC_HOSTED__");
244 
245   if (LangOpts.ObjC1) {
246     Builder.defineMacro("__OBJC__");
247     if (LangOpts.ObjCNonFragileABI) {
248       Builder.defineMacro("__OBJC2__");
249       Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS");
250     }
251 
252     if (LangOpts.getGCMode() != LangOptions::NonGC)
253       Builder.defineMacro("__OBJC_GC__");
254 
255     if (LangOpts.NeXTRuntime)
256       Builder.defineMacro("__NEXT_RUNTIME__");
257   }
258 
259   // darwin_constant_cfstrings controls this. This is also dependent
260   // on other things like the runtime I believe.  This is set even for C code.
261   Builder.defineMacro("__CONSTANT_CFSTRINGS__");
262 
263   if (LangOpts.ObjC2)
264     Builder.defineMacro("OBJC_NEW_PROPERTIES");
265 
266   if (LangOpts.PascalStrings)
267     Builder.defineMacro("__PASCAL_STRINGS__");
268 
269   if (LangOpts.Blocks) {
270     Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))");
271     Builder.defineMacro("__BLOCKS__");
272   }
273 
274   if (LangOpts.Exceptions)
275     Builder.defineMacro("__EXCEPTIONS");
276 
277   if (LangOpts.CPlusPlus) {
278     Builder.defineMacro("__DEPRECATED");
279     Builder.defineMacro("__GNUG__", "4");
280     Builder.defineMacro("__GXX_WEAK__");
281     if (LangOpts.GNUMode)
282       Builder.defineMacro("__cplusplus");
283     else
284       // C++ [cpp.predefined]p1:
285       //   The name_ _cplusplusis defined to the value199711Lwhen compiling a
286       //   C++ translation unit.
287       Builder.defineMacro("__cplusplus", "199711L");
288     Builder.defineMacro("__private_extern__", "extern");
289     // Ugly hack to work with GNU libstdc++.
290     Builder.defineMacro("_GNU_SOURCE");
291   }
292 
293   if (LangOpts.Microsoft) {
294     // Filter out some microsoft extensions when trying to parse in ms-compat
295     // mode.
296     Builder.defineMacro("__int8", "__INT8_TYPE__");
297     Builder.defineMacro("__int16", "__INT16_TYPE__");
298     Builder.defineMacro("__int32", "__INT32_TYPE__");
299     Builder.defineMacro("__int64", "__INT64_TYPE__");
300     // Both __PRETTY_FUNCTION__ and __FUNCTION__ are GCC extensions, however
301     // VC++ appears to only like __FUNCTION__.
302     Builder.defineMacro("__PRETTY_FUNCTION__", "__FUNCTION__");
303     // Work around some issues with Visual C++ headerws.
304     if (LangOpts.CPlusPlus) {
305       // Since we define wchar_t in C++ mode.
306       Builder.defineMacro("_WCHAR_T_DEFINED");
307       Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED");
308       // FIXME:  This should be temporary until we have a __pragma
309       // solution, to avoid some errors flagged in VC++ headers.
310       Builder.defineMacro("_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES", "0");
311     }
312   }
313 
314   if (LangOpts.Optimize)
315     Builder.defineMacro("__OPTIMIZE__");
316   if (LangOpts.OptimizeSize)
317     Builder.defineMacro("__OPTIMIZE_SIZE__");
318 
319   // Initialize target-specific preprocessor defines.
320 
321   // Define type sizing macros based on the target properties.
322   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
323   Builder.defineMacro("__CHAR_BIT__", "8");
324 
325   DefineTypeSize("__SCHAR_MAX__", TI.getCharWidth(), "", true, Builder);
326   DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder);
327   DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder);
328   DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder);
329   DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder);
330   DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder);
331   DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder);
332 
333   DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder);
334   DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder);
335   DefineTypeWidth("__INTMAX_WIDTH__",  TI.getIntMaxType(), TI, Builder);
336   DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder);
337   DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder);
338   DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder);
339   DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder);
340   DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder);
341   DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder);
342   DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
343   DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder);
344   DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
345   DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder);
346   DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder);
347 
348   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat());
349   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat());
350   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat());
351 
352   // Define a __POINTER_WIDTH__ macro for stdint.h.
353   Builder.defineMacro("__POINTER_WIDTH__",
354                       llvm::Twine((int)TI.getPointerWidth(0)));
355 
356   if (!LangOpts.CharIsSigned)
357     Builder.defineMacro("__CHAR_UNSIGNED__");
358 
359   // Define exact-width integer types for stdint.h
360   Builder.defineMacro("__INT" + llvm::Twine(TI.getCharWidth()) + "_TYPE__",
361                       "char");
362 
363   if (TI.getShortWidth() > TI.getCharWidth())
364     DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder);
365 
366   if (TI.getIntWidth() > TI.getShortWidth())
367     DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder);
368 
369   if (TI.getLongWidth() > TI.getIntWidth())
370     DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder);
371 
372   if (TI.getLongLongWidth() > TI.getLongWidth())
373     DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder);
374 
375   // Add __builtin_va_list typedef.
376   Builder.append(TI.getVAListDeclaration());
377 
378   if (const char *Prefix = TI.getUserLabelPrefix())
379     Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix);
380 
381   // Build configuration options.  FIXME: these should be controlled by
382   // command line options or something.
383   Builder.defineMacro("__FINITE_MATH_ONLY__", "0");
384 
385   if (LangOpts.GNUInline)
386     Builder.defineMacro("__GNUC_GNU_INLINE__");
387   else
388     Builder.defineMacro("__GNUC_STDC_INLINE__");
389 
390   if (LangOpts.NoInline)
391     Builder.defineMacro("__NO_INLINE__");
392 
393   if (unsigned PICLevel = LangOpts.PICLevel) {
394     Builder.defineMacro("__PIC__", llvm::Twine(PICLevel));
395     Builder.defineMacro("__pic__", llvm::Twine(PICLevel));
396   }
397 
398   // Macros to control C99 numerics and <float.h>
399   Builder.defineMacro("__FLT_EVAL_METHOD__", "0");
400   Builder.defineMacro("__FLT_RADIX__", "2");
401   int Dig = PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36);
402   Builder.defineMacro("__DECIMAL_DIG__", llvm::Twine(Dig));
403 
404   if (LangOpts.getStackProtectorMode() == LangOptions::SSPOn)
405     Builder.defineMacro("__SSP__");
406   else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq)
407     Builder.defineMacro("__SSP_ALL__", "2");
408 
409   // Get other target #defines.
410   TI.getTargetDefines(LangOpts, Builder);
411 }
412 
413 // Initialize the remapping of files to alternative contents, e.g.,
414 // those specified through other files.
415 static void InitializeFileRemapping(Diagnostic &Diags,
416                                     SourceManager &SourceMgr,
417                                     FileManager &FileMgr,
418                                     const PreprocessorOptions &InitOpts) {
419   // Remap files in the source manager.
420   for (PreprocessorOptions::remapped_file_iterator
421          Remap = InitOpts.remapped_file_begin(),
422          RemapEnd = InitOpts.remapped_file_end();
423        Remap != RemapEnd;
424        ++Remap) {
425     // Find the file that we're mapping to.
426     const FileEntry *ToFile = FileMgr.getFile(Remap->second);
427     if (!ToFile) {
428       Diags.Report(diag::err_fe_remap_missing_to_file)
429         << Remap->first << Remap->second;
430       continue;
431     }
432 
433     // Create the file entry for the file that we're mapping from.
434     const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first,
435                                                        ToFile->getSize(),
436                                                        0);
437     if (!FromFile) {
438       Diags.Report(diag::err_fe_remap_missing_from_file)
439         << Remap->first;
440       continue;
441     }
442 
443     // Load the contents of the file we're mapping to.
444     std::string ErrorStr;
445     const llvm::MemoryBuffer *Buffer
446       = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr);
447     if (!Buffer) {
448       Diags.Report(diag::err_fe_error_opening)
449         << Remap->second << ErrorStr;
450       continue;
451     }
452 
453     // Override the contents of the "from" file with the contents of
454     // the "to" file.
455     SourceMgr.overrideFileContents(FromFile, Buffer);
456   }
457 }
458 
459 /// InitializePreprocessor - Initialize the preprocessor getting it and the
460 /// environment ready to process a single file. This returns true on error.
461 ///
462 void clang::InitializePreprocessor(Preprocessor &PP,
463                                    const PreprocessorOptions &InitOpts,
464                                    const HeaderSearchOptions &HSOpts) {
465   std::string PredefineBuffer;
466   PredefineBuffer.reserve(4080);
467   llvm::raw_string_ostream Predefines(PredefineBuffer);
468   MacroBuilder Builder(Predefines);
469 
470   InitializeFileRemapping(PP.getDiagnostics(), PP.getSourceManager(),
471                           PP.getFileManager(), InitOpts);
472 
473   Builder.append("# 1 \"<built-in>\" 3");
474 
475   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
476   if (InitOpts.UsePredefines)
477     InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
478                                Builder);
479 
480   // Add on the predefines from the driver.  Wrap in a #line directive to report
481   // that they come from the command line.
482   Builder.append("# 1 \"<command line>\" 1");
483 
484   // Process #define's and #undef's in the order they are given.
485   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
486     if (InitOpts.Macros[i].second)  // isUndef
487       Builder.undefineMacro(InitOpts.Macros[i].first);
488     else
489       DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
490                          PP.getDiagnostics());
491   }
492 
493   // If -imacros are specified, include them now.  These are processed before
494   // any -include directives.
495   for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i)
496     AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]);
497 
498   // Process -include directives.
499   for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) {
500     const std::string &Path = InitOpts.Includes[i];
501     if (Path == InitOpts.ImplicitPTHInclude)
502       AddImplicitIncludePTH(Builder, PP, Path);
503     else
504       AddImplicitInclude(Builder, Path);
505   }
506 
507   // Exit the command line and go back to <built-in> (2 is LC_LEAVE).
508   Builder.append("# 1 \"<built-in>\" 2");
509 
510   // Copy PredefinedBuffer into the Preprocessor.
511   PP.setPredefines(Predefines.str());
512 
513   // Initialize the header search object.
514   ApplyHeaderSearchOptions(PP.getHeaderSearchInfo(), HSOpts,
515                            PP.getLangOptions(),
516                            PP.getTargetInfo().getTriple());
517 }
518