Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Frontend/PrintPreprocessedOutput.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- PrintPreprocessedOutput.cpp - Implement the -E mode --------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This code simply runs the preprocessor on the input file and prints out the
10
// result.  This is the traditional behavior of the -E option.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "clang/Frontend/Utils.h"
15
#include "clang/Basic/CharInfo.h"
16
#include "clang/Basic/Diagnostic.h"
17
#include "clang/Basic/SourceManager.h"
18
#include "clang/Frontend/PreprocessorOutputOptions.h"
19
#include "clang/Lex/MacroInfo.h"
20
#include "clang/Lex/PPCallbacks.h"
21
#include "clang/Lex/Pragma.h"
22
#include "clang/Lex/Preprocessor.h"
23
#include "clang/Lex/TokenConcatenation.h"
24
#include "llvm/ADT/STLExtras.h"
25
#include "llvm/ADT/SmallString.h"
26
#include "llvm/ADT/StringRef.h"
27
#include "llvm/Support/ErrorHandling.h"
28
#include "llvm/Support/raw_ostream.h"
29
#include <cstdio>
30
using namespace clang;
31
32
/// PrintMacroDefinition - Print a macro definition in a form that will be
33
/// properly accepted back as a definition.
34
static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
35
490k
                                 Preprocessor &PP, raw_ostream &OS) {
36
490k
  OS << "#define " << II.getName();
37
38
490k
  if (MI.isFunctionLike()) {
39
35
    OS << '(';
40
35
    if (!MI.param_empty()) {
41
34
      MacroInfo::param_iterator AI = MI.param_begin(), E = MI.param_end();
42
37
      for (; AI+1 != E; 
++AI3
) {
43
3
        OS << (*AI)->getName();
44
3
        OS << ',';
45
3
      }
46
47
      // Last argument.
48
34
      if ((*AI)->getName() == "__VA_ARGS__")
49
2
        OS << "...";
50
32
      else
51
32
        OS << (*AI)->getName();
52
34
    }
53
54
35
    if (MI.isGNUVarargs())
55
1
      OS << "...";  // #define foo(x...)
56
57
35
    OS << ')';
58
35
  }
59
60
  // GCC always emits a space, even if the macro body is empty.  However, do not
61
  // want to emit two spaces if the first token has a leading space.
62
490k
  if (MI.tokens_empty() || 
!MI.tokens_begin()->hasLeadingSpace()480k
)
63
490k
    OS << ' ';
64
65
490k
  SmallString<128> SpellingBuffer;
66
568k
  for (const auto &T : MI.tokens()) {
67
568k
    if (T.hasLeadingSpace())
68
49.4k
      OS << ' ';
69
70
568k
    OS << PP.getSpelling(T, SpellingBuffer);
71
568k
  }
72
490k
}
73
74
//===----------------------------------------------------------------------===//
75
// Preprocessed token printer
76
//===----------------------------------------------------------------------===//
77
78
namespace {
79
class PrintPPOutputPPCallbacks : public PPCallbacks {
80
  Preprocessor &PP;
81
  SourceManager &SM;
82
  TokenConcatenation ConcatInfo;
83
public:
84
  raw_ostream &OS;
85
private:
86
  unsigned CurLine;
87
88
  bool EmittedTokensOnThisLine;
89
  bool EmittedDirectiveOnThisLine;
90
  SrcMgr::CharacteristicKind FileType;
91
  SmallString<512> CurFilename;
92
  bool Initialized;
93
  bool DisableLineMarkers;
94
  bool DumpDefines;
95
  bool DumpIncludeDirectives;
96
  bool UseLineDirectives;
97
  bool IsFirstFileEntered;
98
  bool MinimizeWhitespace;
99
100
  Token PrevTok;
101
  Token PrevPrevTok;
102
103
public:
104
  PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
105
                           bool defines, bool DumpIncludeDirectives,
106
                           bool UseLineDirectives, bool MinimizeWhitespace)
107
      : PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
108
        DisableLineMarkers(lineMarkers), DumpDefines(defines),
109
        DumpIncludeDirectives(DumpIncludeDirectives),
110
        UseLineDirectives(UseLineDirectives),
111
551
        MinimizeWhitespace(MinimizeWhitespace) {
112
551
    CurLine = 0;
113
551
    CurFilename += "<uninit>";
114
551
    EmittedTokensOnThisLine = false;
115
551
    EmittedDirectiveOnThisLine = false;
116
551
    FileType = SrcMgr::C_User;
117
551
    Initialized = false;
118
551
    IsFirstFileEntered = false;
119
120
551
    PrevTok.startToken();
121
551
    PrevPrevTok.startToken();
122
551
  }
123
124
0
  bool isMinimizeWhitespace() const { return MinimizeWhitespace; }
125
126
271k
  void setEmittedTokensOnThisLine() { EmittedTokensOnThisLine = true; }
127
0
  bool hasEmittedTokensOnThisLine() const { return EmittedTokensOnThisLine; }
128
129
17.6k
  void setEmittedDirectiveOnThisLine() { EmittedDirectiveOnThisLine = true; }
130
0
  bool hasEmittedDirectiveOnThisLine() const {
131
0
    return EmittedDirectiveOnThisLine;
132
0
  }
133
134
  /// Ensure that the output stream position is at the beginning of a new line
135
  /// and inserts one if it does not. It is intended to ensure that directives
136
  /// inserted by the directives not from the input source (such as #line) are
137
  /// in the first column. To insert newlines that represent the input, use
138
  /// MoveToLine(/*...*/, /*RequireStartOfLine=*/true).
139
  void startNewLineIfNeeded();
140
141
  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
142
                   SrcMgr::CharacteristicKind FileType,
143
                   FileID PrevFID) override;
144
  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
145
                          StringRef FileName, bool IsAngled,
146
                          CharSourceRange FilenameRange, const FileEntry *File,
147
                          StringRef SearchPath, StringRef RelativePath,
148
                          const Module *Imported,
149
                          SrcMgr::CharacteristicKind FileType) override;
150
  void Ident(SourceLocation Loc, StringRef str) override;
151
  void PragmaMessage(SourceLocation Loc, StringRef Namespace,
152
                     PragmaMessageKind Kind, StringRef Str) override;
153
  void PragmaDebug(SourceLocation Loc, StringRef DebugType) override;
154
  void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) override;
155
  void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) override;
156
  void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
157
                        diag::Severity Map, StringRef Str) override;
158
  void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec,
159
                     ArrayRef<int> Ids) override;
160
  void PragmaWarningPush(SourceLocation Loc, int Level) override;
161
  void PragmaWarningPop(SourceLocation Loc) override;
162
  void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str) override;
163
  void PragmaExecCharsetPop(SourceLocation Loc) override;
164
  void PragmaAssumeNonNullBegin(SourceLocation Loc) override;
165
  void PragmaAssumeNonNullEnd(SourceLocation Loc) override;
166
167
  /// Insert whitespace before emitting the next token.
168
  ///
169
  /// @param Tok             Next token to be emitted.
170
  /// @param RequireSpace    Ensure at least one whitespace is emitted. Useful
171
  ///                        if non-tokens have been emitted to the stream.
172
  /// @param RequireSameLine Never emit newlines. Useful when semantics depend
173
  ///                        on being on the same line, such as directives.
174
  void HandleWhitespaceBeforeTok(const Token &Tok, bool RequireSpace,
175
                                 bool RequireSameLine);
176
177
  /// Move to the line of the provided source location. This will
178
  /// return true if a newline was inserted or if
179
  /// the requested location is the first token on the first line.
180
  /// In these cases the next output will be the first column on the line and
181
  /// make it possible to insert indention. The newline was inserted
182
  /// implicitly when at the beginning of the file.
183
  ///
184
  /// @param Tok                 Token where to move to.
185
  /// @param RequireStartOfLine  Whether the next line depends on being in the
186
  ///                            first column, such as a directive.
187
  ///
188
  /// @return Whether column adjustments are necessary.
189
46.5k
  bool MoveToLine(const Token &Tok, bool RequireStartOfLine) {
190
46.5k
    PresumedLoc PLoc = SM.getPresumedLoc(Tok.getLocation());
191
46.5k
    unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : 
CurLine0
;
192
46.5k
    bool IsFirstInFile = Tok.isAtStartOfLine() && 
PLoc.getLine() == 146.3k
;
193
46.5k
    return MoveToLine(TargetLine, RequireStartOfLine) || 
IsFirstInFile406
;
194
46.5k
  }
195
196
  /// Move to the line of the provided source location. Returns true if a new
197
  /// line was inserted.
198
2.30k
  bool MoveToLine(SourceLocation Loc, bool RequireStartOfLine) {
199
2.30k
    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
200
2.30k
    unsigned TargetLine = PLoc.isValid() ? 
PLoc.getLine()2.29k
:
CurLine5
;
201
2.30k
    return MoveToLine(TargetLine, RequireStartOfLine);
202
2.30k
  }
203
  bool MoveToLine(unsigned LineNo, bool RequireStartOfLine);
204
205
  bool AvoidConcat(const Token &PrevPrevTok, const Token &PrevTok,
206
154k
                   const Token &Tok) {
207
154k
    return ConcatInfo.AvoidConcat(PrevPrevTok, PrevTok, Tok);
208
154k
  }
209
  void WriteLineInfo(unsigned LineNo, const char *Extra=nullptr,
210
                     unsigned ExtraLen=0);
211
0
  bool LineMarkersAreDisabled() const { return DisableLineMarkers; }
212
  void HandleNewlinesInToken(const char *TokStr, unsigned Len);
213
214
  /// MacroDefined - This hook is called whenever a macro definition is seen.
215
  void MacroDefined(const Token &MacroNameTok,
216
                    const MacroDirective *MD) override;
217
218
  /// MacroUndefined - This hook is called whenever a macro #undef is seen.
219
  void MacroUndefined(const Token &MacroNameTok,
220
                      const MacroDefinition &MD,
221
                      const MacroDirective *Undef) override;
222
223
  void BeginModule(const Module *M);
224
  void EndModule(const Module *M);
225
};
226
}  // end anonymous namespace
227
228
void PrintPPOutputPPCallbacks::WriteLineInfo(unsigned LineNo,
229
                                             const char *Extra,
230
5.59k
                                             unsigned ExtraLen) {
231
5.59k
  startNewLineIfNeeded();
232
233
  // Emit #line directives or GNU line markers depending on what mode we're in.
234
5.59k
  if (UseLineDirectives) {
235
21
    OS << "#line" << ' ' << LineNo << ' ' << '"';
236
21
    OS.write_escaped(CurFilename);
237
21
    OS << '"';
238
5.56k
  } else {
239
5.56k
    OS << '#' << ' ' << LineNo << ' ' << '"';
240
5.56k
    OS.write_escaped(CurFilename);
241
5.56k
    OS << '"';
242
243
5.56k
    if (ExtraLen)
244
2.97k
      OS.write(Extra, ExtraLen);
245
246
5.56k
    if (FileType == SrcMgr::C_System)
247
1.58k
      OS.write(" 3", 2);
248
3.98k
    else if (FileType == SrcMgr::C_ExternCSystem)
249
15
      OS.write(" 3 4", 4);
250
5.56k
  }
251
5.59k
  OS << '\n';
252
5.59k
}
253
254
/// MoveToLine - Move the output to the source line specified by the location
255
/// object.  We can do this by emitting some number of \n's, or be emitting a
256
/// #line directive.  This returns false if already at the specified line, true
257
/// if some newlines were emitted.
258
bool PrintPPOutputPPCallbacks::MoveToLine(unsigned LineNo,
259
48.8k
                                          bool RequireStartOfLine) {
260
  // If it is required to start a new line or finish the current, insert
261
  // vertical whitespace now and take it into account when moving to the
262
  // expected line.
263
48.8k
  bool StartedNewLine = false;
264
48.8k
  if ((RequireStartOfLine && 
EmittedTokensOnThisLine17.5k
) ||
265
48.8k
      
EmittedDirectiveOnThisLine32.5k
) {
266
17.5k
    OS << '\n';
267
17.5k
    StartedNewLine = true;
268
17.5k
    CurLine += 1;
269
17.5k
    EmittedTokensOnThisLine = false;
270
17.5k
    EmittedDirectiveOnThisLine = false;
271
17.5k
  }
272
273
  // If this line is "close enough" to the original line, just print newlines,
274
  // otherwise print a #line directive.
275
48.8k
  if (CurLine == LineNo) {
276
    // Nothing to do if we are already on the correct line.
277
31.1k
  } else if (MinimizeWhitespace && 
DisableLineMarkers90
) {
278
    // With -E -P -fminimize-whitespace, don't emit anything if not necessary.
279
31.1k
  } else if (!StartedNewLine && 
LineNo - CurLine == 130.7k
) {
280
    // Printing a single line has priority over printing a #line directive, even
281
    // when minimizing whitespace which otherwise would print #line directives
282
    // for every single line.
283
23.6k
    OS << '\n';
284
23.6k
    StartedNewLine = true;
285
23.6k
  } else 
if (7.46k
!DisableLineMarkers7.46k
) {
286
7.33k
    if (LineNo - CurLine <= 8) {
287
5.88k
      const char *NewLines = "\n\n\n\n\n\n\n\n";
288
5.88k
      OS.write(NewLines, LineNo - CurLine);
289
5.88k
    } else {
290
      // Emit a #line or line marker.
291
1.44k
      WriteLineInfo(LineNo, nullptr, 0);
292
1.44k
    }
293
7.33k
    StartedNewLine = true;
294
7.33k
  } else 
if (137
EmittedTokensOnThisLine137
) {
295
    // If we are not on the correct line and don't need to be line-correct,
296
    // at least ensure we start on a new line.
297
95
    OS << '\n';
298
95
    StartedNewLine = true;
299
95
  }
300
301
48.8k
  if (StartedNewLine) {
302
48.2k
    EmittedTokensOnThisLine = false;
303
48.2k
    EmittedDirectiveOnThisLine = false;
304
48.2k
  }
305
306
48.8k
  CurLine = LineNo;
307
48.8k
  return StartedNewLine;
308
48.8k
}
309
310
5.80k
void PrintPPOutputPPCallbacks::startNewLineIfNeeded() {
311
5.80k
  if (EmittedTokensOnThisLine || 
EmittedDirectiveOnThisLine4.95k
) {
312
876
    OS << '\n';
313
876
    EmittedTokensOnThisLine = false;
314
876
    EmittedDirectiveOnThisLine = false;
315
876
  }
316
5.80k
}
317
318
/// FileChanged - Whenever the preprocessor enters or exits a #include file
319
/// it invokes this handler.  Update our conception of the current source
320
/// position.
321
void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
322
                                           FileChangeReason Reason,
323
                                       SrcMgr::CharacteristicKind NewFileType,
324
4.33k
                                       FileID PrevFID) {
325
  // Unless we are exiting a #include, make sure to skip ahead to the line the
326
  // #include directive was at.
327
4.33k
  SourceManager &SourceMgr = SM;
328
329
4.33k
  PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc);
330
4.33k
  if (UserLoc.isInvalid())
331
0
    return;
332
333
4.33k
  unsigned NewLine = UserLoc.getLine();
334
335
4.33k
  if (Reason == PPCallbacks::EnterFile) {
336
2.11k
    SourceLocation IncludeLoc = UserLoc.getIncludeLoc();
337
2.11k
    if (IncludeLoc.isValid())
338
1.00k
      MoveToLine(IncludeLoc, /*RequireStartOfLine=*/false);
339
2.22k
  } else if (Reason == PPCallbacks::SystemHeaderPragma) {
340
    // GCC emits the # directive for this directive on the line AFTER the
341
    // directive and emits a bunch of spaces that aren't needed. This is because
342
    // otherwise we will emit a line marker for THIS line, which requires an
343
    // extra blank line after the directive to avoid making all following lines
344
    // off by one. We can do better by simply incrementing NewLine here.
345
2
    NewLine += 1;
346
2
  }
347
348
4.33k
  CurLine = NewLine;
349
350
4.33k
  CurFilename.clear();
351
4.33k
  CurFilename += UserLoc.getFilename();
352
4.33k
  FileType = NewFileType;
353
354
4.33k
  if (DisableLineMarkers) {
355
197
    if (!MinimizeWhitespace)
356
139
      startNewLineIfNeeded();
357
197
    return;
358
197
  }
359
360
4.14k
  if (!Initialized) {
361
522
    WriteLineInfo(CurLine);
362
522
    Initialized = true;
363
522
  }
364
365
  // Do not emit an enter marker for the main file (which we expect is the first
366
  // entered file). This matches gcc, and improves compatibility with some tools
367
  // which track the # line markers as a way to determine when the preprocessed
368
  // output is in the context of the main file.
369
4.14k
  if (Reason == PPCallbacks::EnterFile && 
!IsFirstFileEntered2.01k
) {
370
522
    IsFirstFileEntered = true;
371
522
    return;
372
522
  }
373
374
3.62k
  switch (Reason) {
375
1.49k
  case PPCallbacks::EnterFile:
376
1.49k
    WriteLineInfo(CurLine, " 1", 2);
377
1.49k
    break;
378
1.49k
  case PPCallbacks::ExitFile:
379
1.49k
    WriteLineInfo(CurLine, " 2", 2);
380
1.49k
    break;
381
2
  case PPCallbacks::SystemHeaderPragma:
382
638
  case PPCallbacks::RenameFile:
383
638
    WriteLineInfo(CurLine);
384
638
    break;
385
3.62k
  }
386
3.62k
}
387
388
void PrintPPOutputPPCallbacks::InclusionDirective(
389
    SourceLocation HashLoc,
390
    const Token &IncludeTok,
391
    StringRef FileName,
392
    bool IsAngled,
393
    CharSourceRange FilenameRange,
394
    const FileEntry *File,
395
    StringRef SearchPath,
396
    StringRef RelativePath,
397
    const Module *Imported,
398
629
    SrcMgr::CharacteristicKind FileType) {
399
  // In -dI mode, dump #include directives prior to dumping their content or
400
  // interpretation.
401
629
  if (DumpIncludeDirectives) {
402
5
    MoveToLine(HashLoc, /*RequireStartOfLine=*/true);
403
5
    const std::string TokenText = PP.getSpelling(IncludeTok);
404
5
    assert(!TokenText.empty());
405
0
    OS << "#" << TokenText << " "
406
5
       << (IsAngled ? 
'<'1
:
'"'4
) << FileName << (IsAngled ?
'>'1
:
'"'4
)
407
5
       << " /* clang -E -dI */";
408
5
    setEmittedDirectiveOnThisLine();
409
5
  }
410
411
  // When preprocessing, turn implicit imports into module import pragmas.
412
629
  if (Imported) {
413
39
    switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
414
27
    case tok::pp_include:
415
39
    case tok::pp_import:
416
39
    case tok::pp_include_next:
417
39
      MoveToLine(HashLoc, /*RequireStartOfLine=*/true);
418
39
      OS << "#pragma clang module import " << Imported->getFullModuleName(true)
419
39
         << " /* clang -E: implicit import for "
420
39
         << "#" << PP.getSpelling(IncludeTok) << " "
421
39
         << (IsAngled ? 
'<'8
:
'"'31
) << FileName << (IsAngled ?
'>'8
:
'"'31
)
422
39
         << " */";
423
39
      setEmittedDirectiveOnThisLine();
424
39
      break;
425
426
0
    case tok::pp___include_macros:
427
      // #__include_macros has no effect on a user of a preprocessed source
428
      // file; the only effect is on preprocessing.
429
      //
430
      // FIXME: That's not *quite* true: it causes the module in question to
431
      // be loaded, which can affect downstream diagnostics.
432
0
      break;
433
434
0
    default:
435
0
      llvm_unreachable("unknown include directive kind");
436
0
      break;
437
39
    }
438
39
  }
439
629
}
440
441
/// Handle entering the scope of a module during a module compilation.
442
37
void PrintPPOutputPPCallbacks::BeginModule(const Module *M) {
443
37
  startNewLineIfNeeded();
444
37
  OS << "#pragma clang module begin " << M->getFullModuleName(true);
445
37
  setEmittedDirectiveOnThisLine();
446
37
}
447
448
/// Handle leaving the scope of a module during a module compilation.
449
37
void PrintPPOutputPPCallbacks::EndModule(const Module *M) {
450
37
  startNewLineIfNeeded();
451
37
  OS << "#pragma clang module end /*" << M->getFullModuleName(true) << "*/";
452
37
  setEmittedDirectiveOnThisLine();
453
37
}
454
455
/// Ident - Handle #ident directives when read by the preprocessor.
456
///
457
0
void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, StringRef S) {
458
0
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
459
460
0
  OS.write("#ident ", strlen("#ident "));
461
0
  OS.write(S.begin(), S.size());
462
0
  setEmittedTokensOnThisLine();
463
0
}
464
465
/// MacroDefined - This hook is called whenever a macro definition is seen.
466
void PrintPPOutputPPCallbacks::MacroDefined(const Token &MacroNameTok,
467
502k
                                            const MacroDirective *MD) {
468
502k
  const MacroInfo *MI = MD->getMacroInfo();
469
  // Only print out macro definitions in -dD mode.
470
502k
  if (!DumpDefines ||
471
      // Ignore __FILE__ etc.
472
502k
      
MI->isBuiltinMacro()1.04k
)
return501k
;
473
474
1.04k
  MoveToLine(MI->getDefinitionLoc(), /*RequireStartOfLine=*/true);
475
1.04k
  PrintMacroDefinition(*MacroNameTok.getIdentifierInfo(), *MI, PP, OS);
476
1.04k
  setEmittedDirectiveOnThisLine();
477
1.04k
}
478
479
void PrintPPOutputPPCallbacks::MacroUndefined(const Token &MacroNameTok,
480
                                              const MacroDefinition &MD,
481
244
                                              const MacroDirective *Undef) {
482
  // Only print out macro definitions in -dD mode.
483
244
  if (!DumpDefines) 
return243
;
484
485
1
  MoveToLine(MacroNameTok.getLocation(), /*RequireStartOfLine=*/true);
486
1
  OS << "#undef " << MacroNameTok.getIdentifierInfo()->getName();
487
1
  setEmittedDirectiveOnThisLine();
488
1
}
489
490
7
static void outputPrintable(raw_ostream &OS, StringRef Str) {
491
43
  for (unsigned char Char : Str) {
492
43
    if (isPrintable(Char) && 
Char != '\\'41
&&
Char != '"'39
)
493
33
      OS << (char)Char;
494
10
    else // Output anything hard as an octal escape.
495
10
      OS << '\\'
496
10
         << (char)('0' + ((Char >> 6) & 7))
497
10
         << (char)('0' + ((Char >> 3) & 7))
498
10
         << (char)('0' + ((Char >> 0) & 7));
499
43
  }
500
7
}
501
502
void PrintPPOutputPPCallbacks::PragmaMessage(SourceLocation Loc,
503
                                             StringRef Namespace,
504
                                             PragmaMessageKind Kind,
505
7
                                             StringRef Str) {
506
7
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
507
7
  OS << "#pragma ";
508
7
  if (!Namespace.empty())
509
4
    OS << Namespace << ' ';
510
7
  switch (Kind) {
511
3
    case PMK_Message:
512
3
      OS << "message(\"";
513
3
      break;
514
2
    case PMK_Warning:
515
2
      OS << "warning \"";
516
2
      break;
517
2
    case PMK_Error:
518
2
      OS << "error \"";
519
2
      break;
520
7
  }
521
522
7
  outputPrintable(OS, Str);
523
7
  OS << '"';
524
7
  if (Kind == PMK_Message)
525
3
    OS << ')';
526
7
  setEmittedDirectiveOnThisLine();
527
7
}
528
529
void PrintPPOutputPPCallbacks::PragmaDebug(SourceLocation Loc,
530
8
                                           StringRef DebugType) {
531
8
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
532
533
8
  OS << "#pragma clang __debug ";
534
8
  OS << DebugType;
535
536
8
  setEmittedDirectiveOnThisLine();
537
8
}
538
539
void PrintPPOutputPPCallbacks::
540
13
PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace) {
541
13
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
542
13
  OS << "#pragma " << Namespace << " diagnostic push";
543
13
  setEmittedDirectiveOnThisLine();
544
13
}
545
546
void PrintPPOutputPPCallbacks::
547
13
PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace) {
548
13
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
549
13
  OS << "#pragma " << Namespace << " diagnostic pop";
550
13
  setEmittedDirectiveOnThisLine();
551
13
}
552
553
void PrintPPOutputPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
554
                                                StringRef Namespace,
555
                                                diag::Severity Map,
556
21
                                                StringRef Str) {
557
21
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
558
21
  OS << "#pragma " << Namespace << " diagnostic ";
559
21
  switch (Map) {
560
0
  case diag::Severity::Remark:
561
0
    OS << "remark";
562
0
    break;
563
5
  case diag::Severity::Warning:
564
5
    OS << "warning";
565
5
    break;
566
3
  case diag::Severity::Error:
567
3
    OS << "error";
568
3
    break;
569
11
  case diag::Severity::Ignored:
570
11
    OS << "ignored";
571
11
    break;
572
2
  case diag::Severity::Fatal:
573
2
    OS << "fatal";
574
2
    break;
575
21
  }
576
21
  OS << " \"" << Str << '"';
577
21
  setEmittedDirectiveOnThisLine();
578
21
}
579
580
void PrintPPOutputPPCallbacks::PragmaWarning(SourceLocation Loc,
581
                                             PragmaWarningSpecifier WarningSpec,
582
15
                                             ArrayRef<int> Ids) {
583
15
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
584
585
15
  OS << "#pragma warning(";
586
15
  switch(WarningSpec) {
587
1
    case PWS_Default:  OS << "default"; break;
588
5
    case PWS_Disable:  OS << "disable"; break;
589
2
    case PWS_Error:    OS << "error"; break;
590
1
    case PWS_Once:     OS << "once"; break;
591
2
    case PWS_Suppress: OS << "suppress"; break;
592
1
    case PWS_Level1:   OS << '1'; break;
593
1
    case PWS_Level2:   OS << '2'; break;
594
1
    case PWS_Level3:   OS << '3'; break;
595
1
    case PWS_Level4:   OS << '4'; break;
596
15
  }
597
15
  OS << ':';
598
599
39
  for (ArrayRef<int>::iterator I = Ids.begin(), E = Ids.end(); I != E; 
++I24
)
600
24
    OS << ' ' << *I;
601
15
  OS << ')';
602
15
  setEmittedDirectiveOnThisLine();
603
15
}
604
605
void PrintPPOutputPPCallbacks::PragmaWarningPush(SourceLocation Loc,
606
17
                                                 int Level) {
607
17
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
608
17
  OS << "#pragma warning(push";
609
17
  if (Level >= 0)
610
9
    OS << ", " << Level;
611
17
  OS << ')';
612
17
  setEmittedDirectiveOnThisLine();
613
17
}
614
615
6
void PrintPPOutputPPCallbacks::PragmaWarningPop(SourceLocation Loc) {
616
6
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
617
6
  OS << "#pragma warning(pop)";
618
6
  setEmittedDirectiveOnThisLine();
619
6
}
620
621
void PrintPPOutputPPCallbacks::PragmaExecCharsetPush(SourceLocation Loc,
622
4
                                                     StringRef Str) {
623
4
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
624
4
  OS << "#pragma character_execution_set(push";
625
4
  if (!Str.empty())
626
4
    OS << ", " << Str;
627
4
  OS << ')';
628
4
  setEmittedDirectiveOnThisLine();
629
4
}
630
631
3
void PrintPPOutputPPCallbacks::PragmaExecCharsetPop(SourceLocation Loc) {
632
3
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
633
3
  OS << "#pragma character_execution_set(pop)";
634
3
  setEmittedDirectiveOnThisLine();
635
3
}
636
637
void PrintPPOutputPPCallbacks::
638
5
PragmaAssumeNonNullBegin(SourceLocation Loc) {
639
5
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
640
5
  OS << "#pragma clang assume_nonnull begin";
641
5
  setEmittedDirectiveOnThisLine();
642
5
}
643
644
void PrintPPOutputPPCallbacks::
645
5
PragmaAssumeNonNullEnd(SourceLocation Loc) {
646
5
  MoveToLine(Loc, /*RequireStartOfLine=*/true);
647
5
  OS << "#pragma clang assume_nonnull end";
648
5
  setEmittedDirectiveOnThisLine();
649
5
}
650
651
void PrintPPOutputPPCallbacks::HandleWhitespaceBeforeTok(const Token &Tok,
652
                                                         bool RequireSpace,
653
271k
                                                         bool RequireSameLine) {
654
  // These tokens are not expanded to anything and don't need whitespace before
655
  // them.
656
271k
  if (Tok.is(tok::eof) ||
657
271k
      
(270k
Tok.isAnnotation()270k
&&
!Tok.is(tok::annot_header_unit)129
&&
658
270k
       
!Tok.is(tok::annot_module_begin)124
&&
!Tok.is(tok::annot_module_end)87
))
659
601
    return;
660
661
  // EmittedDirectiveOnThisLine takes priority over RequireSameLine.
662
270k
  if ((!RequireSameLine || 
EmittedDirectiveOnThisLine224k
) &&
663
270k
      
MoveToLine(Tok, /*RequireStartOfLine=*/EmittedDirectiveOnThisLine)46.5k
) {
664
46.3k
    if (MinimizeWhitespace) {
665
      // Avoid interpreting hash as a directive under -fpreprocessed.
666
125
      if (Tok.is(tok::hash))
667
4
        OS << ' ';
668
46.1k
    } else {
669
      // Print out space characters so that the first token on a line is
670
      // indented for easy reading.
671
46.1k
      unsigned ColNo = SM.getExpansionColumnNumber(Tok.getLocation());
672
673
      // The first token on a line can have a column number of 1, yet still
674
      // expect leading white space, if a macro expansion in column 1 starts
675
      // with an empty macro argument, or an empty nested macro expansion. In
676
      // this case, move the token to column 2.
677
46.1k
      if (ColNo == 1 && 
Tok.hasLeadingSpace()35.2k
)
678
2
        ColNo = 2;
679
680
      // This hack prevents stuff like:
681
      // #define HASH #
682
      // HASH define foo bar
683
      // From having the # character end up at column 1, which makes it so it
684
      // is not handled as a #define next time through the preprocessor if in
685
      // -fpreprocessed mode.
686
46.1k
      if (ColNo <= 1 && 
Tok.is(tok::hash)35.2k
)
687
15
        OS << ' ';
688
689
      // Otherwise, indent the appropriate number of spaces.
690
228k
      for (; ColNo > 1; 
--ColNo182k
)
691
182k
        OS << ' ';
692
46.1k
    }
693
224k
  } else {
694
    // Insert whitespace between the previous and next token if either
695
    // - The caller requires it
696
    // - The input had whitespace between them and we are not in
697
    //   whitespace-minimization mode
698
    // - The whitespace is necessary to keep the tokens apart and there is not
699
    //   already a newline between them
700
224k
    if (RequireSpace || 
(224k
!MinimizeWhitespace224k
&&
Tok.hasLeadingSpace()224k
) ||
701
224k
        
(155k
(155k
EmittedTokensOnThisLine155k
||
EmittedDirectiveOnThisLine104
) &&
702
155k
         
AvoidConcat(PrevPrevTok, PrevTok, Tok)154k
))
703
69.8k
      OS << ' ';
704
224k
  }
705
706
270k
  PrevPrevTok = PrevTok;
707
270k
  PrevTok = Tok;
708
270k
}
709
710
void PrintPPOutputPPCallbacks::HandleNewlinesInToken(const char *TokStr,
711
16.8k
                                                     unsigned Len) {
712
16.8k
  unsigned NumNewlines = 0;
713
749k
  for (; Len; 
--Len, ++TokStr732k
) {
714
732k
    if (*TokStr != '\n' &&
715
732k
        
*TokStr != '\r'731k
)
716
731k
      continue;
717
718
1.18k
    ++NumNewlines;
719
720
    // If we have \n\r or \r\n, skip both and count as one line.
721
1.18k
    if (Len != 1 &&
722
1.18k
        
(1.07k
TokStr[1] == '\n'1.07k
||
TokStr[1] == '\r'1.01k
) &&
723
1.18k
        
TokStr[0] != TokStr[1]56
) {
724
0
      ++TokStr;
725
0
      --Len;
726
0
    }
727
1.18k
  }
728
729
16.8k
  if (NumNewlines == 0) 
return16.5k
;
730
731
280
  CurLine += NumNewlines;
732
280
}
733
734
735
namespace {
736
struct UnknownPragmaHandler : public PragmaHandler {
737
  const char *Prefix;
738
  PrintPPOutputPPCallbacks *Callbacks;
739
740
  // Set to true if tokens should be expanded
741
  bool ShouldExpandTokens;
742
743
  UnknownPragmaHandler(const char *prefix, PrintPPOutputPPCallbacks *callbacks,
744
                       bool RequireTokenExpansion)
745
      : Prefix(prefix), Callbacks(callbacks),
746
2.20k
        ShouldExpandTokens(RequireTokenExpansion) {}
747
  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
748
87
                    Token &PragmaTok) override {
749
    // Figure out what line we went to and insert the appropriate number of
750
    // newline characters.
751
87
    Callbacks->MoveToLine(PragmaTok.getLocation(), /*RequireStartOfLine=*/true);
752
87
    Callbacks->OS.write(Prefix, strlen(Prefix));
753
87
    Callbacks->setEmittedTokensOnThisLine();
754
755
87
    if (ShouldExpandTokens) {
756
      // The first token does not have expanded macros. Expand them, if
757
      // required.
758
62
      auto Toks = std::make_unique<Token[]>(1);
759
62
      Toks[0] = PragmaTok;
760
62
      PP.EnterTokenStream(std::move(Toks), /*NumToks=*/1,
761
62
                          /*DisableMacroExpansion=*/false,
762
62
                          /*IsReinject=*/false);
763
62
      PP.Lex(PragmaTok);
764
62
    }
765
766
    // Read and print all of the pragma tokens.
767
87
    bool IsFirst = true;
768
448
    while (PragmaTok.isNot(tok::eod)) {
769
361
      Callbacks->HandleWhitespaceBeforeTok(PragmaTok, /*RequireSpace=*/IsFirst,
770
361
                                           /*RequireSameLine=*/true);
771
361
      IsFirst = false;
772
361
      std::string TokSpell = PP.getSpelling(PragmaTok);
773
361
      Callbacks->OS.write(&TokSpell[0], TokSpell.size());
774
361
      Callbacks->setEmittedTokensOnThisLine();
775
776
361
      if (ShouldExpandTokens)
777
294
        PP.Lex(PragmaTok);
778
67
      else
779
67
        PP.LexUnexpandedToken(PragmaTok);
780
361
    }
781
87
    Callbacks->setEmittedDirectiveOnThisLine();
782
87
  }
783
};
784
} // end anonymous namespace
785
786
787
static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
788
                                    PrintPPOutputPPCallbacks *Callbacks,
789
551
                                    raw_ostream &OS) {
790
551
  bool DropComments = PP.getLangOpts().TraditionalCPP &&
791
551
                      
!PP.getCommentRetentionState()3
;
792
793
551
  bool IsStartOfLine = false;
794
551
  char Buffer[256];
795
271k
  while (true) {
796
    // Two lines joined with line continuation ('\' as last character on the
797
    // line) must be emitted as one line even though Tok.getLine() returns two
798
    // different values. In this situation Tok.isAtStartOfLine() is false even
799
    // though it may be the first token on the lexical line. When
800
    // dropping/skipping a token that is at the start of a line, propagate the
801
    // start-of-line-ness to the next token to not append it to the previous
802
    // line.
803
271k
    IsStartOfLine = IsStartOfLine || 
Tok.isAtStartOfLine()270k
;
804
805
271k
    Callbacks->HandleWhitespaceBeforeTok(Tok, /*RequireSpace=*/false,
806
271k
                                         /*RequireSameLine=*/!IsStartOfLine);
807
808
271k
    if (DropComments && 
Tok.is(tok::comment)275
) {
809
      // Skip comments. Normally the preprocessor does not generate
810
      // tok::comment nodes at all when not keeping comments, but under
811
      // -traditional-cpp the lexer keeps /all/ whitespace, including comments.
812
50
      PP.Lex(Tok);
813
50
      continue;
814
270k
    } else if (Tok.is(tok::eod)) {
815
      // Don't print end of directive tokens, since they are typically newlines
816
      // that mess up our line tracking. These come from unknown pre-processor
817
      // directives or hash-prefixed comments in standalone assembly files.
818
27
      PP.Lex(Tok);
819
      // FIXME: The token on the next line after #include should have
820
      // Tok.isAtStartOfLine() set.
821
27
      IsStartOfLine = true;
822
27
      continue;
823
270k
    } else if (Tok.is(tok::annot_module_include)) {
824
      // PrintPPOutputPPCallbacks::InclusionDirective handles producing
825
      // appropriate output here. Ignore this token entirely.
826
47
      PP.Lex(Tok);
827
47
      IsStartOfLine = true;
828
47
      continue;
829
270k
    } else if (Tok.is(tok::annot_module_begin)) {
830
      // FIXME: We retrieve this token after the FileChanged callback, and
831
      // retrieve the module_end token before the FileChanged callback, so
832
      // we render this within the file and render the module end outside the
833
      // file, but this is backwards from the token locations: the module_begin
834
      // token is at the include location (outside the file) and the module_end
835
      // token is at the EOF location (within the file).
836
37
      Callbacks->BeginModule(
837
37
          reinterpret_cast<Module *>(Tok.getAnnotationValue()));
838
37
      PP.Lex(Tok);
839
37
      IsStartOfLine = true;
840
37
      continue;
841
270k
    } else if (Tok.is(tok::annot_module_end)) {
842
37
      Callbacks->EndModule(
843
37
          reinterpret_cast<Module *>(Tok.getAnnotationValue()));
844
37
      PP.Lex(Tok);
845
37
      IsStartOfLine = true;
846
37
      continue;
847
270k
    } else if (Tok.is(tok::annot_header_unit)) {
848
      // This is a header-name that has been (effectively) converted into a
849
      // module-name.
850
      // FIXME: The module name could contain non-identifier module name
851
      // components. We don't have a good way to round-trip those.
852
5
      Module *M = reinterpret_cast<Module *>(Tok.getAnnotationValue());
853
5
      std::string Name = M->getFullModuleName();
854
5
      OS.write(Name.data(), Name.size());
855
5
      Callbacks->HandleNewlinesInToken(Name.data(), Name.size());
856
270k
    } else if (Tok.isAnnotation()) {
857
      // Ignore annotation tokens created by pragmas - the pragmas themselves
858
      // will be reproduced in the preprocessed output.
859
3
      PP.Lex(Tok);
860
3
      continue;
861
270k
    } else if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
862
103k
      OS << II->getName();
863
167k
    } else if (Tok.isLiteral() && 
!Tok.needsCleaning()13.7k
&&
864
167k
               
Tok.getLiteralData()13.7k
) {
865
13.7k
      OS.write(Tok.getLiteralData(), Tok.getLength());
866
153k
    } else if (Tok.getLength() < llvm::array_lengthof(Buffer)) {
867
153k
      const char *TokPtr = Buffer;
868
153k
      unsigned Len = PP.getSpelling(Tok, TokPtr);
869
153k
      OS.write(TokPtr, Len);
870
871
      // Tokens that can contain embedded newlines need to adjust our current
872
      // line number.
873
      // FIXME: The token may end with a newline in which case
874
      // setEmittedDirectiveOnThisLine/setEmittedTokensOnThisLine afterwards is
875
      // wrong.
876
153k
      if (Tok.getKind() == tok::comment || 
Tok.getKind() == tok::unknown137k
)
877
16.7k
        Callbacks->HandleNewlinesInToken(TokPtr, Len);
878
153k
      if (Tok.is(tok::comment) && 
Len >= 216.4k
&&
TokPtr[0] == '/'16.4k
&&
879
153k
          
TokPtr[1] == '/'16.4k
) {
880
        // It's a line comment;
881
        // Ensure that we don't concatenate anything behind it.
882
16.2k
        Callbacks->setEmittedDirectiveOnThisLine();
883
16.2k
      }
884
153k
    } else {
885
111
      std::string S = PP.getSpelling(Tok);
886
111
      OS.write(S.data(), S.size());
887
888
      // Tokens that can contain embedded newlines need to adjust our current
889
      // line number.
890
111
      if (Tok.getKind() == tok::comment || 
Tok.getKind() == tok::unknown0
)
891
111
        Callbacks->HandleNewlinesInToken(S.data(), S.size());
892
111
      if (Tok.is(tok::comment) && S.size() >= 2 && S[0] == '/' && S[1] == '/') {
893
        // It's a line comment;
894
        // Ensure that we don't concatenate anything behind it.
895
0
        Callbacks->setEmittedDirectiveOnThisLine();
896
0
      }
897
111
    }
898
270k
    Callbacks->setEmittedTokensOnThisLine();
899
270k
    IsStartOfLine = false;
900
901
270k
    if (Tok.is(tok::eof)) 
break551
;
902
903
270k
    PP.Lex(Tok);
904
270k
  }
905
551
}
906
907
typedef std::pair<const IdentifierInfo *, MacroInfo *> id_macro_pair;
908
4.46M
static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) {
909
4.46M
  return LHS->first->getName().compare(RHS->first->getName());
910
4.46M
}
911
912
1.34k
static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) {
913
  // Ignore unknown pragmas.
914
1.34k
  PP.IgnorePragmas();
915
916
  // -dM mode just scans and ignores all tokens in the files, then dumps out
917
  // the macro table at the end.
918
1.34k
  PP.EnterMainSourceFile();
919
920
1.34k
  Token Tok;
921
1.63k
  do PP.Lex(Tok);
922
1.63k
  while (Tok.isNot(tok::eof));
923
924
1.34k
  SmallVector<id_macro_pair, 128> MacrosByID;
925
1.34k
  for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
926
524k
       I != E; 
++I522k
) {
927
522k
    auto *MD = I->second.getLatest();
928
522k
    if (MD && MD->isDefined())
929
522k
      MacrosByID.push_back(id_macro_pair(I->first, MD->getMacroInfo()));
930
522k
  }
931
1.34k
  llvm::array_pod_sort(MacrosByID.begin(), MacrosByID.end(), MacroIDCompare);
932
933
524k
  for (unsigned i = 0, e = MacrosByID.size(); i != e; 
++i522k
) {
934
522k
    MacroInfo &MI = *MacrosByID[i].second;
935
    // Ignore computed macros like __LINE__ and friends.
936
522k
    if (MI.isBuiltinMacro()) 
continue33.6k
;
937
938
489k
    PrintMacroDefinition(*MacrosByID[i].first, MI, PP, *OS);
939
489k
    *OS << '\n';
940
489k
  }
941
1.34k
}
942
943
/// DoPrintPreprocessedInput - This implements -E mode.
944
///
945
void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
946
1.89k
                                     const PreprocessorOutputOptions &Opts) {
947
  // Show macros with no output is handled specially.
948
1.89k
  if (!Opts.ShowCPP) {
949
1.34k
    assert(Opts.ShowMacros && "Not yet implemented!");
950
0
    DoPrintMacros(PP, OS);
951
1.34k
    return;
952
1.34k
  }
953
954
  // Inform the preprocessor whether we want it to retain comments or not, due
955
  // to -C or -CC.
956
551
  PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
957
958
551
  PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
959
551
      PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros,
960
551
      Opts.ShowIncludeDirectives, Opts.UseLineDirectives,
961
551
      Opts.MinimizeWhitespace);
962
963
  // Expand macros in pragmas with -fms-extensions.  The assumption is that
964
  // the majority of pragmas in such a file will be Microsoft pragmas.
965
  // Remember the handlers we will add so that we can remove them later.
966
551
  std::unique_ptr<UnknownPragmaHandler> MicrosoftExtHandler(
967
551
      new UnknownPragmaHandler(
968
551
          "#pragma", Callbacks,
969
551
          /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt));
970
971
551
  std::unique_ptr<UnknownPragmaHandler> GCCHandler(new UnknownPragmaHandler(
972
551
      "#pragma GCC", Callbacks,
973
551
      /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt));
974
975
551
  std::unique_ptr<UnknownPragmaHandler> ClangHandler(new UnknownPragmaHandler(
976
551
      "#pragma clang", Callbacks,
977
551
      /*RequireTokenExpansion=*/PP.getLangOpts().MicrosoftExt));
978
979
551
  PP.AddPragmaHandler(MicrosoftExtHandler.get());
980
551
  PP.AddPragmaHandler("GCC", GCCHandler.get());
981
551
  PP.AddPragmaHandler("clang", ClangHandler.get());
982
983
  // The tokens after pragma omp need to be expanded.
984
  //
985
  //  OpenMP [2.1, Directive format]
986
  //  Preprocessing tokens following the #pragma omp are subject to macro
987
  //  replacement.
988
551
  std::unique_ptr<UnknownPragmaHandler> OpenMPHandler(
989
551
      new UnknownPragmaHandler("#pragma omp", Callbacks,
990
551
                               /*RequireTokenExpansion=*/true));
991
551
  PP.AddPragmaHandler("omp", OpenMPHandler.get());
992
993
551
  PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(Callbacks));
994
995
  // After we have configured the preprocessor, enter the main file.
996
551
  PP.EnterMainSourceFile();
997
998
  // Consume all of the tokens that come from the predefines buffer.  Those
999
  // should not be emitted into the output and are guaranteed to be at the
1000
  // start.
1001
551
  const SourceManager &SourceMgr = PP.getSourceManager();
1002
551
  Token Tok;
1003
551
  do {
1004
551
    PP.Lex(Tok);
1005
551
    if (Tok.is(tok::eof) || 
!Tok.getLocation().isFileID()453
)
1006
146
      break;
1007
1008
405
    PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
1009
405
    if (PLoc.isInvalid())
1010
0
      break;
1011
1012
405
    if (strcmp(PLoc.getFilename(), "<built-in>"))
1013
405
      break;
1014
405
  } while (
true0
);
1015
1016
  // Read all the preprocessed tokens, printing them out to the stream.
1017
0
  PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
1018
551
  *OS << '\n';
1019
1020
  // Remove the handlers we just added to leave the preprocessor in a sane state
1021
  // so that it can be reused (for example by a clang::Parser instance).
1022
551
  PP.RemovePragmaHandler(MicrosoftExtHandler.get());
1023
551
  PP.RemovePragmaHandler("GCC", GCCHandler.get());
1024
551
  PP.RemovePragmaHandler("clang", ClangHandler.get());
1025
551
  PP.RemovePragmaHandler("omp", OpenMPHandler.get());
1026
551
}