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