Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Lex/Preprocessor.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Preprocessor.cpp - C Language Family Preprocessor Implementation ---===//
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 file implements the Preprocessor interface.
10
//
11
//===----------------------------------------------------------------------===//
12
//
13
// Options to support:
14
//   -H       - Print the name of each header file used.
15
//   -d[DNI] - Dump various things.
16
//   -fworking-directory - #line's with preprocessor's working dir.
17
//   -fpreprocessed
18
//   -dependency-file,-M,-MM,-MF,-MG,-MP,-MT,-MQ,-MD,-MMD
19
//   -W*
20
//   -w
21
//
22
// Messages to emit:
23
//   "Multiple include guards may be useful for:\n"
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include "clang/Lex/Preprocessor.h"
28
#include "clang/Basic/Builtins.h"
29
#include "clang/Basic/FileManager.h"
30
#include "clang/Basic/FileSystemStatCache.h"
31
#include "clang/Basic/IdentifierTable.h"
32
#include "clang/Basic/LLVM.h"
33
#include "clang/Basic/LangOptions.h"
34
#include "clang/Basic/Module.h"
35
#include "clang/Basic/SourceLocation.h"
36
#include "clang/Basic/SourceManager.h"
37
#include "clang/Basic/TargetInfo.h"
38
#include "clang/Lex/CodeCompletionHandler.h"
39
#include "clang/Lex/ExternalPreprocessorSource.h"
40
#include "clang/Lex/HeaderSearch.h"
41
#include "clang/Lex/LexDiagnostic.h"
42
#include "clang/Lex/Lexer.h"
43
#include "clang/Lex/LiteralSupport.h"
44
#include "clang/Lex/MacroArgs.h"
45
#include "clang/Lex/MacroInfo.h"
46
#include "clang/Lex/ModuleLoader.h"
47
#include "clang/Lex/Pragma.h"
48
#include "clang/Lex/PreprocessingRecord.h"
49
#include "clang/Lex/PreprocessorLexer.h"
50
#include "clang/Lex/PreprocessorOptions.h"
51
#include "clang/Lex/ScratchBuffer.h"
52
#include "clang/Lex/Token.h"
53
#include "clang/Lex/TokenLexer.h"
54
#include "llvm/ADT/APInt.h"
55
#include "llvm/ADT/ArrayRef.h"
56
#include "llvm/ADT/DenseMap.h"
57
#include "llvm/ADT/STLExtras.h"
58
#include "llvm/ADT/SmallString.h"
59
#include "llvm/ADT/SmallVector.h"
60
#include "llvm/ADT/StringRef.h"
61
#include "llvm/ADT/StringSwitch.h"
62
#include "llvm/Support/Capacity.h"
63
#include "llvm/Support/ErrorHandling.h"
64
#include "llvm/Support/MemoryBuffer.h"
65
#include "llvm/Support/raw_ostream.h"
66
#include <algorithm>
67
#include <cassert>
68
#include <memory>
69
#include <string>
70
#include <utility>
71
#include <vector>
72
73
using namespace clang;
74
75
LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
76
77
12.3k
ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
78
79
Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
80
                           DiagnosticsEngine &diags, LangOptions &opts,
81
                           SourceManager &SM, HeaderSearch &Headers,
82
                           ModuleLoader &TheModuleLoader,
83
                           IdentifierInfoLookup *IILookup, bool OwnsHeaders,
84
                           TranslationUnitKind TUKind)
85
    : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
86
      FileMgr(Headers.getFileMgr()), SourceMgr(SM),
87
      ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
88
      TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
89
      // As the language options may have not been loaded yet (when
90
      // deserializing an ASTUnit), adding keywords to the identifier table is
91
      // deferred to Preprocessor::Initialize().
92
      Identifiers(IILookup), PragmaHandlers(new PragmaNamespace(StringRef())),
93
      TUKind(TUKind), SkipMainFilePreamble(0, true),
94
97.0k
      CurSubmoduleState(&NullSubmoduleState) {
95
97.0k
  OwnsHeaderSearch = OwnsHeaders;
96
97
  // Default to discarding comments.
98
97.0k
  KeepComments = false;
99
97.0k
  KeepMacroComments = false;
100
97.0k
  SuppressIncludeNotFoundError = false;
101
102
  // Macro expansion is enabled.
103
97.0k
  DisableMacroExpansion = false;
104
97.0k
  MacroExpansionInDirectivesOverride = false;
105
97.0k
  InMacroArgs = false;
106
97.0k
  ArgMacro = nullptr;
107
97.0k
  InMacroArgPreExpansion = false;
108
97.0k
  NumCachedTokenLexers = 0;
109
97.0k
  PragmasEnabled = true;
110
97.0k
  ParsingIfOrElifDirective = false;
111
97.0k
  PreprocessedOutput = false;
112
113
  // We haven't read anything from the external source.
114
97.0k
  ReadMacrosFromExternalSource = false;
115
116
97.0k
  BuiltinInfo = std::make_unique<Builtin::Context>();
117
118
  // "Poison" __VA_ARGS__, __VA_OPT__ which can only appear in the expansion of
119
  // a macro. They get unpoisoned where it is allowed.
120
97.0k
  (Ident__VA_ARGS__ = getIdentifierInfo("__VA_ARGS__"))->setIsPoisoned();
121
97.0k
  SetPoisonReason(Ident__VA_ARGS__,diag::ext_pp_bad_vaargs_use);
122
97.0k
  (Ident__VA_OPT__ = getIdentifierInfo("__VA_OPT__"))->setIsPoisoned();
123
97.0k
  SetPoisonReason(Ident__VA_OPT__,diag::ext_pp_bad_vaopt_use);
124
125
  // Initialize the pragma handlers.
126
97.0k
  RegisterBuiltinPragmas();
127
128
  // Initialize builtin macros like __LINE__ and friends.
129
97.0k
  RegisterBuiltinMacros();
130
131
97.0k
  if(LangOpts.Borland) {
132
6
    Ident__exception_info        = getIdentifierInfo("_exception_info");
133
6
    Ident___exception_info       = getIdentifierInfo("__exception_info");
134
6
    Ident_GetExceptionInfo       = getIdentifierInfo("GetExceptionInformation");
135
6
    Ident__exception_code        = getIdentifierInfo("_exception_code");
136
6
    Ident___exception_code       = getIdentifierInfo("__exception_code");
137
6
    Ident_GetExceptionCode       = getIdentifierInfo("GetExceptionCode");
138
6
    Ident__abnormal_termination  = getIdentifierInfo("_abnormal_termination");
139
6
    Ident___abnormal_termination = getIdentifierInfo("__abnormal_termination");
140
6
    Ident_AbnormalTermination    = getIdentifierInfo("AbnormalTermination");
141
97.0k
  } else {
142
97.0k
    Ident__exception_info = Ident__exception_code = nullptr;
143
97.0k
    Ident__abnormal_termination = Ident___exception_info = nullptr;
144
97.0k
    Ident___exception_code = Ident___abnormal_termination = nullptr;
145
97.0k
    Ident_GetExceptionInfo = Ident_GetExceptionCode = nullptr;
146
97.0k
    Ident_AbnormalTermination = nullptr;
147
97.0k
  }
148
149
  // If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
150
97.0k
  if (usingPCHWithPragmaHdrStop())
151
8
    SkippingUntilPragmaHdrStop = true;
152
153
  // If using a PCH with a through header, start skipping tokens.
154
97.0k
  if (!this->PPOpts->PCHThroughHeader.empty() &&
155
97.0k
      
!this->PPOpts->ImplicitPCHInclude.empty()32
)
156
17
    SkippingUntilPCHThroughHeader = true;
157
158
97.0k
  if (this->PPOpts->GeneratePreamble)
159
91
    PreambleConditionalStack.startRecording();
160
161
97.0k
  ExcludedConditionalDirectiveSkipMappings =
162
97.0k
      this->PPOpts->ExcludedConditionalDirectiveSkipMappings;
163
97.0k
  if (ExcludedConditionalDirectiveSkipMappings)
164
137
    ExcludedConditionalDirectiveSkipMappings->clear();
165
166
97.0k
  MaxTokens = LangOpts.MaxTokens;
167
97.0k
}
168
169
91.1k
Preprocessor::~Preprocessor() {
170
91.1k
  assert(BacktrackPositions.empty() && "EnableBacktrack/Backtrack imbalance!");
171
172
0
  IncludeMacroStack.clear();
173
174
  // Destroy any macro definitions.
175
45.9M
  while (MacroInfoChain *I = MIChainHead) {
176
45.8M
    MIChainHead = I->Next;
177
45.8M
    I->~MacroInfoChain();
178
45.8M
  }
179
180
  // Free any cached macro expanders.
181
  // This populates MacroArgCache, so all TokenLexers need to be destroyed
182
  // before the code below that frees up the MacroArgCache list.
183
91.1k
  std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers, nullptr);
184
91.1k
  CurTokenLexer.reset();
185
186
  // Free any cached MacroArgs.
187
135k
  for (MacroArgs *ArgList = MacroArgCache; ArgList;)
188
44.0k
    ArgList = ArgList->deallocate();
189
190
  // Delete the header search info, if we own it.
191
91.1k
  if (OwnsHeaderSearch)
192
90.9k
    delete &HeaderInfo;
193
91.1k
}
194
195
void Preprocessor::Initialize(const TargetInfo &Target,
196
97.0k
                              const TargetInfo *AuxTarget) {
197
97.0k
  assert((!this->Target || this->Target == &Target) &&
198
97.0k
         "Invalid override of target information");
199
0
  this->Target = &Target;
200
201
97.0k
  assert((!this->AuxTarget || this->AuxTarget == AuxTarget) &&
202
97.0k
         "Invalid override of aux target information.");
203
0
  this->AuxTarget = AuxTarget;
204
205
  // Initialize information about built-ins.
206
97.0k
  BuiltinInfo->InitializeTarget(Target, AuxTarget);
207
97.0k
  HeaderInfo.setTarget(Target);
208
209
  // Populate the identifier table with info about keywords for the current language.
210
97.0k
  Identifiers.AddKeywords(LangOpts);
211
97.0k
}
212
213
2
void Preprocessor::InitializeForModelFile() {
214
2
  NumEnteredSourceFiles = 0;
215
216
  // Reset pragmas
217
2
  PragmaHandlersBackup = std::move(PragmaHandlers);
218
2
  PragmaHandlers = std::make_unique<PragmaNamespace>(StringRef());
219
2
  RegisterBuiltinPragmas();
220
221
  // Reset PredefinesFileID
222
2
  PredefinesFileID = FileID();
223
2
}
224
225
2
void Preprocessor::FinalizeForModelFile() {
226
2
  NumEnteredSourceFiles = 1;
227
228
2
  PragmaHandlers = std::move(PragmaHandlersBackup);
229
2
}
230
231
7
void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {
232
7
  llvm::errs() << tok::getTokenName(Tok.getKind()) << " '"
233
7
               << getSpelling(Tok) << "'";
234
235
7
  if (!DumpFlags) 
return0
;
236
237
7
  llvm::errs() << "\t";
238
7
  if (Tok.isAtStartOfLine())
239
3
    llvm::errs() << " [StartOfLine]";
240
7
  if (Tok.hasLeadingSpace())
241
0
    llvm::errs() << " [LeadingSpace]";
242
7
  if (Tok.isExpandDisabled())
243
0
    llvm::errs() << " [ExpandDisabled]";
244
7
  if (Tok.needsCleaning()) {
245
0
    const char *Start = SourceMgr.getCharacterData(Tok.getLocation());
246
0
    llvm::errs() << " [UnClean='" << StringRef(Start, Tok.getLength())
247
0
                 << "']";
248
0
  }
249
250
7
  llvm::errs() << "\tLoc=<";
251
7
  DumpLocation(Tok.getLocation());
252
7
  llvm::errs() << ">";
253
7
}
254
255
7
void Preprocessor::DumpLocation(SourceLocation Loc) const {
256
7
  Loc.print(llvm::errs(), SourceMgr);
257
7
}
258
259
0
void Preprocessor::DumpMacro(const MacroInfo &MI) const {
260
0
  llvm::errs() << "MACRO: ";
261
0
  for (unsigned i = 0, e = MI.getNumTokens(); i != e; ++i) {
262
0
    DumpToken(MI.getReplacementToken(i));
263
0
    llvm::errs() << "  ";
264
0
  }
265
0
  llvm::errs() << "\n";
266
0
}
267
268
3
void Preprocessor::PrintStats() {
269
3
  llvm::errs() << "\n*** Preprocessor Stats:\n";
270
3
  llvm::errs() << NumDirectives << " directives found:\n";
271
3
  llvm::errs() << "  " << NumDefined << " #define.\n";
272
3
  llvm::errs() << "  " << NumUndefined << " #undef.\n";
273
3
  llvm::errs() << "  #include/#include_next/#import:\n";
274
3
  llvm::errs() << "    " << NumEnteredSourceFiles << " source files entered.\n";
275
3
  llvm::errs() << "    " << MaxIncludeStackDepth << " max include stack depth\n";
276
3
  llvm::errs() << "  " << NumIf << " #if/#ifndef/#ifdef.\n";
277
3
  llvm::errs() << "  " << NumElse << " #else/#elif/#elifdef/#elifndef.\n";
278
3
  llvm::errs() << "  " << NumEndif << " #endif.\n";
279
3
  llvm::errs() << "  " << NumPragma << " #pragma.\n";
280
3
  llvm::errs() << NumSkipped << " #if/#ifndef#ifdef regions skipped\n";
281
282
3
  llvm::errs() << NumMacroExpanded << "/" << NumFnMacroExpanded << "/"
283
3
             << NumBuiltinMacroExpanded << " obj/fn/builtin macros expanded, "
284
3
             << NumFastMacroExpanded << " on the fast path.\n";
285
3
  llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
286
3
             << " token paste (##) operations performed, "
287
3
             << NumFastTokenPaste << " on the fast path.\n";
288
289
3
  llvm::errs() << "\nPreprocessor Memory: " << getTotalMemory() << "B total";
290
291
3
  llvm::errs() << "\n  BumpPtr: " << BP.getTotalMemory();
292
3
  llvm::errs() << "\n  Macro Expanded Tokens: "
293
3
               << llvm::capacity_in_bytes(MacroExpandedTokens);
294
3
  llvm::errs() << "\n  Predefines Buffer: " << Predefines.capacity();
295
  // FIXME: List information for all submodules.
296
3
  llvm::errs() << "\n  Macros: "
297
3
               << llvm::capacity_in_bytes(CurSubmoduleState->Macros);
298
3
  llvm::errs() << "\n  #pragma push_macro Info: "
299
3
               << llvm::capacity_in_bytes(PragmaPushMacroInfo);
300
3
  llvm::errs() << "\n  Poison Reasons: "
301
3
               << llvm::capacity_in_bytes(PoisonReasons);
302
3
  llvm::errs() << "\n  Comment Handlers: "
303
3
               << llvm::capacity_in_bytes(CommentHandlers) << "\n";
304
3
}
305
306
Preprocessor::macro_iterator
307
2.53k
Preprocessor::macro_begin(bool IncludeExternalMacros) const {
308
2.53k
  if (IncludeExternalMacros && 
ExternalSource2.52k
&&
309
2.53k
      
!ReadMacrosFromExternalSource448
) {
310
205
    ReadMacrosFromExternalSource = true;
311
205
    ExternalSource->ReadDefinedMacros();
312
205
  }
313
314
  // Make sure we cover all macros in visible modules.
315
2.53k
  for (const ModuleMacro &Macro : ModuleMacros)
316
5.11M
    CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
317
318
2.53k
  return CurSubmoduleState->Macros.begin();
319
2.53k
}
320
321
4
size_t Preprocessor::getTotalMemory() const {
322
4
  return BP.getTotalMemory()
323
4
    + llvm::capacity_in_bytes(MacroExpandedTokens)
324
4
    + Predefines.capacity() /* Predefines buffer. */
325
    // FIXME: Include sizes from all submodules, and include MacroInfo sizes,
326
    // and ModuleMacros.
327
4
    + llvm::capacity_in_bytes(CurSubmoduleState->Macros)
328
4
    + llvm::capacity_in_bytes(PragmaPushMacroInfo)
329
4
    + llvm::capacity_in_bytes(PoisonReasons)
330
4
    + llvm::capacity_in_bytes(CommentHandlers);
331
4
}
332
333
Preprocessor::macro_iterator
334
2.53k
Preprocessor::macro_end(bool IncludeExternalMacros) const {
335
2.53k
  if (IncludeExternalMacros && 
ExternalSource2.52k
&&
336
2.53k
      
!ReadMacrosFromExternalSource448
) {
337
0
    ReadMacrosFromExternalSource = true;
338
0
    ExternalSource->ReadDefinedMacros();
339
0
  }
340
341
2.53k
  return CurSubmoduleState->Macros.end();
342
2.53k
}
343
344
/// Compares macro tokens with a specified token value sequence.
345
static bool MacroDefinitionEquals(const MacroInfo *MI,
346
115k
                                  ArrayRef<TokenValue> Tokens) {
347
115k
  return Tokens.size() == MI->getNumTokens() &&
348
115k
      
std::equal(Tokens.begin(), Tokens.end(), MI->tokens_begin())12.1k
;
349
115k
}
350
351
StringRef Preprocessor::getLastMacroWithSpelling(
352
                                    SourceLocation Loc,
353
301
                                    ArrayRef<TokenValue> Tokens) const {
354
301
  SourceLocation BestLocation;
355
301
  StringRef BestSpelling;
356
301
  for (Preprocessor::macro_iterator I = macro_begin(), E = macro_end();
357
115k
       I != E; 
++I115k
) {
358
115k
    const MacroDirective::DefInfo
359
115k
      Def = I->second.findDirectiveAtLoc(Loc, SourceMgr);
360
115k
    if (!Def || 
!Def.getMacroInfo()115k
)
361
284
      continue;
362
115k
    if (!Def.getMacroInfo()->isObjectLike())
363
25
      continue;
364
115k
    if (!MacroDefinitionEquals(Def.getMacroInfo(), Tokens))
365
114k
      continue;
366
73
    SourceLocation Location = Def.getLocation();
367
    // Choose the macro defined latest.
368
73
    if (BestLocation.isInvalid() ||
369
73
        
(13
Location.isValid()13
&&
370
71
         
SourceMgr.isBeforeInTranslationUnit(BestLocation, Location)13
)) {
371
71
      BestLocation = Location;
372
71
      BestSpelling = I->first->getName();
373
71
    }
374
73
  }
375
301
  return BestSpelling;
376
301
}
377
378
10.7M
void Preprocessor::recomputeCurLexerKind() {
379
10.7M
  if (CurLexer)
380
4.29k
    CurLexerKind = CLK_Lexer;
381
10.7M
  else if (CurTokenLexer)
382
9
    CurLexerKind = CLK_TokenLexer;
383
10.7M
  else
384
10.7M
    CurLexerKind = CLK_CachingLexer;
385
10.7M
}
386
387
bool Preprocessor::SetCodeCompletionPoint(const FileEntry *File,
388
                                          unsigned CompleteLine,
389
1.25k
                                          unsigned CompleteColumn) {
390
1.25k
  assert(File);
391
0
  assert(CompleteLine && CompleteColumn && "Starts from 1:1");
392
0
  assert(!CodeCompletionFile && "Already set");
393
394
  // Load the actual file's contents.
395
0
  Optional<llvm::MemoryBufferRef> Buffer =
396
1.25k
      SourceMgr.getMemoryBufferForFileOrNone(File);
397
1.25k
  if (!Buffer)
398
0
    return true;
399
400
  // Find the byte position of the truncation point.
401
1.25k
  const char *Position = Buffer->getBufferStart();
402
37.2k
  for (unsigned Line = 1; Line < CompleteLine; 
++Line35.9k
) {
403
946k
    for (; *Position; 
++Position910k
) {
404
946k
      if (*Position != '\r' && *Position != '\n')
405
910k
        continue;
406
407
      // Eat \r\n or \n\r as a single line.
408
35.9k
      if ((Position[1] == '\r' || Position[1] == '\n') &&
409
35.9k
          
Position[0] != Position[1]5.29k
)
410
0
        ++Position;
411
35.9k
      ++Position;
412
35.9k
      break;
413
946k
    }
414
35.9k
  }
415
416
1.25k
  Position += CompleteColumn - 1;
417
418
  // If pointing inside the preamble, adjust the position at the beginning of
419
  // the file after the preamble.
420
1.25k
  if (SkipMainFilePreamble.first &&
421
1.25k
      
SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()) == File75
) {
422
75
    if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
423
5
      Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
424
75
  }
425
426
1.25k
  if (Position > Buffer->getBufferEnd())
427
1
    Position = Buffer->getBufferEnd();
428
429
1.25k
  CodeCompletionFile = File;
430
1.25k
  CodeCompletionOffset = Position - Buffer->getBufferStart();
431
432
1.25k
  auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
433
1.25k
      Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
434
1.25k
  char *NewBuf = NewBuffer->getBufferStart();
435
1.25k
  char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
436
1.25k
  *NewPos = '\0';
437
1.25k
  std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
438
1.25k
  SourceMgr.overrideFileContents(File, std::move(NewBuffer));
439
440
1.25k
  return false;
441
1.25k
}
442
443
void Preprocessor::CodeCompleteIncludedFile(llvm::StringRef Dir,
444
11
                                            bool IsAngled) {
445
11
  setCodeCompletionReached();
446
11
  if (CodeComplete)
447
11
    CodeComplete->CodeCompleteIncludedFile(Dir, IsAngled);
448
11
}
449
450
50
void Preprocessor::CodeCompleteNaturalLanguage() {
451
50
  setCodeCompletionReached();
452
50
  if (CodeComplete)
453
50
    CodeComplete->CodeCompleteNaturalLanguage();
454
50
}
455
456
/// getSpelling - This method is used to get the spelling of a token into a
457
/// SmallVector. Note that the returned StringRef may not point to the
458
/// supplied buffer if a copy can be avoided.
459
StringRef Preprocessor::getSpelling(const Token &Tok,
460
                                          SmallVectorImpl<char> &Buffer,
461
13.3M
                                          bool *Invalid) const {
462
  // NOTE: this has to be checked *before* testing for an IdentifierInfo.
463
13.3M
  if (Tok.isNot(tok::raw_identifier) && 
!Tok.hasUCN()9.16M
) {
464
    // Try the fast path.
465
9.16M
    if (const IdentifierInfo *II = Tok.getIdentifierInfo())
466
170k
      return II->getName();
467
9.16M
  }
468
469
  // Resize the buffer if we need to copy into it.
470
13.2M
  if (Tok.needsCleaning())
471
4.21M
    Buffer.resize(Tok.getLength());
472
473
13.2M
  const char *Ptr = Buffer.data();
474
13.2M
  unsigned Len = getSpelling(Tok, Ptr, Invalid);
475
13.2M
  return StringRef(Ptr, Len);
476
13.3M
}
477
478
/// CreateString - Plop the specified string into a scratch buffer and return a
479
/// location for it.  If specified, the source location provides a source
480
/// location for the token.
481
void Preprocessor::CreateString(StringRef Str, Token &Tok,
482
                                SourceLocation ExpansionLocStart,
483
8.68M
                                SourceLocation ExpansionLocEnd) {
484
8.68M
  Tok.setLength(Str.size());
485
486
8.68M
  const char *DestPtr;
487
8.68M
  SourceLocation Loc = ScratchBuf->getToken(Str.data(), Str.size(), DestPtr);
488
489
8.68M
  if (ExpansionLocStart.isValid())
490
726k
    Loc = SourceMgr.createExpansionLoc(Loc, ExpansionLocStart,
491
726k
                                       ExpansionLocEnd, Str.size());
492
8.68M
  Tok.setLocation(Loc);
493
494
  // If this is a raw identifier or a literal token, set the pointer data.
495
8.68M
  if (Tok.is(tok::raw_identifier))
496
286k
    Tok.setRawIdentifierData(DestPtr);
497
8.39M
  else if (Tok.isLiteral())
498
7.79M
    Tok.setLiteralData(DestPtr);
499
8.68M
}
500
501
17.1k
SourceLocation Preprocessor::SplitToken(SourceLocation Loc, unsigned Length) {
502
17.1k
  auto &SM = getSourceManager();
503
17.1k
  SourceLocation SpellingLoc = SM.getSpellingLoc(Loc);
504
17.1k
  std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SpellingLoc);
505
17.1k
  bool Invalid = false;
506
17.1k
  StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
507
17.1k
  if (Invalid)
508
0
    return SourceLocation();
509
510
  // FIXME: We could consider re-using spelling for tokens we see repeatedly.
511
17.1k
  const char *DestPtr;
512
17.1k
  SourceLocation Spelling =
513
17.1k
      ScratchBuf->getToken(Buffer.data() + LocInfo.second, Length, DestPtr);
514
17.1k
  return SM.createTokenSplitLoc(Spelling, Loc, Loc.getLocWithOffset(Length));
515
17.1k
}
516
517
16.5M
Module *Preprocessor::getCurrentModule() {
518
16.5M
  if (!getLangOpts().isCompilingModule())
519
14.7M
    return nullptr;
520
521
1.89M
  return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
522
16.5M
}
523
524
//===----------------------------------------------------------------------===//
525
// Preprocessor Initialization Methods
526
//===----------------------------------------------------------------------===//
527
528
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
529
/// which implicitly adds the builtin defines etc.
530
96.7k
void Preprocessor::EnterMainSourceFile() {
531
  // We do not allow the preprocessor to reenter the main file.  Doing so will
532
  // cause FileID's to accumulate information from both runs (e.g. #line
533
  // information) and predefined macros aren't guaranteed to be set properly.
534
96.7k
  assert(NumEnteredSourceFiles == 0 && "Cannot reenter the main file!");
535
0
  FileID MainFileID = SourceMgr.getMainFileID();
536
537
  // If MainFileID is loaded it means we loaded an AST file, no need to enter
538
  // a main file.
539
96.7k
  if (!SourceMgr.isLoadedFileID(MainFileID)) {
540
    // Enter the main file source buffer.
541
96.7k
    EnterSourceFile(MainFileID, nullptr, SourceLocation());
542
543
    // If we've been asked to skip bytes in the main file (e.g., as part of a
544
    // precompiled preamble), do so now.
545
96.7k
    if (SkipMainFilePreamble.first > 0)
546
421
      CurLexer->SetByteOffset(SkipMainFilePreamble.first,
547
421
                              SkipMainFilePreamble.second);
548
549
    // Tell the header info that the main file was entered.  If the file is later
550
    // #imported, it won't be re-entered.
551
96.7k
    if (const FileEntry *FE = SourceMgr.getFileEntryForID(MainFileID))
552
75.5k
      HeaderInfo.IncrementIncludeCount(FE);
553
96.7k
  }
554
555
  // Preprocess Predefines to populate the initial preprocessor state.
556
96.7k
  std::unique_ptr<llvm::MemoryBuffer> SB =
557
96.7k
    llvm::MemoryBuffer::getMemBufferCopy(Predefines, "<built-in>");
558
96.7k
  assert(SB && "Cannot create predefined source buffer");
559
0
  FileID FID = SourceMgr.createFileID(std::move(SB));
560
96.7k
  assert(FID.isValid() && "Could not create FileID for predefines?");
561
0
  setPredefinesFileID(FID);
562
563
  // Start parsing the predefines.
564
96.7k
  EnterSourceFile(FID, nullptr, SourceLocation());
565
566
96.7k
  if (!PPOpts->PCHThroughHeader.empty()) {
567
    // Lookup and save the FileID for the through header. If it isn't found
568
    // in the search path, it's a fatal error.
569
30
    const DirectoryLookup *CurDir;
570
30
    Optional<FileEntryRef> File = LookupFile(
571
30
        SourceLocation(), PPOpts->PCHThroughHeader,
572
30
        /*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, CurDir,
573
30
        /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
574
30
        /*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
575
30
        /*IsFrameworkFound=*/nullptr);
576
30
    if (!File) {
577
2
      Diag(SourceLocation(), diag::err_pp_through_header_not_found)
578
2
          << PPOpts->PCHThroughHeader;
579
2
      return;
580
2
    }
581
28
    setPCHThroughHeaderFileID(
582
28
        SourceMgr.createFileID(*File, SourceLocation(), SrcMgr::C_User));
583
28
  }
584
585
  // Skip tokens from the Predefines and if needed the main file.
586
96.7k
  if ((usingPCHWithThroughHeader() && 
SkippingUntilPCHThroughHeader15
) ||
587
96.7k
      
(96.7k
usingPCHWithPragmaHdrStop()96.7k
&&
SkippingUntilPragmaHdrStop8
))
588
23
    SkipTokensWhileUsingPCH();
589
96.7k
}
590
591
28
void Preprocessor::setPCHThroughHeaderFileID(FileID FID) {
592
28
  assert(PCHThroughHeaderFileID.isInvalid() &&
593
28
         "PCHThroughHeaderFileID already set!");
594
0
  PCHThroughHeaderFileID = FID;
595
28
}
596
597
43
bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {
598
43
  assert(PCHThroughHeaderFileID.isValid() &&
599
43
         "Invalid PCH through header FileID");
600
0
  return FE == SourceMgr.getFileEntryForID(PCHThroughHeaderFileID);
601
43
}
602
603
1.42M
bool Preprocessor::creatingPCHWithThroughHeader() {
604
1.42M
  return TUKind == TU_Prefix && 
!PPOpts->PCHThroughHeader.empty()7.67k
&&
605
1.42M
         
PCHThroughHeaderFileID.isValid()40
;
606
1.42M
}
607
608
1.70M
bool Preprocessor::usingPCHWithThroughHeader() {
609
1.70M
  return TUKind != TU_Prefix && 
!PPOpts->PCHThroughHeader.empty()1.69M
&&
610
1.70M
         
PCHThroughHeaderFileID.isValid()43
;
611
1.70M
}
612
613
7
bool Preprocessor::creatingPCHWithPragmaHdrStop() {
614
7
  return TUKind == TU_Prefix && 
PPOpts->PCHWithHdrStop2
;
615
7
}
616
617
193k
bool Preprocessor::usingPCHWithPragmaHdrStop() {
618
193k
  return TUKind != TU_Prefix && 
PPOpts->PCHWithHdrStop186k
;
619
193k
}
620
621
/// Skip tokens until after the #include of the through header or
622
/// until after a #pragma hdrstop is seen. Tokens in the predefines file
623
/// and the main file may be skipped. If the end of the predefines file
624
/// is reached, skipping continues into the main file. If the end of the
625
/// main file is reached, it's a fatal error.
626
23
void Preprocessor::SkipTokensWhileUsingPCH() {
627
23
  bool ReachedMainFileEOF = false;
628
23
  bool UsingPCHThroughHeader = SkippingUntilPCHThroughHeader;
629
23
  bool UsingPragmaHdrStop = SkippingUntilPragmaHdrStop;
630
23
  Token Tok;
631
197
  while (true) {
632
197
    bool InPredefines =
633
197
        (CurLexer && 
CurLexer->getFileID() == getPredefinesFileID()193
);
634
197
    switch (CurLexerKind) {
635
193
    case CLK_Lexer:
636
193
      CurLexer->Lex(Tok);
637
193
     break;
638
4
    case CLK_TokenLexer:
639
4
      CurTokenLexer->Lex(Tok);
640
4
      break;
641
0
    case CLK_CachingLexer:
642
0
      CachingLex(Tok);
643
0
      break;
644
0
    case CLK_LexAfterModuleImport:
645
0
      LexAfterModuleImport(Tok);
646
0
      break;
647
197
    }
648
197
    if (Tok.is(tok::eof) && 
!InPredefines4
) {
649
4
      ReachedMainFileEOF = true;
650
4
      break;
651
4
    }
652
193
    if (UsingPCHThroughHeader && 
!SkippingUntilPCHThroughHeader61
)
653
14
      break;
654
179
    if (UsingPragmaHdrStop && 
!SkippingUntilPragmaHdrStop132
)
655
5
      break;
656
179
  }
657
23
  if (ReachedMainFileEOF) {
658
4
    if (UsingPCHThroughHeader)
659
1
      Diag(SourceLocation(), diag::err_pp_through_header_not_seen)
660
1
          << PPOpts->PCHThroughHeader << 1;
661
3
    else if (!PPOpts->PCHWithHdrStopCreate)
662
1
      Diag(SourceLocation(), diag::err_pp_pragma_hdrstop_not_seen);
663
4
  }
664
23
}
665
666
96.7k
void Preprocessor::replayPreambleConditionalStack() {
667
  // Restore the conditional stack from the preamble, if there is one.
668
96.7k
  if (PreambleConditionalStack.isReplaying()) {
669
28
    assert(CurPPLexer &&
670
28
           "CurPPLexer is null when calling replayPreambleConditionalStack.");
671
0
    CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
672
28
    PreambleConditionalStack.doneReplaying();
673
28
    if (PreambleConditionalStack.reachedEOFWhileSkipping())
674
18
      SkipExcludedConditionalBlock(
675
18
          PreambleConditionalStack.SkipInfo->HashTokenLoc,
676
18
          PreambleConditionalStack.SkipInfo->IfTokenLoc,
677
18
          PreambleConditionalStack.SkipInfo->FoundNonSkipPortion,
678
18
          PreambleConditionalStack.SkipInfo->FoundElse,
679
18
          PreambleConditionalStack.SkipInfo->ElseLoc);
680
28
  }
681
96.7k
}
682
683
69.7k
void Preprocessor::EndSourceFile() {
684
  // Notify the client that we reached the end of the source file.
685
69.7k
  if (Callbacks)
686
68.2k
    Callbacks->EndOfMainFile();
687
69.7k
}
688
689
//===----------------------------------------------------------------------===//
690
// Lexer Event Handling.
691
//===----------------------------------------------------------------------===//
692
693
/// LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the
694
/// identifier information for the token and install it into the token,
695
/// updating the token kind accordingly.
696
622M
IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const {
697
622M
  assert(!Identifier.getRawIdentifier().empty() && "No raw identifier data!");
698
699
  // Look up this token, see if it is a macro, or if it is a language keyword.
700
0
  IdentifierInfo *II;
701
622M
  if (!Identifier.needsCleaning() && 
!Identifier.hasUCN()618M
) {
702
    // No cleaning needed, just use the characters from the lexed buffer.
703
618M
    II = getIdentifierInfo(Identifier.getRawIdentifier());
704
618M
  } else {
705
    // Cleaning needed, alloca a buffer, clean into it, then use the buffer.
706
4.21M
    SmallString<64> IdentifierBuffer;
707
4.21M
    StringRef CleanedStr = getSpelling(Identifier, IdentifierBuffer);
708
709
4.21M
    if (Identifier.hasUCN()) {
710
148
      SmallString<64> UCNIdentifierBuffer;
711
148
      expandUCNs(UCNIdentifierBuffer, CleanedStr);
712
148
      II = getIdentifierInfo(UCNIdentifierBuffer);
713
4.21M
    } else {
714
4.21M
      II = getIdentifierInfo(CleanedStr);
715
4.21M
    }
716
4.21M
  }
717
718
  // Update the token info (identifier info and appropriate token kind).
719
  // FIXME: the raw_identifier may contain leading whitespace which is removed
720
  // from the cleaned identifier token. The SourceLocation should be updated to
721
  // refer to the non-whitespace character. For instance, the text "\\\nB" (a
722
  // line continuation before 'B') is parsed as a single tok::raw_identifier and
723
  // is cleaned to tok::identifier "B". After cleaning the token's length is
724
  // still 3 and the SourceLocation refers to the location of the backslash.
725
622M
  Identifier.setIdentifierInfo(II);
726
622M
  if (getLangOpts().MSVCCompat && 
II->isCPlusPlusOperatorKeyword()9.68M
&&
727
622M
      
getSourceManager().isInSystemHeader(Identifier.getLocation())31
)
728
3
    Identifier.setKind(tok::identifier);
729
622M
  else
730
622M
    Identifier.setKind(II->getTokenID());
731
732
622M
  return II;
733
622M
}
734
735
194k
void Preprocessor::SetPoisonReason(IdentifierInfo *II, unsigned DiagID) {
736
194k
  PoisonReasons[II] = DiagID;
737
194k
}
738
739
0
void Preprocessor::PoisonSEHIdentifiers(bool Poison) {
740
0
  assert(Ident__exception_code && Ident__exception_info);
741
0
  assert(Ident___exception_code && Ident___exception_info);
742
0
  Ident__exception_code->setIsPoisoned(Poison);
743
0
  Ident___exception_code->setIsPoisoned(Poison);
744
0
  Ident_GetExceptionCode->setIsPoisoned(Poison);
745
0
  Ident__exception_info->setIsPoisoned(Poison);
746
0
  Ident___exception_info->setIsPoisoned(Poison);
747
0
  Ident_GetExceptionInfo->setIsPoisoned(Poison);
748
0
  Ident__abnormal_termination->setIsPoisoned(Poison);
749
0
  Ident___abnormal_termination->setIsPoisoned(Poison);
750
0
  Ident_AbnormalTermination->setIsPoisoned(Poison);
751
0
}
752
753
27.0k
void Preprocessor::HandlePoisonedIdentifier(Token & Identifier) {
754
27.0k
  assert(Identifier.getIdentifierInfo() &&
755
27.0k
         "Can't handle identifiers without identifier info!");
756
0
  llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
757
27.0k
    PoisonReasons.find(Identifier.getIdentifierInfo());
758
27.0k
  if(it == PoisonReasons.end())
759
4
    Diag(Identifier, diag::err_pp_used_poisoned_id);
760
27.0k
  else
761
27.0k
    Diag(Identifier,it->second) << Identifier.getIdentifierInfo();
762
27.0k
}
763
764
/// Returns a diagnostic message kind for reporting a future keyword as
765
/// appropriate for the identifier and specified language.
766
static diag::kind getFutureCompatDiagKind(const IdentifierInfo &II,
767
192
                                          const LangOptions &LangOpts) {
768
192
  assert(II.isFutureCompatKeyword() && "diagnostic should not be needed");
769
770
192
  if (LangOpts.CPlusPlus)
771
192
    return llvm::StringSwitch<diag::kind>(II.getName())
772
192
#define CXX11_KEYWORD(NAME, FLAGS)                                             \
773
1.92k
        .Case(#NAME, diag::warn_cxx11_keyword)
774
192
#define CXX20_KEYWORD(NAME, FLAGS)                                             \
775
1.34k
        .Case(#NAME, diag::warn_cxx20_keyword)
776
192
#include "clang/Basic/TokenKinds.def"
777
        // char8_t is not modeled as a CXX20_KEYWORD because it's not
778
        // unconditionally enabled in C++20 mode. (It can be disabled
779
        // by -fno-char8_t.)
780
192
        .Case("char8_t", diag::warn_cxx20_keyword)
781
0
        ;
782
783
0
  llvm_unreachable(
784
0
      "Keyword not known to come from a newer Standard or proposed Standard");
785
0
}
786
787
45.0k
void Preprocessor::updateOutOfDateIdentifier(IdentifierInfo &II) const {
788
45.0k
  assert(II.isOutOfDate() && "not out of date");
789
0
  getExternalSource()->updateOutOfDateIdentifier(II);
790
45.0k
}
791
792
/// HandleIdentifier - This callback is invoked when the lexer reads an
793
/// identifier.  This callback looks up the identifier in the map and/or
794
/// potentially macro expands it or turns it into a named token (like 'for').
795
///
796
/// Note that callers of this method are guarded by checking the
797
/// IdentifierInfo's 'isHandleIdentifierCase' bit.  If this method changes, the
798
/// IdentifierInfo methods that compute these properties will need to change to
799
/// match.
800
87.3M
bool Preprocessor::HandleIdentifier(Token &Identifier) {
801
87.3M
  assert(Identifier.getIdentifierInfo() &&
802
87.3M
         "Can't handle identifiers without identifier info!");
803
804
0
  IdentifierInfo &II = *Identifier.getIdentifierInfo();
805
806
  // If the information about this identifier is out of date, update it from
807
  // the external source.
808
  // We have to treat __VA_ARGS__ in a special way, since it gets
809
  // serialized with isPoisoned = true, but our preprocessor may have
810
  // unpoisoned it if we're defining a C99 macro.
811
87.3M
  if (II.isOutOfDate()) {
812
43.9k
    bool CurrentIsPoisoned = false;
813
43.9k
    const bool IsSpecialVariadicMacro =
814
43.9k
        &II == Ident__VA_ARGS__ || 
&II == Ident__VA_OPT__43.8k
;
815
43.9k
    if (IsSpecialVariadicMacro)
816
97
      CurrentIsPoisoned = II.isPoisoned();
817
818
43.9k
    updateOutOfDateIdentifier(II);
819
43.9k
    Identifier.setKind(II.getTokenID());
820
821
43.9k
    if (IsSpecialVariadicMacro)
822
97
      II.setIsPoisoned(CurrentIsPoisoned);
823
43.9k
  }
824
825
  // If this identifier was poisoned, and if it was not produced from a macro
826
  // expansion, emit an error.
827
87.3M
  if (II.isPoisoned() && 
CurPPLexer27.0k
) {
828
27.0k
    HandlePoisonedIdentifier(Identifier);
829
27.0k
  }
830
831
  // If this is a macro to be expanded, do it.
832
87.3M
  if (MacroDefinition MD = getMacroDefinition(&II)) {
833
87.1M
    auto *MI = MD.getMacroInfo();
834
87.1M
    assert(MI && "macro definition with no macro info?");
835
87.1M
    if (!DisableMacroExpansion) {
836
64.6M
      if (!Identifier.isExpandDisabled() && 
MI->isEnabled()64.6M
) {
837
        // C99 6.10.3p10: If the preprocessing token immediately after the
838
        // macro name isn't a '(', this macro should not be expanded.
839
64.6M
        if (!MI->isFunctionLike() || 
isNextPPTokenLParen()21.8M
)
840
62.4M
          return HandleMacroExpandedIdentifier(Identifier, MD);
841
64.6M
      } else {
842
        // C99 6.10.3.4p2 says that a disabled macro may never again be
843
        // expanded, even if it's in a context where it could be expanded in the
844
        // future.
845
2.50k
        Identifier.setFlag(Token::DisableExpand);
846
2.50k
        if (MI->isObjectLike() || 
isNextPPTokenLParen()512
)
847
2.08k
          Diag(Identifier, diag::pp_disabled_macro_expansion);
848
2.50k
      }
849
64.6M
    }
850
87.1M
  }
851
852
  // If this identifier is a keyword in a newer Standard or proposed Standard,
853
  // produce a warning. Don't warn if we're not considering macro expansion,
854
  // since this identifier might be the name of a macro.
855
  // FIXME: This warning is disabled in cases where it shouldn't be, like
856
  //   "#define constexpr constexpr", "int constexpr;"
857
24.9M
  if (II.isFutureCompatKeyword() && 
!DisableMacroExpansion923
) {
858
192
    Diag(Identifier, getFutureCompatDiagKind(II, getLangOpts()))
859
192
        << II.getName();
860
    // Don't diagnose this keyword again in this translation unit.
861
192
    II.setIsFutureCompatKeyword(false);
862
192
  }
863
864
  // If this is an extension token, diagnose its use.
865
  // We avoid diagnosing tokens that originate from macro definitions.
866
  // FIXME: This warning is disabled in cases where it shouldn't be,
867
  // like "#define TY typeof", "TY(1) x".
868
24.9M
  if (II.isExtensionToken() && 
!DisableMacroExpansion7.65k
)
869
6.03k
    Diag(Identifier, diag::ext_token_used);
870
871
  // If this is the 'import' contextual keyword following an '@', note
872
  // that the next token indicates a module name.
873
  //
874
  // Note that we do not treat 'import' as a contextual
875
  // keyword when we're in a caching lexer, because caching lexers only get
876
  // used in contexts where import declarations are disallowed.
877
  //
878
  // Likewise if this is the C++ Modules TS import keyword.
879
24.9M
  if (((LastTokenWasAt && 
II.isModulesImport()2.75k
) ||
880
24.9M
       
Identifier.is(tok::kw_import)24.9M
) &&
881
24.9M
      
!InMacroArgs1.88k
&&
!DisableMacroExpansion1.88k
&&
882
24.9M
      
(1.87k
getLangOpts().Modules1.87k
||
getLangOpts().DebuggerSupport43
) &&
883
24.9M
      
CurLexerKind != CLK_CachingLexer1.87k
) {
884
1.87k
    ModuleImportLoc = Identifier.getLocation();
885
1.87k
    ModuleImportPath.clear();
886
1.87k
    ModuleImportExpectsIdentifier = true;
887
1.87k
    CurLexerKind = CLK_LexAfterModuleImport;
888
1.87k
  }
889
24.9M
  return true;
890
87.3M
}
891
892
2.18G
void Preprocessor::Lex(Token &Result) {
893
2.18G
  ++LexLevel;
894
895
  // We loop here until a lex function returns a token; this avoids recursion.
896
2.18G
  bool ReturnedToken;
897
2.37G
  do {
898
2.37G
    switch (CurLexerKind) {
899
1.45G
    case CLK_Lexer:
900
1.45G
      ReturnedToken = CurLexer->Lex(Result);
901
1.45G
      break;
902
675M
    case CLK_TokenLexer:
903
675M
      ReturnedToken = CurTokenLexer->Lex(Result);
904
675M
      break;
905
235M
    case CLK_CachingLexer:
906
235M
      CachingLex(Result);
907
235M
      ReturnedToken = true;
908
235M
      break;
909
4.30k
    case CLK_LexAfterModuleImport:
910
4.30k
      ReturnedToken = LexAfterModuleImport(Result);
911
4.30k
      break;
912
2.37G
    }
913
2.37G
  } while (
!ReturnedToken2.37G
);
914
915
2.18G
  if (Result.is(tok::unknown) && 
TheModuleLoader.HadFatalFailure14.7k
)
916
0
    return;
917
918
2.18G
  if (Result.is(tok::code_completion) && 
Result.getIdentifierInfo()3.36k
) {
919
    // Remember the identifier before code completion token.
920
85
    setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
921
85
    setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
922
    // Set IdenfitierInfo to null to avoid confusing code that handles both
923
    // identifiers and completion tokens.
924
85
    Result.setIdentifierInfo(nullptr);
925
85
  }
926
927
  // Update ImportSeqState to track our position within a C++20 import-seq
928
  // if this token is being produced as a result of phase 4 of translation.
929
2.18G
  if (getLangOpts().CPlusPlusModules && 
LexLevel == 16.77M
&&
930
2.18G
      
!Result.getFlag(Token::IsReinjected)983k
) {
931
718k
    switch (Result.getKind()) {
932
108k
    
case tok::l_paren: 80.9k
case tok::l_square: 85.0k
case tok::l_brace:
933
108k
      ImportSeqState.handleOpenBracket();
934
108k
      break;
935
85.0k
    
case tok::r_paren: 80.9k
case tok::r_square:
936
85.0k
      ImportSeqState.handleCloseBracket();
937
85.0k
      break;
938
23.5k
    case tok::r_brace:
939
23.5k
      ImportSeqState.handleCloseBrace();
940
23.5k
      break;
941
56.0k
    case tok::semi:
942
56.0k
      ImportSeqState.handleSemi();
943
56.0k
      break;
944
15
    case tok::header_name:
945
24
    case tok::annot_header_unit:
946
24
      ImportSeqState.handleHeaderName();
947
24
      break;
948
87
    case tok::kw_export:
949
87
      ImportSeqState.handleExport();
950
87
      break;
951
180k
    case tok::identifier:
952
180k
      if (Result.getIdentifierInfo()->isModulesImport()) {
953
50
        ImportSeqState.handleImport();
954
50
        if (ImportSeqState.afterImportSeq()) {
955
32
          ModuleImportLoc = Result.getLocation();
956
32
          ModuleImportPath.clear();
957
32
          ModuleImportExpectsIdentifier = true;
958
32
          CurLexerKind = CLK_LexAfterModuleImport;
959
32
        }
960
50
        break;
961
50
      }
962
180k
      
LLVM_FALLTHROUGH180k
;180k
963
444k
    default:
964
444k
      ImportSeqState.handleMisc();
965
444k
      break;
966
718k
    }
967
718k
  }
968
969
2.18G
  LastTokenWasAt = Result.is(tok::at);
970
2.18G
  --LexLevel;
971
972
2.18G
  if ((LexLevel == 0 || 
PreprocessToken845M
) &&
973
2.18G
      
!Result.getFlag(Token::IsReinjected)1.34G
) {
974
1.19G
    if (LexLevel == 0)
975
1.19G
      ++TokenCount;
976
1.19G
    if (OnToken)
977
79.0k
      OnToken(Result);
978
1.19G
  }
979
2.18G
}
980
981
/// Lex a header-name token (including one formed from header-name-tokens if
982
/// \p AllowConcatenation is \c true).
983
///
984
/// \param FilenameTok Filled in with the next token. On success, this will
985
///        be either a header_name token. On failure, it will be whatever other
986
///        token was found instead.
987
/// \param AllowMacroExpansion If \c true, allow the header name to be formed
988
///        by macro expansion (concatenating tokens as necessary if the first
989
///        token is a '<').
990
/// \return \c true if we reached EOD or EOF while looking for a > token in
991
///         a concatenated header name and diagnosed it. \c false otherwise.
992
1.64M
bool Preprocessor::LexHeaderName(Token &FilenameTok, bool AllowMacroExpansion) {
993
  // Lex using header-name tokenization rules if tokens are being lexed from
994
  // a file. Just grab a token normally if we're in a macro expansion.
995
1.64M
  if (CurPPLexer)
996
1.64M
    CurPPLexer->LexIncludeFilename(FilenameTok);
997
29
  else
998
29
    Lex(FilenameTok);
999
1000
  // This could be a <foo/bar.h> file coming from a macro expansion.  In this
1001
  // case, glue the tokens together into an angle_string_literal token.
1002
1.64M
  SmallString<128> FilenameBuffer;
1003
1.64M
  if (FilenameTok.is(tok::less) && 
AllowMacroExpansion23
) {
1004
23
    bool StartOfLine = FilenameTok.isAtStartOfLine();
1005
23
    bool LeadingSpace = FilenameTok.hasLeadingSpace();
1006
23
    bool LeadingEmptyMacro = FilenameTok.hasLeadingEmptyMacro();
1007
1008
23
    SourceLocation Start = FilenameTok.getLocation();
1009
23
    SourceLocation End;
1010
23
    FilenameBuffer.push_back('<');
1011
1012
    // Consume tokens until we find a '>'.
1013
    // FIXME: A header-name could be formed starting or ending with an
1014
    // alternative token. It's not clear whether that's ill-formed in all
1015
    // cases.
1016
109
    while (FilenameTok.isNot(tok::greater)) {
1017
91
      Lex(FilenameTok);
1018
91
      if (FilenameTok.isOneOf(tok::eod, tok::eof)) {
1019
5
        Diag(FilenameTok.getLocation(), diag::err_expected) << tok::greater;
1020
5
        Diag(Start, diag::note_matching) << tok::less;
1021
5
        return true;
1022
5
      }
1023
1024
86
      End = FilenameTok.getLocation();
1025
1026
      // FIXME: Provide code completion for #includes.
1027
86
      if (FilenameTok.is(tok::code_completion)) {
1028
0
        setCodeCompletionReached();
1029
0
        Lex(FilenameTok);
1030
0
        continue;
1031
0
      }
1032
1033
      // Append the spelling of this token to the buffer. If there was a space
1034
      // before it, add it now.
1035
86
      if (FilenameTok.hasLeadingSpace())
1036
4
        FilenameBuffer.push_back(' ');
1037
1038
      // Get the spelling of the token, directly into FilenameBuffer if
1039
      // possible.
1040
86
      size_t PreAppendSize = FilenameBuffer.size();
1041
86
      FilenameBuffer.resize(PreAppendSize + FilenameTok.getLength());
1042
1043
86
      const char *BufPtr = &FilenameBuffer[PreAppendSize];
1044
86
      unsigned ActualLen = getSpelling(FilenameTok, BufPtr);
1045
1046
      // If the token was spelled somewhere else, copy it into FilenameBuffer.
1047
86
      if (BufPtr != &FilenameBuffer[PreAppendSize])
1048
86
        memcpy(&FilenameBuffer[PreAppendSize], BufPtr, ActualLen);
1049
1050
      // Resize FilenameBuffer to the correct size.
1051
86
      if (FilenameTok.getLength() != ActualLen)
1052
0
        FilenameBuffer.resize(PreAppendSize + ActualLen);
1053
86
    }
1054
1055
18
    FilenameTok.startToken();
1056
18
    FilenameTok.setKind(tok::header_name);
1057
18
    FilenameTok.setFlagValue(Token::StartOfLine, StartOfLine);
1058
18
    FilenameTok.setFlagValue(Token::LeadingSpace, LeadingSpace);
1059
18
    FilenameTok.setFlagValue(Token::LeadingEmptyMacro, LeadingEmptyMacro);
1060
18
    CreateString(FilenameBuffer, FilenameTok, Start, End);
1061
1.64M
  } else if (FilenameTok.is(tok::string_literal) && 
AllowMacroExpansion83
) {
1062
    // Convert a string-literal token of the form " h-char-sequence "
1063
    // (produced by macro expansion) into a header-name token.
1064
    //
1065
    // The rules for header-names don't quite match the rules for
1066
    // string-literals, but all the places where they differ result in
1067
    // undefined behavior, so we can and do treat them the same.
1068
    //
1069
    // A string-literal with a prefix or suffix is not translated into a
1070
    // header-name. This could theoretically be observable via the C++20
1071
    // context-sensitive header-name formation rules.
1072
82
    StringRef Str = getSpelling(FilenameTok, FilenameBuffer);
1073
82
    if (Str.size() >= 2 && Str.front() == '"' && Str.back() == '"')
1074
82
      FilenameTok.setKind(tok::header_name);
1075
82
  }
1076
1077
1.64M
  return false;
1078
1.64M
}
1079
1080
/// Collect the tokens of a C++20 pp-import-suffix.
1081
39
void Preprocessor::CollectPpImportSuffix(SmallVectorImpl<Token> &Toks) {
1082
  // FIXME: For error recovery, consider recognizing attribute syntax here
1083
  // and terminating / diagnosing a missing semicolon if we find anything
1084
  // else? (Can we leave that to the parser?)
1085
39
  unsigned BracketDepth = 0;
1086
104
  while (true) {
1087
104
    Toks.emplace_back();
1088
104
    Lex(Toks.back());
1089
1090
104
    switch (Toks.back().getKind()) {
1091
16
    
case tok::l_paren: 0
case tok::l_square: 14
case tok::l_brace:
1092
16
      ++BracketDepth;
1093
16
      break;
1094
1095
28
    
case tok::r_paren: 0
case tok::r_square: 26
case tok::r_brace:
1096
28
      if (BracketDepth == 0)
1097
12
        return;
1098
16
      --BracketDepth;
1099
16
      break;
1100
1101
26
    case tok::semi:
1102
26
      if (BracketDepth == 0)
1103
26
        return;
1104
0
    break;
1105
1106
1
    case tok::eof:
1107
1
      return;
1108
1109
33
    default:
1110
33
      break;
1111
104
    }
1112
104
  }
1113
39
}
1114
1115
1116
/// Lex a token following the 'import' contextual keyword.
1117
///
1118
///     pp-import: [C++20]
1119
///           import header-name pp-import-suffix[opt] ;
1120
///           import header-name-tokens pp-import-suffix[opt] ;
1121
/// [ObjC]    @ import module-name ;
1122
/// [Clang]   import module-name ;
1123
///
1124
///     header-name-tokens:
1125
///           string-literal
1126
///           < [any sequence of preprocessing-tokens other than >] >
1127
///
1128
///     module-name:
1129
///           module-name-qualifier[opt] identifier
1130
///
1131
///     module-name-qualifier
1132
///           module-name-qualifier[opt] identifier .
1133
///
1134
/// We respond to a pp-import by importing macros from the named module.
1135
4.30k
bool Preprocessor::LexAfterModuleImport(Token &Result) {
1136
  // Figure out what kind of lexer we actually have.
1137
4.30k
  recomputeCurLexerKind();
1138
1139
  // Lex the next token. The header-name lexing rules are used at the start of
1140
  // a pp-import.
1141
  //
1142
  // For now, we only support header-name imports in C++20 mode.
1143
  // FIXME: Should we allow this in all language modes that support an import
1144
  // declaration as an extension?
1145
4.30k
  if (ModuleImportPath.empty() && 
getLangOpts().CPlusPlusModules1.90k
) {
1146
32
    if (LexHeaderName(Result))
1147
0
      return true;
1148
4.27k
  } else {
1149
4.27k
    Lex(Result);
1150
4.27k
  }
1151
1152
  // Allocate a holding buffer for a sequence of tokens and introduce it into
1153
  // the token stream.
1154
4.30k
  auto EnterTokens = [this](ArrayRef<Token> Toks) {
1155
39
    auto ToksCopy = std::make_unique<Token[]>(Toks.size());
1156
39
    std::copy(Toks.begin(), Toks.end(), ToksCopy.get());
1157
39
    EnterTokenStream(std::move(ToksCopy), Toks.size(),
1158
39
                     /*DisableMacroExpansion*/ true, /*IsReinject*/ false);
1159
39
  };
1160
1161
  // Check for a header-name.
1162
4.30k
  SmallVector<Token, 32> Suffix;
1163
4.30k
  if (Result.is(tok::header_name)) {
1164
    // Enter the header-name token into the token stream; a Lex action cannot
1165
    // both return a token and cache tokens (doing so would corrupt the token
1166
    // cache if the call to Lex comes from CachingLex / PeekAhead).
1167
24
    Suffix.push_back(Result);
1168
1169
    // Consume the pp-import-suffix and expand any macros in it now. We'll add
1170
    // it back into the token stream later.
1171
24
    CollectPpImportSuffix(Suffix);
1172
24
    if (Suffix.back().isNot(tok::semi)) {
1173
      // This is not a pp-import after all.
1174
0
      EnterTokens(Suffix);
1175
0
      return false;
1176
0
    }
1177
1178
    // C++2a [cpp.module]p1:
1179
    //   The ';' preprocessing-token terminating a pp-import shall not have
1180
    //   been produced by macro replacement.
1181
24
    SourceLocation SemiLoc = Suffix.back().getLocation();
1182
24
    if (SemiLoc.isMacroID())
1183
1
      Diag(SemiLoc, diag::err_header_import_semi_in_macro);
1184
1185
    // Reconstitute the import token.
1186
24
    Token ImportTok;
1187
24
    ImportTok.startToken();
1188
24
    ImportTok.setKind(tok::kw_import);
1189
24
    ImportTok.setLocation(ModuleImportLoc);
1190
24
    ImportTok.setIdentifierInfo(getIdentifierInfo("import"));
1191
24
    ImportTok.setLength(6);
1192
1193
24
    auto Action = HandleHeaderIncludeOrImport(
1194
24
        /*HashLoc*/ SourceLocation(), ImportTok, Suffix.front(), SemiLoc);
1195
24
    switch (Action.Kind) {
1196
15
    case ImportAction::None:
1197
15
      break;
1198
1199
0
    case ImportAction::ModuleBegin:
1200
      // Let the parser know we're textually entering the module.
1201
0
      Suffix.emplace_back();
1202
0
      Suffix.back().startToken();
1203
0
      Suffix.back().setKind(tok::annot_module_begin);
1204
0
      Suffix.back().setLocation(SemiLoc);
1205
0
      Suffix.back().setAnnotationEndLoc(SemiLoc);
1206
0
      Suffix.back().setAnnotationValue(Action.ModuleForHeader);
1207
0
      LLVM_FALLTHROUGH;
1208
1209
9
    case ImportAction::ModuleImport:
1210
9
    case ImportAction::SkippedModuleImport:
1211
      // We chose to import (or textually enter) the file. Convert the
1212
      // header-name token into a header unit annotation token.
1213
9
      Suffix[0].setKind(tok::annot_header_unit);
1214
9
      Suffix[0].setAnnotationEndLoc(Suffix[0].getLocation());
1215
9
      Suffix[0].setAnnotationValue(Action.ModuleForHeader);
1216
      // FIXME: Call the moduleImport callback?
1217
9
      break;
1218
0
    case ImportAction::Failure:
1219
0
      assert(TheModuleLoader.HadFatalFailure &&
1220
0
             "This should be an early exit only to a fatal error");
1221
0
      Result.setKind(tok::eof);
1222
0
      CurLexer->cutOffLexing();
1223
0
      EnterTokens(Suffix);
1224
0
      return true;
1225
24
    }
1226
1227
24
    EnterTokens(Suffix);
1228
24
    return false;
1229
24
  }
1230
1231
  // The token sequence
1232
  //
1233
  //   import identifier (. identifier)*
1234
  //
1235
  // indicates a module import directive. We already saw the 'import'
1236
  // contextual keyword, so now we're looking for the identifiers.
1237
4.28k
  if (ModuleImportExpectsIdentifier && 
Result.getKind() == tok::identifier2.14k
) {
1238
    // We expected to see an identifier here, and we did; continue handling
1239
    // identifiers.
1240
2.13k
    ModuleImportPath.push_back(std::make_pair(Result.getIdentifierInfo(),
1241
2.13k
                                              Result.getLocation()));
1242
2.13k
    ModuleImportExpectsIdentifier = false;
1243
2.13k
    CurLexerKind = CLK_LexAfterModuleImport;
1244
2.13k
    return true;
1245
2.13k
  }
1246
1247
  // If we're expecting a '.' or a ';', and we got a '.', then wait until we
1248
  // see the next identifier. (We can also see a '[[' that begins an
1249
  // attribute-specifier-seq here under the C++ Modules TS.)
1250
2.14k
  if (!ModuleImportExpectsIdentifier && 
Result.getKind() == tok::period2.13k
) {
1251
270
    ModuleImportExpectsIdentifier = true;
1252
270
    CurLexerKind = CLK_LexAfterModuleImport;
1253
270
    return true;
1254
270
  }
1255
1256
  // If we didn't recognize a module name at all, this is not a (valid) import.
1257
1.87k
  if (ModuleImportPath.empty() || 
Result.is(tok::eof)1.87k
)
1258
8
    return true;
1259
1260
  // Consume the pp-import-suffix and expand any macros in it now, if we're not
1261
  // at the semicolon already.
1262
1.87k
  SourceLocation SemiLoc = Result.getLocation();
1263
1.87k
  if (Result.isNot(tok::semi)) {
1264
15
    Suffix.push_back(Result);
1265
15
    CollectPpImportSuffix(Suffix);
1266
15
    if (Suffix.back().isNot(tok::semi)) {
1267
      // This is not an import after all.
1268
13
      EnterTokens(Suffix);
1269
13
      return false;
1270
13
    }
1271
2
    SemiLoc = Suffix.back().getLocation();
1272
2
  }
1273
1274
  // Under the Modules TS, the dot is just part of the module name, and not
1275
  // a real hierarchy separator. Flatten such module names now.
1276
  //
1277
  // FIXME: Is this the right level to be performing this transformation?
1278
1.85k
  std::string FlatModuleName;
1279
1.85k
  if (getLangOpts().ModulesTS || 
getLangOpts().CPlusPlusModules1.79k
) {
1280
72
    for (auto &Piece : ModuleImportPath) {
1281
72
      if (!FlatModuleName.empty())
1282
7
        FlatModuleName += ".";
1283
72
      FlatModuleName += Piece.first->getName();
1284
72
    }
1285
65
    SourceLocation FirstPathLoc = ModuleImportPath[0].second;
1286
65
    ModuleImportPath.clear();
1287
65
    ModuleImportPath.push_back(
1288
65
        std::make_pair(getIdentifierInfo(FlatModuleName), FirstPathLoc));
1289
65
  }
1290
1291
1.85k
  Module *Imported = nullptr;
1292
1.85k
  if (getLangOpts().Modules) {
1293
1.81k
    Imported = TheModuleLoader.loadModule(ModuleImportLoc,
1294
1.81k
                                          ModuleImportPath,
1295
1.81k
                                          Module::Hidden,
1296
1.81k
                                          /*IsInclusionDirective=*/false);
1297
1.81k
    if (Imported)
1298
1.70k
      makeModuleVisible(Imported, SemiLoc);
1299
1.81k
  }
1300
1.85k
  if (Callbacks)
1301
1.85k
    Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
1302
1303
1.85k
  if (!Suffix.empty()) {
1304
2
    EnterTokens(Suffix);
1305
2
    return false;
1306
2
  }
1307
1.85k
  return true;
1308
1.85k
}
1309
1310
100k
void Preprocessor::makeModuleVisible(Module *M, SourceLocation Loc) {
1311
100k
  CurSubmoduleState->VisibleModules.setVisible(
1312
668k
      M, Loc, [](Module *) {},
1313
100k
      [&](ArrayRef<Module *> Path, Module *Conflict, StringRef Message) {
1314
        // FIXME: Include the path in the diagnostic.
1315
        // FIXME: Include the import location for the conflicting module.
1316
1
        Diag(ModuleImportLoc, diag::warn_module_conflict)
1317
1
            << Path[0]->getFullModuleName()
1318
1
            << Conflict->getFullModuleName()
1319
1
            << Message;
1320
1
      });
1321
1322
  // Add this module to the imports list of the currently-built submodule.
1323
100k
  if (!BuildingSubmoduleStack.empty() && 
M != BuildingSubmoduleStack.back().M78.3k
)
1324
76.8k
    BuildingSubmoduleStack.back().M->Imports.insert(M);
1325
100k
}
1326
1327
bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String,
1328
                                          const char *DiagnosticTag,
1329
56.2k
                                          bool AllowMacroExpansion) {
1330
  // We need at least one string literal.
1331
56.2k
  if (Result.isNot(tok::string_literal)) {
1332
15
    Diag(Result, diag::err_expected_string_literal)
1333
15
      << /*Source='in...'*/0 << DiagnosticTag;
1334
15
    return false;
1335
15
  }
1336
1337
  // Lex string literal tokens, optionally with macro expansion.
1338
56.2k
  SmallVector<Token, 4> StrToks;
1339
56.2k
  do {
1340
56.2k
    StrToks.push_back(Result);
1341
1342
56.2k
    if (Result.hasUDSuffix())
1343
4
      Diag(Result, diag::err_invalid_string_udl);
1344
1345
56.2k
    if (AllowMacroExpansion)
1346
147
      Lex(Result);
1347
56.0k
    else
1348
56.0k
      LexUnexpandedToken(Result);
1349
56.2k
  } while (Result.is(tok::string_literal));
1350
1351
  // Concatenate and parse the strings.
1352
56.2k
  StringLiteralParser Literal(StrToks, *this);
1353
56.2k
  assert(Literal.isAscii() && "Didn't allow wide strings in");
1354
1355
56.2k
  if (Literal.hadError)
1356
0
    return false;
1357
1358
56.2k
  if (Literal.Pascal) {
1359
0
    Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
1360
0
      << /*Source='in...'*/0 << DiagnosticTag;
1361
0
    return false;
1362
0
  }
1363
1364
56.2k
  String = std::string(Literal.GetString());
1365
56.2k
  return true;
1366
56.2k
}
1367
1368
101
bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value) {
1369
101
  assert(Tok.is(tok::numeric_constant));
1370
0
  SmallString<8> IntegerBuffer;
1371
101
  bool NumberInvalid = false;
1372
101
  StringRef Spelling = getSpelling(Tok, IntegerBuffer, &NumberInvalid);
1373
101
  if (NumberInvalid)
1374
0
    return false;
1375
101
  NumericLiteralParser Literal(Spelling, Tok.getLocation(), getSourceManager(),
1376
101
                               getLangOpts(), getTargetInfo(),
1377
101
                               getDiagnostics());
1378
101
  if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
1379
1
    return false;
1380
100
  llvm::APInt APVal(64, 0);
1381
100
  if (Literal.GetIntegerValue(APVal))
1382
0
    return false;
1383
100
  Lex(Tok);
1384
100
  Value = APVal.getLimitedValue();
1385
100
  return true;
1386
100
}
1387
1388
111k
void Preprocessor::addCommentHandler(CommentHandler *Handler) {
1389
111k
  assert(Handler && "NULL comment handler");
1390
0
  assert(llvm::find(CommentHandlers, Handler) == CommentHandlers.end() &&
1391
111k
         "Comment handler already registered");
1392
0
  CommentHandlers.push_back(Handler);
1393
111k
}
1394
1395
111k
void Preprocessor::removeCommentHandler(CommentHandler *Handler) {
1396
111k
  std::vector<CommentHandler *>::iterator Pos =
1397
111k
      llvm::find(CommentHandlers, Handler);
1398
111k
  assert(Pos != CommentHandlers.end() && "Comment handler not registered");
1399
0
  CommentHandlers.erase(Pos);
1400
111k
}
1401
1402
72.6M
bool Preprocessor::HandleComment(Token &result, SourceRange Comment) {
1403
72.6M
  bool AnyPendingTokens = false;
1404
72.6M
  for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
1405
72.6M
       HEnd = CommentHandlers.end();
1406
166M
       H != HEnd; 
++H93.4M
) {
1407
93.4M
    if ((*H)->HandleComment(*this, Comment))
1408
0
      AnyPendingTokens = true;
1409
93.4M
  }
1410
72.6M
  if (!AnyPendingTokens || 
getCommentRetentionState()0
)
1411
72.6M
    return false;
1412
18.4E
  Lex(result);
1413
18.4E
  return true;
1414
72.6M
}
1415
1416
9
void Preprocessor::emitMacroDeprecationWarning(const Token &Identifier) {
1417
9
  auto DepMsg = getMacroDeprecationMsg(Identifier.getIdentifierInfo());
1418
9
  if (!DepMsg)
1419
8
    Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
1420
8
        << Identifier.getIdentifierInfo() << 0;
1421
1
  else
1422
1
    Diag(Identifier, diag::warn_pragma_deprecated_macro_use)
1423
1
        << Identifier.getIdentifierInfo() << 1 << *DepMsg;
1424
9
}
1425
1426
9
void Preprocessor::emitMacroUnsafeHeaderWarning(const Token &Identifier) {
1427
9
  auto DepMsg = getRestrictExpansionMsg(Identifier.getIdentifierInfo());
1428
9
  if (DepMsg.first.empty())
1429
1
    Diag(Identifier, diag::warn_pragma_restrict_expansion_macro_use)
1430
1
        << Identifier.getIdentifierInfo() << 0;
1431
8
  else
1432
8
    Diag(Identifier, diag::warn_pragma_restrict_expansion_macro_use)
1433
8
        << Identifier.getIdentifierInfo() << 1 << DepMsg.first;
1434
9
  Diag(DepMsg.second, diag::note_pp_macro_annotation) << 1;
1435
9
}
1436
1437
98.9k
ModuleLoader::~ModuleLoader() = default;
1438
1439
111k
CommentHandler::~CommentHandler() = default;
1440
1441
80
EmptylineHandler::~EmptylineHandler() = default;
1442
1443
94.2k
CodeCompletionHandler::~CodeCompletionHandler() = default;
1444
1445
2.10k
void Preprocessor::createPreprocessingRecord() {
1446
2.10k
  if (Record)
1447
0
    return;
1448
1449
2.10k
  Record = new PreprocessingRecord(getSourceManager());
1450
2.10k
  addPPCallbacks(std::unique_ptr<PPCallbacks>(Record));
1451
2.10k
}