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