clang  16.0.0git
Pragma.cpp
Go to the documentation of this file.
1 //===- Pragma.cpp - Pragma registration and handling ----------------------===//
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 PragmaHandler/PragmaTable interfaces and implements
10 // pragma related methods of the Preprocessor class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Lex/Pragma.h"
15 #include "clang/Basic/CLWarnings.h"
16 #include "clang/Basic/Diagnostic.h"
19 #include "clang/Basic/LLVM.h"
21 #include "clang/Basic/Module.h"
24 #include "clang/Basic/TokenKinds.h"
25 #include "clang/Lex/HeaderSearch.h"
27 #include "clang/Lex/Lexer.h"
29 #include "clang/Lex/MacroInfo.h"
30 #include "clang/Lex/ModuleLoader.h"
31 #include "clang/Lex/PPCallbacks.h"
32 #include "clang/Lex/Preprocessor.h"
35 #include "clang/Lex/Token.h"
36 #include "clang/Lex/TokenLexer.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/DenseMap.h"
39 #include "llvm/ADT/STLExtras.h"
40 #include "llvm/ADT/SmallString.h"
41 #include "llvm/ADT/SmallVector.h"
42 #include "llvm/ADT/StringRef.h"
43 #include "llvm/Support/Compiler.h"
44 #include "llvm/Support/ErrorHandling.h"
45 #include "llvm/Support/Timer.h"
46 #include <algorithm>
47 #include <cassert>
48 #include <cstddef>
49 #include <cstdint>
50 #include <limits>
51 #include <string>
52 #include <utility>
53 #include <vector>
54 
55 using namespace clang;
56 
57 // Out-of-line destructor to provide a home for the class.
59 
60 //===----------------------------------------------------------------------===//
61 // EmptyPragmaHandler Implementation.
62 //===----------------------------------------------------------------------===//
63 
65 
67  PragmaIntroducer Introducer,
68  Token &FirstToken) {}
69 
70 //===----------------------------------------------------------------------===//
71 // PragmaNamespace Implementation.
72 //===----------------------------------------------------------------------===//
73 
74 /// FindHandler - Check to see if there is already a handler for the
75 /// specified name. If not, return the handler for the null identifier if it
76 /// exists, otherwise return null. If IgnoreNull is true (the default) then
77 /// the null handler isn't returned on failure to match.
79  bool IgnoreNull) const {
80  auto I = Handlers.find(Name);
81  if (I != Handlers.end())
82  return I->getValue().get();
83  if (IgnoreNull)
84  return nullptr;
85  I = Handlers.find(StringRef());
86  if (I != Handlers.end())
87  return I->getValue().get();
88  return nullptr;
89 }
90 
92  assert(!Handlers.count(Handler->getName()) &&
93  "A handler with this name is already registered in this namespace");
94  Handlers[Handler->getName()].reset(Handler);
95 }
96 
98  auto I = Handlers.find(Handler->getName());
99  assert(I != Handlers.end() &&
100  "Handler not registered in this namespace");
101  // Release ownership back to the caller.
102  I->getValue().release();
103  Handlers.erase(I);
104 }
105 
107  PragmaIntroducer Introducer, Token &Tok) {
108  // Read the 'namespace' that the directive is in, e.g. STDC. Do not macro
109  // expand it, the user can have a STDC #define, that should not affect this.
110  PP.LexUnexpandedToken(Tok);
111 
112  // Get the handler for this token. If there is no handler, ignore the pragma.
113  PragmaHandler *Handler
115  : StringRef(),
116  /*IgnoreNull=*/false);
117  if (!Handler) {
118  PP.Diag(Tok, diag::warn_pragma_ignored);
119  return;
120  }
121 
122  // Otherwise, pass it down.
123  Handler->HandlePragma(PP, Introducer, Tok);
124 }
125 
126 //===----------------------------------------------------------------------===//
127 // Preprocessor Pragma Directive Handling.
128 //===----------------------------------------------------------------------===//
129 
130 namespace {
131 // TokenCollector provides the option to collect tokens that were "read"
132 // and return them to the stream to be read later.
133 // Currently used when reading _Pragma/__pragma directives.
134 struct TokenCollector {
135  Preprocessor &Self;
136  bool Collect;
137  SmallVector<Token, 3> Tokens;
138  Token &Tok;
139 
140  void lex() {
141  if (Collect)
142  Tokens.push_back(Tok);
143  Self.Lex(Tok);
144  }
145 
146  void revert() {
147  assert(Collect && "did not collect tokens");
148  assert(!Tokens.empty() && "collected unexpected number of tokens");
149 
150  // Push the ( "string" ) tokens into the token stream.
151  auto Toks = std::make_unique<Token[]>(Tokens.size());
152  std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
153  Toks[Tokens.size() - 1] = Tok;
154  Self.EnterTokenStream(std::move(Toks), Tokens.size(),
155  /*DisableMacroExpansion*/ true,
156  /*IsReinject*/ true);
157 
158  // ... and return the pragma token unchanged.
159  Tok = *Tokens.begin();
160  }
161 };
162 } // namespace
163 
164 /// HandlePragmaDirective - The "\#pragma" directive has been parsed. Lex the
165 /// rest of the pragma, passing it to the registered pragma handlers.
166 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
167  if (Callbacks)
168  Callbacks->PragmaDirective(Introducer.Loc, Introducer.Kind);
169 
170  if (!PragmasEnabled)
171  return;
172 
173  ++NumPragma;
174 
175  // Invoke the first level of pragma handlers which reads the namespace id.
176  Token Tok;
177  PragmaHandlers->HandlePragma(*this, Introducer, Tok);
178 
179  // If the pragma handler didn't read the rest of the line, consume it now.
180  if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective())
181  || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective))
183 }
184 
185 /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
186 /// return the first token after the directive. The _Pragma token has just
187 /// been read into 'Tok'.
188 void Preprocessor::Handle_Pragma(Token &Tok) {
189  // C11 6.10.3.4/3:
190  // all pragma unary operator expressions within [a completely
191  // macro-replaced preprocessing token sequence] are [...] processed [after
192  // rescanning is complete]
193  //
194  // This means that we execute _Pragma operators in two cases:
195  //
196  // 1) on token sequences that would otherwise be produced as the output of
197  // phase 4 of preprocessing, and
198  // 2) on token sequences formed as the macro-replaced token sequence of a
199  // macro argument
200  //
201  // Case #2 appears to be a wording bug: only _Pragmas that would survive to
202  // the end of phase 4 should actually be executed. Discussion on the WG14
203  // mailing list suggests that a _Pragma operator is notionally checked early,
204  // but only pragmas that survive to the end of phase 4 should be executed.
205  //
206  // In Case #2, we check the syntax now, but then put the tokens back into the
207  // token stream for later consumption.
208 
209  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
210 
211  // Remember the pragma token location.
212  SourceLocation PragmaLoc = Tok.getLocation();
213 
214  // Read the '('.
215  Toks.lex();
216  if (Tok.isNot(tok::l_paren)) {
217  Diag(PragmaLoc, diag::err__Pragma_malformed);
218  return;
219  }
220 
221  // Read the '"..."'.
222  Toks.lex();
223  if (!tok::isStringLiteral(Tok.getKind())) {
224  Diag(PragmaLoc, diag::err__Pragma_malformed);
225  // Skip bad tokens, and the ')', if present.
226  if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
227  Lex(Tok);
228  while (Tok.isNot(tok::r_paren) &&
229  !Tok.isAtStartOfLine() &&
230  Tok.isNot(tok::eof))
231  Lex(Tok);
232  if (Tok.is(tok::r_paren))
233  Lex(Tok);
234  return;
235  }
236 
237  if (Tok.hasUDSuffix()) {
238  Diag(Tok, diag::err_invalid_string_udl);
239  // Skip this token, and the ')', if present.
240  Lex(Tok);
241  if (Tok.is(tok::r_paren))
242  Lex(Tok);
243  return;
244  }
245 
246  // Remember the string.
247  Token StrTok = Tok;
248 
249  // Read the ')'.
250  Toks.lex();
251  if (Tok.isNot(tok::r_paren)) {
252  Diag(PragmaLoc, diag::err__Pragma_malformed);
253  return;
254  }
255 
256  // If we're expanding a macro argument, put the tokens back.
257  if (InMacroArgPreExpansion) {
258  Toks.revert();
259  return;
260  }
261 
262  SourceLocation RParenLoc = Tok.getLocation();
263  bool Invalid = false;
264  std::string StrVal = getSpelling(StrTok, &Invalid);
265  if (Invalid) {
266  Diag(PragmaLoc, diag::err__Pragma_malformed);
267  return;
268  }
269 
270  // The _Pragma is lexically sound. Destringize according to C11 6.10.9.1:
271  // "The string literal is destringized by deleting any encoding prefix,
272  // deleting the leading and trailing double-quotes, replacing each escape
273  // sequence \" by a double-quote, and replacing each escape sequence \\ by a
274  // single backslash."
275  if (StrVal[0] == 'L' || StrVal[0] == 'U' ||
276  (StrVal[0] == 'u' && StrVal[1] != '8'))
277  StrVal.erase(StrVal.begin());
278  else if (StrVal[0] == 'u')
279  StrVal.erase(StrVal.begin(), StrVal.begin() + 2);
280 
281  if (StrVal[0] == 'R') {
282  // FIXME: C++11 does not specify how to handle raw-string-literals here.
283  // We strip off the 'R', the quotes, the d-char-sequences, and the parens.
284  assert(StrVal[1] == '"' && StrVal[StrVal.size() - 1] == '"' &&
285  "Invalid raw string token!");
286 
287  // Measure the length of the d-char-sequence.
288  unsigned NumDChars = 0;
289  while (StrVal[2 + NumDChars] != '(') {
290  assert(NumDChars < (StrVal.size() - 5) / 2 &&
291  "Invalid raw string token!");
292  ++NumDChars;
293  }
294  assert(StrVal[StrVal.size() - 2 - NumDChars] == ')');
295 
296  // Remove 'R " d-char-sequence' and 'd-char-sequence "'. We'll replace the
297  // parens below.
298  StrVal.erase(0, 2 + NumDChars);
299  StrVal.erase(StrVal.size() - 1 - NumDChars);
300  } else {
301  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
302  "Invalid string token!");
303 
304  // Remove escaped quotes and escapes.
305  unsigned ResultPos = 1;
306  for (size_t i = 1, e = StrVal.size() - 1; i != e; ++i) {
307  // Skip escapes. \\ -> '\' and \" -> '"'.
308  if (StrVal[i] == '\\' && i + 1 < e &&
309  (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
310  ++i;
311  StrVal[ResultPos++] = StrVal[i];
312  }
313  StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 1);
314  }
315 
316  // Remove the front quote, replacing it with a space, so that the pragma
317  // contents appear to have a space before them.
318  StrVal[0] = ' ';
319 
320  // Replace the terminating quote with a \n.
321  StrVal[StrVal.size()-1] = '\n';
322 
323  // Plop the string (including the newline and trailing null) into a buffer
324  // where we can lex it.
325  Token TmpTok;
326  TmpTok.startToken();
327  CreateString(StrVal, TmpTok);
328  SourceLocation TokLoc = TmpTok.getLocation();
329 
330  // Make and enter a lexer object so that we lex and expand the tokens just
331  // like any others.
332  Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
333  StrVal.size(), *this);
334 
335  EnterSourceFileWithLexer(TL, nullptr);
336 
337  // With everything set up, lex this as a #pragma directive.
338  HandlePragmaDirective({PIK__Pragma, PragmaLoc});
339 
340  // Finally, return whatever came after the pragma directive.
341  return Lex(Tok);
342 }
343 
344 /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
345 /// is not enclosed within a string literal.
346 void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
347  // During macro pre-expansion, check the syntax now but put the tokens back
348  // into the token stream for later consumption. Same as Handle_Pragma.
349  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
350 
351  // Remember the pragma token location.
352  SourceLocation PragmaLoc = Tok.getLocation();
353 
354  // Read the '('.
355  Toks.lex();
356  if (Tok.isNot(tok::l_paren)) {
357  Diag(PragmaLoc, diag::err__Pragma_malformed);
358  return;
359  }
360 
361  // Get the tokens enclosed within the __pragma(), as well as the final ')'.
362  SmallVector<Token, 32> PragmaToks;
363  int NumParens = 0;
364  Toks.lex();
365  while (Tok.isNot(tok::eof)) {
366  PragmaToks.push_back(Tok);
367  if (Tok.is(tok::l_paren))
368  NumParens++;
369  else if (Tok.is(tok::r_paren) && NumParens-- == 0)
370  break;
371  Toks.lex();
372  }
373 
374  if (Tok.is(tok::eof)) {
375  Diag(PragmaLoc, diag::err_unterminated___pragma);
376  return;
377  }
378 
379  // If we're expanding a macro argument, put the tokens back.
380  if (InMacroArgPreExpansion) {
381  Toks.revert();
382  return;
383  }
384 
385  PragmaToks.front().setFlag(Token::LeadingSpace);
386 
387  // Replace the ')' with an EOD to mark the end of the pragma.
388  PragmaToks.back().setKind(tok::eod);
389 
390  Token *TokArray = new Token[PragmaToks.size()];
391  std::copy(PragmaToks.begin(), PragmaToks.end(), TokArray);
392 
393  // Push the tokens onto the stack.
394  EnterTokenStream(TokArray, PragmaToks.size(), true, true,
395  /*IsReinject*/ false);
396 
397  // With everything set up, lex this as a #pragma directive.
398  HandlePragmaDirective({PIK___pragma, PragmaLoc});
399 
400  // Finally, return whatever came after the pragma directive.
401  return Lex(Tok);
402 }
403 
404 /// HandlePragmaOnce - Handle \#pragma once. OnceTok is the 'once'.
406  // Don't honor the 'once' when handling the primary source file, unless
407  // this is a prefix to a TU, which indicates we're generating a PCH file, or
408  // when the main file is a header (e.g. when -xc-header is provided on the
409  // commandline).
411  Diag(OnceTok, diag::pp_pragma_once_in_main_file);
412  return;
413  }
414 
415  // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
416  // Mark the file as a once-only file now.
417  HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
418 }
419 
421  assert(CurPPLexer && "No current lexer?");
422 
423  SmallString<64> Buffer;
424  CurLexer->ReadToEndOfLine(&Buffer);
425  if (Callbacks)
426  Callbacks->PragmaMark(MarkTok.getLocation(), Buffer);
427 }
428 
429 /// HandlePragmaPoison - Handle \#pragma GCC poison. PoisonTok is the 'poison'.
431  Token Tok;
432 
433  while (true) {
434  // Read the next token to poison. While doing this, pretend that we are
435  // skipping while reading the identifier to poison.
436  // This avoids errors on code like:
437  // #pragma GCC poison X
438  // #pragma GCC poison X
439  if (CurPPLexer) CurPPLexer->LexingRawMode = true;
440  LexUnexpandedToken(Tok);
441  if (CurPPLexer) CurPPLexer->LexingRawMode = false;
442 
443  // If we reached the end of line, we're done.
444  if (Tok.is(tok::eod)) return;
445 
446  // Can only poison identifiers.
447  if (Tok.isNot(tok::raw_identifier)) {
448  Diag(Tok, diag::err_pp_invalid_poison);
449  return;
450  }
451 
452  // Look up the identifier info for the token. We disabled identifier lookup
453  // by saying we're skipping contents, so we need to do this manually.
455 
456  // Already poisoned.
457  if (II->isPoisoned()) continue;
458 
459  // If this is a macro identifier, emit a warning.
460  if (isMacroDefined(II))
461  Diag(Tok, diag::pp_poisoning_existing_macro);
462 
463  // Finally, poison it!
464  II->setIsPoisoned();
465  if (II->isFromAST())
467  }
468 }
469 
470 /// HandlePragmaSystemHeader - Implement \#pragma GCC system_header. We know
471 /// that the whole directive has been parsed.
473  if (isInPrimaryFile()) {
474  Diag(SysHeaderTok, diag::pp_pragma_sysheader_in_main_file);
475  return;
476  }
477 
478  // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
480 
481  // Mark the file as a system header.
482  HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
483 
484  PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
485  if (PLoc.isInvalid())
486  return;
487 
488  unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename());
489 
490  // Notify the client, if desired, that we are in a new source file.
491  if (Callbacks)
492  Callbacks->FileChanged(SysHeaderTok.getLocation(),
494 
495  // Emit a line marker. This will change any source locations from this point
496  // forward to realize they are in a system header.
497  // Create a line note with this information.
498  SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine() + 1,
499  FilenameID, /*IsEntry=*/false, /*IsExit=*/false,
501 }
502 
503 /// HandlePragmaDependency - Handle \#pragma GCC dependency "foo" blah.
505  Token FilenameTok;
506  if (LexHeaderName(FilenameTok, /*AllowConcatenation*/false))
507  return;
508 
509  // If the next token wasn't a header-name, diagnose the error.
510  if (FilenameTok.isNot(tok::header_name)) {
511  Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
512  return;
513  }
514 
515  // Reserve a buffer to get the spelling.
516  SmallString<128> FilenameBuffer;
517  bool Invalid = false;
518  StringRef Filename = getSpelling(FilenameTok, FilenameBuffer, &Invalid);
519  if (Invalid)
520  return;
521 
522  bool isAngled =
524  // If GetIncludeFilenameSpelling set the start ptr to null, there was an
525  // error.
526  if (Filename.empty())
527  return;
528 
529  // Search include directories for this file.
531  LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
532  nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
533  if (!File) {
534  if (!SuppressIncludeNotFoundError)
535  Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
536  return;
537  }
538 
539  const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry();
540 
541  // If this file is older than the file it depends on, emit a diagnostic.
542  if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) {
543  // Lex tokens at the end of the message and include them in the message.
544  std::string Message;
545  Lex(DependencyTok);
546  while (DependencyTok.isNot(tok::eod)) {
547  Message += getSpelling(DependencyTok) + " ";
548  Lex(DependencyTok);
549  }
550 
551  // Remove the trailing ' ' if present.
552  if (!Message.empty())
553  Message.erase(Message.end()-1);
554  Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message;
555  }
556 }
557 
558 /// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
559 /// Return the IdentifierInfo* associated with the macro to push or pop.
561  // Remember the pragma token location.
562  Token PragmaTok = Tok;
563 
564  // Read the '('.
565  Lex(Tok);
566  if (Tok.isNot(tok::l_paren)) {
567  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
568  << getSpelling(PragmaTok);
569  return nullptr;
570  }
571 
572  // Read the macro name string.
573  Lex(Tok);
574  if (Tok.isNot(tok::string_literal)) {
575  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
576  << getSpelling(PragmaTok);
577  return nullptr;
578  }
579 
580  if (Tok.hasUDSuffix()) {
581  Diag(Tok, diag::err_invalid_string_udl);
582  return nullptr;
583  }
584 
585  // Remember the macro string.
586  std::string StrVal = getSpelling(Tok);
587 
588  // Read the ')'.
589  Lex(Tok);
590  if (Tok.isNot(tok::r_paren)) {
591  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
592  << getSpelling(PragmaTok);
593  return nullptr;
594  }
595 
596  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
597  "Invalid string token!");
598 
599  // Create a Token from the string.
600  Token MacroTok;
601  MacroTok.startToken();
602  MacroTok.setKind(tok::raw_identifier);
603  CreateString(StringRef(&StrVal[1], StrVal.size() - 2), MacroTok);
604 
605  // Get the IdentifierInfo of MacroToPushTok.
606  return LookUpIdentifierInfo(MacroTok);
607 }
608 
609 /// Handle \#pragma push_macro.
610 ///
611 /// The syntax is:
612 /// \code
613 /// #pragma push_macro("macro")
614 /// \endcode
616  // Parse the pragma directive and get the macro IdentifierInfo*.
617  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PushMacroTok);
618  if (!IdentInfo) return;
619 
620  // Get the MacroInfo associated with IdentInfo.
621  MacroInfo *MI = getMacroInfo(IdentInfo);
622 
623  if (MI) {
624  // Allow the original MacroInfo to be redefined later.
626  }
627 
628  // Push the cloned MacroInfo so we can retrieve it later.
629  PragmaPushMacroInfo[IdentInfo].push_back(MI);
630 }
631 
632 /// Handle \#pragma pop_macro.
633 ///
634 /// The syntax is:
635 /// \code
636 /// #pragma pop_macro("macro")
637 /// \endcode
639  SourceLocation MessageLoc = PopMacroTok.getLocation();
640 
641  // Parse the pragma directive and get the macro IdentifierInfo*.
642  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PopMacroTok);
643  if (!IdentInfo) return;
644 
645  // Find the vector<MacroInfo*> associated with the macro.
646  llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>::iterator iter =
647  PragmaPushMacroInfo.find(IdentInfo);
648  if (iter != PragmaPushMacroInfo.end()) {
649  // Forget the MacroInfo currently associated with IdentInfo.
650  if (MacroInfo *MI = getMacroInfo(IdentInfo)) {
651  if (MI->isWarnIfUnused())
652  WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
653  appendMacroDirective(IdentInfo, AllocateUndefMacroDirective(MessageLoc));
654  }
655 
656  // Get the MacroInfo we want to reinstall.
657  MacroInfo *MacroToReInstall = iter->second.back();
658 
659  if (MacroToReInstall)
660  // Reinstall the previously pushed macro.
661  appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc);
662 
663  // Pop PragmaPushMacroInfo stack.
664  iter->second.pop_back();
665  if (iter->second.empty())
666  PragmaPushMacroInfo.erase(iter);
667  } else {
668  Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push)
669  << IdentInfo->getName();
670  }
671 }
672 
674  // We will either get a quoted filename or a bracketed filename, and we
675  // have to track which we got. The first filename is the source name,
676  // and the second name is the mapped filename. If the first is quoted,
677  // the second must be as well (cannot mix and match quotes and brackets).
678 
679  // Get the open paren
680  Lex(Tok);
681  if (Tok.isNot(tok::l_paren)) {
682  Diag(Tok, diag::warn_pragma_include_alias_expected) << "(";
683  return;
684  }
685 
686  // We expect either a quoted string literal, or a bracketed name
687  Token SourceFilenameTok;
688  if (LexHeaderName(SourceFilenameTok))
689  return;
690 
691  StringRef SourceFileName;
692  SmallString<128> FileNameBuffer;
693  if (SourceFilenameTok.is(tok::header_name)) {
694  SourceFileName = getSpelling(SourceFilenameTok, FileNameBuffer);
695  } else {
696  Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
697  return;
698  }
699  FileNameBuffer.clear();
700 
701  // Now we expect a comma, followed by another include name
702  Lex(Tok);
703  if (Tok.isNot(tok::comma)) {
704  Diag(Tok, diag::warn_pragma_include_alias_expected) << ",";
705  return;
706  }
707 
708  Token ReplaceFilenameTok;
709  if (LexHeaderName(ReplaceFilenameTok))
710  return;
711 
712  StringRef ReplaceFileName;
713  if (ReplaceFilenameTok.is(tok::header_name)) {
714  ReplaceFileName = getSpelling(ReplaceFilenameTok, FileNameBuffer);
715  } else {
716  Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
717  return;
718  }
719 
720  // Finally, we expect the closing paren
721  Lex(Tok);
722  if (Tok.isNot(tok::r_paren)) {
723  Diag(Tok, diag::warn_pragma_include_alias_expected) << ")";
724  return;
725  }
726 
727  // Now that we have the source and target filenames, we need to make sure
728  // they're both of the same type (angled vs non-angled)
729  StringRef OriginalSource = SourceFileName;
730 
731  bool SourceIsAngled =
732  GetIncludeFilenameSpelling(SourceFilenameTok.getLocation(),
733  SourceFileName);
734  bool ReplaceIsAngled =
735  GetIncludeFilenameSpelling(ReplaceFilenameTok.getLocation(),
736  ReplaceFileName);
737  if (!SourceFileName.empty() && !ReplaceFileName.empty() &&
738  (SourceIsAngled != ReplaceIsAngled)) {
739  unsigned int DiagID;
740  if (SourceIsAngled)
741  DiagID = diag::warn_pragma_include_alias_mismatch_angle;
742  else
743  DiagID = diag::warn_pragma_include_alias_mismatch_quote;
744 
745  Diag(SourceFilenameTok.getLocation(), DiagID)
746  << SourceFileName
747  << ReplaceFileName;
748 
749  return;
750  }
751 
752  // Now we can let the include handler know about this mapping
753  getHeaderSearchInfo().AddIncludeAlias(OriginalSource, ReplaceFileName);
754 }
755 
756 // Lex a component of a module name: either an identifier or a string literal;
757 // for components that can be expressed both ways, the two forms are equivalent.
759  Preprocessor &PP, Token &Tok,
760  std::pair<IdentifierInfo *, SourceLocation> &ModuleNameComponent,
761  bool First) {
762  PP.LexUnexpandedToken(Tok);
763  if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) {
764  StringLiteralParser Literal(Tok, PP);
765  if (Literal.hadError)
766  return true;
767  ModuleNameComponent = std::make_pair(
768  PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation());
769  } else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) {
770  ModuleNameComponent =
771  std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation());
772  } else {
773  PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First;
774  return true;
775  }
776  return false;
777 }
778 
779 static bool LexModuleName(
780  Preprocessor &PP, Token &Tok,
781  llvm::SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>>
782  &ModuleName) {
783  while (true) {
784  std::pair<IdentifierInfo*, SourceLocation> NameComponent;
785  if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty()))
786  return true;
787  ModuleName.push_back(NameComponent);
788 
789  PP.LexUnexpandedToken(Tok);
790  if (Tok.isNot(tok::period))
791  return false;
792  }
793 }
794 
796  SourceLocation Loc = Tok.getLocation();
797 
798  std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc;
799  if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true))
800  return;
801  IdentifierInfo *ModuleName = ModuleNameLoc.first;
802 
803  LexUnexpandedToken(Tok);
804  if (Tok.isNot(tok::eod)) {
805  Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
807  }
808 
809  CurLexer->LexingRawMode = true;
810 
811  auto TryConsumeIdentifier = [&](StringRef Ident) -> bool {
812  if (Tok.getKind() != tok::raw_identifier ||
813  Tok.getRawIdentifier() != Ident)
814  return false;
815  CurLexer->Lex(Tok);
816  return true;
817  };
818 
819  // Scan forward looking for the end of the module.
820  const char *Start = CurLexer->getBufferLocation();
821  const char *End = nullptr;
822  unsigned NestingLevel = 1;
823  while (true) {
824  End = CurLexer->getBufferLocation();
825  CurLexer->Lex(Tok);
826 
827  if (Tok.is(tok::eof)) {
828  Diag(Loc, diag::err_pp_module_build_missing_end);
829  break;
830  }
831 
832  if (Tok.isNot(tok::hash) || !Tok.isAtStartOfLine()) {
833  // Token was part of module; keep going.
834  continue;
835  }
836 
837  // We hit something directive-shaped; check to see if this is the end
838  // of the module build.
839  CurLexer->ParsingPreprocessorDirective = true;
840  CurLexer->Lex(Tok);
841  if (TryConsumeIdentifier("pragma") && TryConsumeIdentifier("clang") &&
842  TryConsumeIdentifier("module")) {
843  if (TryConsumeIdentifier("build"))
844  // #pragma clang module build -> entering a nested module build.
845  ++NestingLevel;
846  else if (TryConsumeIdentifier("endbuild")) {
847  // #pragma clang module endbuild -> leaving a module build.
848  if (--NestingLevel == 0)
849  break;
850  }
851  // We should either be looking at the EOD or more of the current directive
852  // preceding the EOD. Either way we can ignore this token and keep going.
853  assert(Tok.getKind() != tok::eof && "missing EOD before EOF");
854  }
855  }
856 
857  CurLexer->LexingRawMode = false;
858 
859  // Load the extracted text as a preprocessed module.
860  assert(CurLexer->getBuffer().begin() <= Start &&
861  Start <= CurLexer->getBuffer().end() &&
862  CurLexer->getBuffer().begin() <= End &&
863  End <= CurLexer->getBuffer().end() &&
864  "module source range not contained within same file buffer");
865  TheModuleLoader.createModuleFromSource(Loc, ModuleName->getName(),
866  StringRef(Start, End - Start));
867 }
868 
870  Lex(Tok);
871  if (Tok.is(tok::l_paren)) {
872  Diag(Tok.getLocation(), diag::warn_pp_hdrstop_filename_ignored);
873 
874  std::string FileName;
875  if (!LexStringLiteral(Tok, FileName, "pragma hdrstop", false))
876  return;
877 
878  if (Tok.isNot(tok::r_paren)) {
879  Diag(Tok, diag::err_expected) << tok::r_paren;
880  return;
881  }
882  Lex(Tok);
883  }
884  if (Tok.isNot(tok::eod))
885  Diag(Tok.getLocation(), diag::ext_pp_extra_tokens_at_eol)
886  << "pragma hdrstop";
887 
889  SourceMgr.isInMainFile(Tok.getLocation())) {
890  assert(CurLexer && "no lexer for #pragma hdrstop processing");
891  Token &Result = Tok;
892  Result.startToken();
893  CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
894  CurLexer->cutOffLexing();
895  }
897  SkippingUntilPragmaHdrStop = false;
898 }
899 
900 /// AddPragmaHandler - Add the specified pragma handler to the preprocessor.
901 /// If 'Namespace' is non-null, then it is a token required to exist on the
902 /// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
903 void Preprocessor::AddPragmaHandler(StringRef Namespace,
904  PragmaHandler *Handler) {
905  PragmaNamespace *InsertNS = PragmaHandlers.get();
906 
907  // If this is specified to be in a namespace, step down into it.
908  if (!Namespace.empty()) {
909  // If there is already a pragma handler with the name of this namespace,
910  // we either have an error (directive with the same name as a namespace) or
911  // we already have the namespace to insert into.
912  if (PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace)) {
913  InsertNS = Existing->getIfNamespace();
914  assert(InsertNS != nullptr && "Cannot have a pragma namespace and pragma"
915  " handler with the same name!");
916  } else {
917  // Otherwise, this namespace doesn't exist yet, create and insert the
918  // handler for it.
919  InsertNS = new PragmaNamespace(Namespace);
920  PragmaHandlers->AddPragma(InsertNS);
921  }
922  }
923 
924  // Check to make sure we don't already have a pragma for this identifier.
925  assert(!InsertNS->FindHandler(Handler->getName()) &&
926  "Pragma handler already exists for this identifier!");
927  InsertNS->AddPragma(Handler);
928 }
929 
930 /// RemovePragmaHandler - Remove the specific pragma handler from the
931 /// preprocessor. If \arg Namespace is non-null, then it should be the
932 /// namespace that \arg Handler was added to. It is an error to remove
933 /// a handler that has not been registered.
934 void Preprocessor::RemovePragmaHandler(StringRef Namespace,
935  PragmaHandler *Handler) {
936  PragmaNamespace *NS = PragmaHandlers.get();
937 
938  // If this is specified to be in a namespace, step down into it.
939  if (!Namespace.empty()) {
940  PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace);
941  assert(Existing && "Namespace containing handler does not exist!");
942 
943  NS = Existing->getIfNamespace();
944  assert(NS && "Invalid namespace, registered as a regular pragma handler!");
945  }
946 
947  NS->RemovePragmaHandler(Handler);
948 
949  // If this is a non-default namespace and it is now empty, remove it.
950  if (NS != PragmaHandlers.get() && NS->IsEmpty()) {
951  PragmaHandlers->RemovePragmaHandler(NS);
952  delete NS;
953  }
954 }
955 
957  Token Tok;
958  LexUnexpandedToken(Tok);
959 
960  if (Tok.isNot(tok::identifier)) {
961  Diag(Tok, diag::ext_on_off_switch_syntax);
962  return true;
963  }
964  IdentifierInfo *II = Tok.getIdentifierInfo();
965  if (II->isStr("ON"))
966  Result = tok::OOS_ON;
967  else if (II->isStr("OFF"))
968  Result = tok::OOS_OFF;
969  else if (II->isStr("DEFAULT"))
970  Result = tok::OOS_DEFAULT;
971  else {
972  Diag(Tok, diag::ext_on_off_switch_syntax);
973  return true;
974  }
975 
976  // Verify that this is followed by EOD.
977  LexUnexpandedToken(Tok);
978  if (Tok.isNot(tok::eod))
979  Diag(Tok, diag::ext_pragma_syntax_eod);
980  return false;
981 }
982 
983 namespace {
984 
985 /// PragmaOnceHandler - "\#pragma once" marks the file as atomically included.
986 struct PragmaOnceHandler : public PragmaHandler {
987  PragmaOnceHandler() : PragmaHandler("once") {}
988 
989  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
990  Token &OnceTok) override {
991  PP.CheckEndOfDirective("pragma once");
992  PP.HandlePragmaOnce(OnceTok);
993  }
994 };
995 
996 /// PragmaMarkHandler - "\#pragma mark ..." is ignored by the compiler, and the
997 /// rest of the line is not lexed.
998 struct PragmaMarkHandler : public PragmaHandler {
999  PragmaMarkHandler() : PragmaHandler("mark") {}
1000 
1001  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1002  Token &MarkTok) override {
1003  PP.HandlePragmaMark(MarkTok);
1004  }
1005 };
1006 
1007 /// PragmaPoisonHandler - "\#pragma poison x" marks x as not usable.
1008 struct PragmaPoisonHandler : public PragmaHandler {
1009  PragmaPoisonHandler() : PragmaHandler("poison") {}
1010 
1011  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1012  Token &PoisonTok) override {
1013  PP.HandlePragmaPoison();
1014  }
1015 };
1016 
1017 /// PragmaSystemHeaderHandler - "\#pragma system_header" marks the current file
1018 /// as a system header, which silences warnings in it.
1019 struct PragmaSystemHeaderHandler : public PragmaHandler {
1020  PragmaSystemHeaderHandler() : PragmaHandler("system_header") {}
1021 
1022  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1023  Token &SHToken) override {
1024  PP.HandlePragmaSystemHeader(SHToken);
1025  PP.CheckEndOfDirective("pragma");
1026  }
1027 };
1028 
1029 struct PragmaDependencyHandler : public PragmaHandler {
1030  PragmaDependencyHandler() : PragmaHandler("dependency") {}
1031 
1032  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1033  Token &DepToken) override {
1034  PP.HandlePragmaDependency(DepToken);
1035  }
1036 };
1037 
1038 struct PragmaDebugHandler : public PragmaHandler {
1039  PragmaDebugHandler() : PragmaHandler("__debug") {}
1040 
1041  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1042  Token &DebugToken) override {
1043  Token Tok;
1044  PP.LexUnexpandedToken(Tok);
1045  if (Tok.isNot(tok::identifier)) {
1046  PP.Diag(Tok, diag::warn_pragma_debug_missing_command);
1047  return;
1048  }
1049  IdentifierInfo *II = Tok.getIdentifierInfo();
1050 
1051  if (II->isStr("assert")) {
1053  llvm_unreachable("This is an assertion!");
1054  } else if (II->isStr("crash")) {
1055  llvm::Timer T("crash", "pragma crash");
1056  llvm::TimeRegion R(&T);
1058  LLVM_BUILTIN_TRAP;
1059  } else if (II->isStr("parser_crash")) {
1061  Token Crasher;
1062  Crasher.startToken();
1063  Crasher.setKind(tok::annot_pragma_parser_crash);
1064  Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
1065  PP.EnterToken(Crasher, /*IsReinject*/ false);
1066  }
1067  } else if (II->isStr("dump")) {
1068  Token Identifier;
1070  if (auto *DumpII = Identifier.getIdentifierInfo()) {
1071  Token DumpAnnot;
1072  DumpAnnot.startToken();
1073  DumpAnnot.setKind(tok::annot_pragma_dump);
1074  DumpAnnot.setAnnotationRange(
1075  SourceRange(Tok.getLocation(), Identifier.getLocation()));
1076  DumpAnnot.setAnnotationValue(DumpII);
1078  PP.EnterToken(DumpAnnot, /*IsReinject*/false);
1079  } else {
1080  PP.Diag(Identifier, diag::warn_pragma_debug_missing_argument)
1081  << II->getName();
1082  }
1083  } else if (II->isStr("diag_mapping")) {
1084  Token DiagName;
1085  PP.LexUnexpandedToken(DiagName);
1086  if (DiagName.is(tok::eod))
1087  PP.getDiagnostics().dump();
1088  else if (DiagName.is(tok::string_literal) && !DiagName.hasUDSuffix()) {
1089  StringLiteralParser Literal(DiagName, PP);
1090  if (Literal.hadError)
1091  return;
1092  PP.getDiagnostics().dump(Literal.GetString());
1093  } else {
1094  PP.Diag(DiagName, diag::warn_pragma_debug_missing_argument)
1095  << II->getName();
1096  }
1097  } else if (II->isStr("llvm_fatal_error")) {
1099  llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
1100  } else if (II->isStr("llvm_unreachable")) {
1102  llvm_unreachable("#pragma clang __debug llvm_unreachable");
1103  } else if (II->isStr("macro")) {
1104  Token MacroName;
1105  PP.LexUnexpandedToken(MacroName);
1106  auto *MacroII = MacroName.getIdentifierInfo();
1107  if (MacroII)
1108  PP.dumpMacroInfo(MacroII);
1109  else
1110  PP.Diag(MacroName, diag::warn_pragma_debug_missing_argument)
1111  << II->getName();
1112  } else if (II->isStr("module_map")) {
1114  ModuleName;
1115  if (LexModuleName(PP, Tok, ModuleName))
1116  return;
1118  Module *M = nullptr;
1119  for (auto IIAndLoc : ModuleName) {
1120  M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M);
1121  if (!M) {
1122  PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module)
1123  << IIAndLoc.first;
1124  return;
1125  }
1126  }
1127  M->dump();
1128  } else if (II->isStr("overflow_stack")) {
1130  DebugOverflowStack();
1131  } else if (II->isStr("captured")) {
1132  HandleCaptured(PP);
1133  } else if (II->isStr("modules")) {
1134  struct ModuleVisitor {
1135  Preprocessor &PP;
1136  void visit(Module *M, bool VisibleOnly) {
1137  SourceLocation ImportLoc = PP.getModuleImportLoc(M);
1138  if (!VisibleOnly || ImportLoc.isValid()) {
1139  llvm::errs() << M->getFullModuleName() << " ";
1140  if (ImportLoc.isValid()) {
1141  llvm::errs() << M << " visible ";
1142  ImportLoc.print(llvm::errs(), PP.getSourceManager());
1143  }
1144  llvm::errs() << "\n";
1145  }
1146  for (Module *Sub : M->submodules()) {
1147  if (!VisibleOnly || ImportLoc.isInvalid() || Sub->IsExplicit)
1148  visit(Sub, VisibleOnly);
1149  }
1150  }
1151  void visitAll(bool VisibleOnly) {
1152  for (auto &NameAndMod :
1154  visit(NameAndMod.second, VisibleOnly);
1155  }
1156  } Visitor{PP};
1157 
1158  Token Kind;
1160  auto *DumpII = Kind.getIdentifierInfo();
1161  if (!DumpII) {
1162  PP.Diag(Kind, diag::warn_pragma_debug_missing_argument)
1163  << II->getName();
1164  } else if (DumpII->isStr("all")) {
1165  Visitor.visitAll(false);
1166  } else if (DumpII->isStr("visible")) {
1167  Visitor.visitAll(true);
1168  } else if (DumpII->isStr("building")) {
1169  for (auto &Building : PP.getBuildingSubmodules()) {
1170  llvm::errs() << "in " << Building.M->getFullModuleName();
1171  if (Building.ImportLoc.isValid()) {
1172  llvm::errs() << " imported ";
1173  if (Building.IsPragma)
1174  llvm::errs() << "via pragma ";
1175  llvm::errs() << "at ";
1176  Building.ImportLoc.print(llvm::errs(), PP.getSourceManager());
1177  llvm::errs() << "\n";
1178  }
1179  }
1180  } else {
1181  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
1182  << DumpII->getName();
1183  }
1184  } else if (II->isStr("sloc_usage")) {
1185  // An optional integer literal argument specifies the number of files to
1186  // specifically report information about.
1187  Optional<unsigned> MaxNotes;
1188  Token ArgToken;
1189  PP.Lex(ArgToken);
1190  uint64_t Value;
1191  if (ArgToken.is(tok::numeric_constant) &&
1192  PP.parseSimpleIntegerLiteral(ArgToken, Value)) {
1193  MaxNotes = Value;
1194  } else if (ArgToken.isNot(tok::eod)) {
1195  PP.Diag(ArgToken, diag::warn_pragma_debug_unexpected_argument);
1196  }
1197 
1198  PP.Diag(Tok, diag::remark_sloc_usage);
1200  MaxNotes);
1201  } else {
1202  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
1203  << II->getName();
1204  }
1205 
1206  PPCallbacks *Callbacks = PP.getPPCallbacks();
1207  if (Callbacks)
1208  Callbacks->PragmaDebug(Tok.getLocation(), II->getName());
1209  }
1210 
1211  void HandleCaptured(Preprocessor &PP) {
1212  Token Tok;
1213  PP.LexUnexpandedToken(Tok);
1214 
1215  if (Tok.isNot(tok::eod)) {
1216  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol)
1217  << "pragma clang __debug captured";
1218  return;
1219  }
1220 
1221  SourceLocation NameLoc = Tok.getLocation();
1223  PP.getPreprocessorAllocator().Allocate<Token>(1), 1);
1224  Toks[0].startToken();
1225  Toks[0].setKind(tok::annot_pragma_captured);
1226  Toks[0].setLocation(NameLoc);
1227 
1228  PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true,
1229  /*IsReinject=*/false);
1230  }
1231 
1232 // Disable MSVC warning about runtime stack overflow.
1233 #ifdef _MSC_VER
1234  #pragma warning(disable : 4717)
1235 #endif
1236  static void DebugOverflowStack(void (*P)() = nullptr) {
1237  void (*volatile Self)(void(*P)()) = DebugOverflowStack;
1238  Self(reinterpret_cast<void(*)()>(Self));
1239  }
1240 #ifdef _MSC_VER
1241  #pragma warning(default : 4717)
1242 #endif
1243 };
1244 
1245 /// PragmaDiagnosticHandler - e.g. '\#pragma GCC diagnostic ignored "-Wformat"'
1246 struct PragmaDiagnosticHandler : public PragmaHandler {
1247 private:
1248  const char *Namespace;
1249 
1250 public:
1251  explicit PragmaDiagnosticHandler(const char *NS)
1252  : PragmaHandler("diagnostic"), Namespace(NS) {}
1253 
1254  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1255  Token &DiagToken) override {
1256  SourceLocation DiagLoc = DiagToken.getLocation();
1257  Token Tok;
1258  PP.LexUnexpandedToken(Tok);
1259  if (Tok.isNot(tok::identifier)) {
1260  PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1261  return;
1262  }
1263  IdentifierInfo *II = Tok.getIdentifierInfo();
1264  PPCallbacks *Callbacks = PP.getPPCallbacks();
1265 
1266  if (II->isStr("pop")) {
1267  if (!PP.getDiagnostics().popMappings(DiagLoc))
1268  PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop);
1269  else if (Callbacks)
1270  Callbacks->PragmaDiagnosticPop(DiagLoc, Namespace);
1271  return;
1272  } else if (II->isStr("push")) {
1273  PP.getDiagnostics().pushMappings(DiagLoc);
1274  if (Callbacks)
1275  Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace);
1276  return;
1277  }
1278 
1279  diag::Severity SV = llvm::StringSwitch<diag::Severity>(II->getName())
1280  .Case("ignored", diag::Severity::Ignored)
1281  .Case("warning", diag::Severity::Warning)
1282  .Case("error", diag::Severity::Error)
1283  .Case("fatal", diag::Severity::Fatal)
1284  .Default(diag::Severity());
1285 
1286  if (SV == diag::Severity()) {
1287  PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1288  return;
1289  }
1290 
1291  PP.LexUnexpandedToken(Tok);
1292  SourceLocation StringLoc = Tok.getLocation();
1293 
1294  std::string WarningName;
1295  if (!PP.FinishLexStringLiteral(Tok, WarningName, "pragma diagnostic",
1296  /*AllowMacroExpansion=*/false))
1297  return;
1298 
1299  if (Tok.isNot(tok::eod)) {
1300  PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
1301  return;
1302  }
1303 
1304  if (WarningName.size() < 3 || WarningName[0] != '-' ||
1305  (WarningName[1] != 'W' && WarningName[1] != 'R')) {
1306  PP.Diag(StringLoc, diag::warn_pragma_diagnostic_invalid_option);
1307  return;
1308  }
1309 
1310  diag::Flavor Flavor = WarningName[1] == 'W' ? diag::Flavor::WarningOrError
1312  StringRef Group = StringRef(WarningName).substr(2);
1313  bool unknownDiag = false;
1314  if (Group == "everything") {
1315  // Special handling for pragma clang diagnostic ... "-Weverything".
1316  // There is no formal group named "everything", so there has to be a
1317  // special case for it.
1318  PP.getDiagnostics().setSeverityForAll(Flavor, SV, DiagLoc);
1319  } else
1320  unknownDiag = PP.getDiagnostics().setSeverityForGroup(Flavor, Group, SV,
1321  DiagLoc);
1322  if (unknownDiag)
1323  PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning)
1324  << WarningName;
1325  else if (Callbacks)
1326  Callbacks->PragmaDiagnostic(DiagLoc, Namespace, SV, WarningName);
1327  }
1328 };
1329 
1330 /// "\#pragma hdrstop [<header-name-string>]"
1331 struct PragmaHdrstopHandler : public PragmaHandler {
1332  PragmaHdrstopHandler() : PragmaHandler("hdrstop") {}
1333  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1334  Token &DepToken) override {
1335  PP.HandlePragmaHdrstop(DepToken);
1336  }
1337 };
1338 
1339 /// "\#pragma warning(...)". MSVC's diagnostics do not map cleanly to clang's
1340 /// diagnostics, so we don't really implement this pragma. We parse it and
1341 /// ignore it to avoid -Wunknown-pragma warnings.
1342 struct PragmaWarningHandler : public PragmaHandler {
1343  PragmaWarningHandler() : PragmaHandler("warning") {}
1344 
1345  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1346  Token &Tok) override {
1347  // Parse things like:
1348  // warning(push, 1)
1349  // warning(pop)
1350  // warning(disable : 1 2 3 ; error : 4 5 6 ; suppress : 7 8 9)
1351  SourceLocation DiagLoc = Tok.getLocation();
1352  PPCallbacks *Callbacks = PP.getPPCallbacks();
1353 
1354  PP.Lex(Tok);
1355  if (Tok.isNot(tok::l_paren)) {
1356  PP.Diag(Tok, diag::warn_pragma_warning_expected) << "(";
1357  return;
1358  }
1359 
1360  PP.Lex(Tok);
1361  IdentifierInfo *II = Tok.getIdentifierInfo();
1362 
1363  if (II && II->isStr("push")) {
1364  // #pragma warning( push[ ,n ] )
1365  int Level = -1;
1366  PP.Lex(Tok);
1367  if (Tok.is(tok::comma)) {
1368  PP.Lex(Tok);
1369  uint64_t Value;
1370  if (Tok.is(tok::numeric_constant) &&
1372  Level = int(Value);
1373  if (Level < 0 || Level > 4) {
1374  PP.Diag(Tok, diag::warn_pragma_warning_push_level);
1375  return;
1376  }
1377  }
1378  PP.getDiagnostics().pushMappings(DiagLoc);
1379  if (Callbacks)
1380  Callbacks->PragmaWarningPush(DiagLoc, Level);
1381  } else if (II && II->isStr("pop")) {
1382  // #pragma warning( pop )
1383  PP.Lex(Tok);
1384  if (!PP.getDiagnostics().popMappings(DiagLoc))
1385  PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop);
1386  else if (Callbacks)
1387  Callbacks->PragmaWarningPop(DiagLoc);
1388  } else {
1389  // #pragma warning( warning-specifier : warning-number-list
1390  // [; warning-specifier : warning-number-list...] )
1391  while (true) {
1392  II = Tok.getIdentifierInfo();
1393  if (!II && !Tok.is(tok::numeric_constant)) {
1394  PP.Diag(Tok, diag::warn_pragma_warning_spec_invalid);
1395  return;
1396  }
1397 
1398  // Figure out which warning specifier this is.
1399  bool SpecifierValid;
1401  if (II) {
1402  int SpecifierInt = llvm::StringSwitch<int>(II->getName())
1403  .Case("default", PPCallbacks::PWS_Default)
1404  .Case("disable", PPCallbacks::PWS_Disable)
1405  .Case("error", PPCallbacks::PWS_Error)
1406  .Case("once", PPCallbacks::PWS_Once)
1407  .Case("suppress", PPCallbacks::PWS_Suppress)
1408  .Default(-1);
1409  if ((SpecifierValid = SpecifierInt != -1))
1410  Specifier =
1411  static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);
1412 
1413  // If we read a correct specifier, snatch next token (that should be
1414  // ":", checked later).
1415  if (SpecifierValid)
1416  PP.Lex(Tok);
1417  } else {
1418  // Token is a numeric constant. It should be either 1, 2, 3 or 4.
1419  uint64_t Value;
1420  if (PP.parseSimpleIntegerLiteral(Tok, Value)) {
1421  if ((SpecifierValid = (Value >= 1) && (Value <= 4)))
1424  } else
1425  SpecifierValid = false;
1426  // Next token already snatched by parseSimpleIntegerLiteral.
1427  }
1428 
1429  if (!SpecifierValid) {
1430  PP.Diag(Tok, diag::warn_pragma_warning_spec_invalid);
1431  return;
1432  }
1433  if (Tok.isNot(tok::colon)) {
1434  PP.Diag(Tok, diag::warn_pragma_warning_expected) << ":";
1435  return;
1436  }
1437 
1438  // Collect the warning ids.
1439  SmallVector<int, 4> Ids;
1440  PP.Lex(Tok);
1441  while (Tok.is(tok::numeric_constant)) {
1442  uint64_t Value;
1443  if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
1444  Value > INT_MAX) {
1445  PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
1446  return;
1447  }
1448  Ids.push_back(int(Value));
1449  }
1450 
1451  // Only act on disable for now.
1455  if (SV != diag::Severity())
1456  for (int Id : Ids) {
1457  if (auto Group = diagGroupFromCLWarningID(Id)) {
1458  bool unknownDiag = PP.getDiagnostics().setSeverityForGroup(
1459  diag::Flavor::WarningOrError, *Group, SV, DiagLoc);
1460  assert(!unknownDiag &&
1461  "wd table should only contain known diags");
1462  (void)unknownDiag;
1463  }
1464  }
1465 
1466  if (Callbacks)
1467  Callbacks->PragmaWarning(DiagLoc, Specifier, Ids);
1468 
1469  // Parse the next specifier if there is a semicolon.
1470  if (Tok.isNot(tok::semi))
1471  break;
1472  PP.Lex(Tok);
1473  }
1474  }
1475 
1476  if (Tok.isNot(tok::r_paren)) {
1477  PP.Diag(Tok, diag::warn_pragma_warning_expected) << ")";
1478  return;
1479  }
1480 
1481  PP.Lex(Tok);
1482  if (Tok.isNot(tok::eod))
1483  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma warning";
1484  }
1485 };
1486 
1487 /// "\#pragma execution_character_set(...)". MSVC supports this pragma only
1488 /// for "UTF-8". We parse it and ignore it if UTF-8 is provided and warn
1489 /// otherwise to avoid -Wunknown-pragma warnings.
1490 struct PragmaExecCharsetHandler : public PragmaHandler {
1491  PragmaExecCharsetHandler() : PragmaHandler("execution_character_set") {}
1492 
1493  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1494  Token &Tok) override {
1495  // Parse things like:
1496  // execution_character_set(push, "UTF-8")
1497  // execution_character_set(pop)
1498  SourceLocation DiagLoc = Tok.getLocation();
1499  PPCallbacks *Callbacks = PP.getPPCallbacks();
1500 
1501  PP.Lex(Tok);
1502  if (Tok.isNot(tok::l_paren)) {
1503  PP.Diag(Tok, diag::warn_pragma_exec_charset_expected) << "(";
1504  return;
1505  }
1506 
1507  PP.Lex(Tok);
1508  IdentifierInfo *II = Tok.getIdentifierInfo();
1509 
1510  if (II && II->isStr("push")) {
1511  // #pragma execution_character_set( push[ , string ] )
1512  PP.Lex(Tok);
1513  if (Tok.is(tok::comma)) {
1514  PP.Lex(Tok);
1515 
1516  std::string ExecCharset;
1517  if (!PP.FinishLexStringLiteral(Tok, ExecCharset,
1518  "pragma execution_character_set",
1519  /*AllowMacroExpansion=*/false))
1520  return;
1521 
1522  // MSVC supports either of these, but nothing else.
1523  if (ExecCharset != "UTF-8" && ExecCharset != "utf-8") {
1524  PP.Diag(Tok, diag::warn_pragma_exec_charset_push_invalid) << ExecCharset;
1525  return;
1526  }
1527  }
1528  if (Callbacks)
1529  Callbacks->PragmaExecCharsetPush(DiagLoc, "UTF-8");
1530  } else if (II && II->isStr("pop")) {
1531  // #pragma execution_character_set( pop )
1532  PP.Lex(Tok);
1533  if (Callbacks)
1534  Callbacks->PragmaExecCharsetPop(DiagLoc);
1535  } else {
1536  PP.Diag(Tok, diag::warn_pragma_exec_charset_spec_invalid);
1537  return;
1538  }
1539 
1540  if (Tok.isNot(tok::r_paren)) {
1541  PP.Diag(Tok, diag::warn_pragma_exec_charset_expected) << ")";
1542  return;
1543  }
1544 
1545  PP.Lex(Tok);
1546  if (Tok.isNot(tok::eod))
1547  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma execution_character_set";
1548  }
1549 };
1550 
1551 /// PragmaIncludeAliasHandler - "\#pragma include_alias("...")".
1552 struct PragmaIncludeAliasHandler : public PragmaHandler {
1553  PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}
1554 
1555  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1556  Token &IncludeAliasTok) override {
1557  PP.HandlePragmaIncludeAlias(IncludeAliasTok);
1558  }
1559 };
1560 
1561 /// PragmaMessageHandler - Handle the microsoft and gcc \#pragma message
1562 /// extension. The syntax is:
1563 /// \code
1564 /// #pragma message(string)
1565 /// \endcode
1566 /// OR, in GCC mode:
1567 /// \code
1568 /// #pragma message string
1569 /// \endcode
1570 /// string is a string, which is fully macro expanded, and permits string
1571 /// concatenation, embedded escape characters, etc... See MSDN for more details.
1572 /// Also handles \#pragma GCC warning and \#pragma GCC error which take the same
1573 /// form as \#pragma message.
1574 struct PragmaMessageHandler : public PragmaHandler {
1575 private:
1577  const StringRef Namespace;
1578 
1579  static const char* PragmaKind(PPCallbacks::PragmaMessageKind Kind,
1580  bool PragmaNameOnly = false) {
1581  switch (Kind) {
1583  return PragmaNameOnly ? "message" : "pragma message";
1585  return PragmaNameOnly ? "warning" : "pragma warning";
1587  return PragmaNameOnly ? "error" : "pragma error";
1588  }
1589  llvm_unreachable("Unknown PragmaMessageKind!");
1590  }
1591 
1592 public:
1593  PragmaMessageHandler(PPCallbacks::PragmaMessageKind Kind,
1594  StringRef Namespace = StringRef())
1595  : PragmaHandler(PragmaKind(Kind, true)), Kind(Kind),
1596  Namespace(Namespace) {}
1597 
1598  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1599  Token &Tok) override {
1600  SourceLocation MessageLoc = Tok.getLocation();
1601  PP.Lex(Tok);
1602  bool ExpectClosingParen = false;
1603  switch (Tok.getKind()) {
1604  case tok::l_paren:
1605  // We have a MSVC style pragma message.
1606  ExpectClosingParen = true;
1607  // Read the string.
1608  PP.Lex(Tok);
1609  break;
1610  case tok::string_literal:
1611  // We have a GCC style pragma message, and we just read the string.
1612  break;
1613  default:
1614  PP.Diag(MessageLoc, diag::err_pragma_message_malformed) << Kind;
1615  return;
1616  }
1617 
1618  std::string MessageString;
1619  if (!PP.FinishLexStringLiteral(Tok, MessageString, PragmaKind(Kind),
1620  /*AllowMacroExpansion=*/true))
1621  return;
1622 
1623  if (ExpectClosingParen) {
1624  if (Tok.isNot(tok::r_paren)) {
1625  PP.Diag(Tok.getLocation(), diag::err_pragma_message_malformed) << Kind;
1626  return;
1627  }
1628  PP.Lex(Tok); // eat the r_paren.
1629  }
1630 
1631  if (Tok.isNot(tok::eod)) {
1632  PP.Diag(Tok.getLocation(), diag::err_pragma_message_malformed) << Kind;
1633  return;
1634  }
1635 
1636  // Output the message.
1637  PP.Diag(MessageLoc, (Kind == PPCallbacks::PMK_Error)
1638  ? diag::err_pragma_message
1639  : diag::warn_pragma_message) << MessageString;
1640 
1641  // If the pragma is lexically sound, notify any interested PPCallbacks.
1642  if (PPCallbacks *Callbacks = PP.getPPCallbacks())
1643  Callbacks->PragmaMessage(MessageLoc, Namespace, Kind, MessageString);
1644  }
1645 };
1646 
1647 /// Handle the clang \#pragma module import extension. The syntax is:
1648 /// \code
1649 /// #pragma clang module import some.module.name
1650 /// \endcode
1651 struct PragmaModuleImportHandler : public PragmaHandler {
1652  PragmaModuleImportHandler() : PragmaHandler("import") {}
1653 
1654  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1655  Token &Tok) override {
1656  SourceLocation ImportLoc = Tok.getLocation();
1657 
1658  // Read the module name.
1660  ModuleName;
1661  if (LexModuleName(PP, Tok, ModuleName))
1662  return;
1663 
1664  if (Tok.isNot(tok::eod))
1665  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1666 
1667  // If we have a non-empty module path, load the named module.
1668  Module *Imported =
1669  PP.getModuleLoader().loadModule(ImportLoc, ModuleName, Module::Hidden,
1670  /*IsInclusionDirective=*/false);
1671  if (!Imported)
1672  return;
1673 
1674  PP.makeModuleVisible(Imported, ImportLoc);
1675  PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().second),
1676  tok::annot_module_include, Imported);
1677  if (auto *CB = PP.getPPCallbacks())
1678  CB->moduleImport(ImportLoc, ModuleName, Imported);
1679  }
1680 };
1681 
1682 /// Handle the clang \#pragma module begin extension. The syntax is:
1683 /// \code
1684 /// #pragma clang module begin some.module.name
1685 /// ...
1686 /// #pragma clang module end
1687 /// \endcode
1688 struct PragmaModuleBeginHandler : public PragmaHandler {
1689  PragmaModuleBeginHandler() : PragmaHandler("begin") {}
1690 
1691  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1692  Token &Tok) override {
1693  SourceLocation BeginLoc = Tok.getLocation();
1694 
1695  // Read the module name.
1697  ModuleName;
1698  if (LexModuleName(PP, Tok, ModuleName))
1699  return;
1700 
1701  if (Tok.isNot(tok::eod))
1702  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1703 
1704  // We can only enter submodules of the current module.
1705  StringRef Current = PP.getLangOpts().CurrentModule;
1706  if (ModuleName.front().first->getName() != Current) {
1707  PP.Diag(ModuleName.front().second, diag::err_pp_module_begin_wrong_module)
1708  << ModuleName.front().first << (ModuleName.size() > 1)
1709  << Current.empty() << Current;
1710  return;
1711  }
1712 
1713  // Find the module we're entering. We require that a module map for it
1714  // be loaded or implicitly loadable.
1715  auto &HSI = PP.getHeaderSearchInfo();
1716  Module *M = HSI.lookupModule(Current, ModuleName.front().second);
1717  if (!M) {
1718  PP.Diag(ModuleName.front().second,
1719  diag::err_pp_module_begin_no_module_map) << Current;
1720  return;
1721  }
1722  for (unsigned I = 1; I != ModuleName.size(); ++I) {
1723  auto *NewM = M->findOrInferSubmodule(ModuleName[I].first->getName());
1724  if (!NewM) {
1725  PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
1726  << M->getFullModuleName() << ModuleName[I].first;
1727  return;
1728  }
1729  M = NewM;
1730  }
1731 
1732  // If the module isn't available, it doesn't make sense to enter it.
1734  PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics(), M)) {
1735  PP.Diag(BeginLoc, diag::note_pp_module_begin_here)
1736  << M->getTopLevelModuleName();
1737  return;
1738  }
1739 
1740  // Enter the scope of the submodule.
1741  PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true);
1742  PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second),
1743  tok::annot_module_begin, M);
1744  }
1745 };
1746 
1747 /// Handle the clang \#pragma module end extension.
1748 struct PragmaModuleEndHandler : public PragmaHandler {
1749  PragmaModuleEndHandler() : PragmaHandler("end") {}
1750 
1751  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1752  Token &Tok) override {
1753  SourceLocation Loc = Tok.getLocation();
1754 
1755  PP.LexUnexpandedToken(Tok);
1756  if (Tok.isNot(tok::eod))
1757  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1758 
1759  Module *M = PP.LeaveSubmodule(/*ForPragma*/true);
1760  if (M)
1761  PP.EnterAnnotationToken(SourceRange(Loc), tok::annot_module_end, M);
1762  else
1763  PP.Diag(Loc, diag::err_pp_module_end_without_module_begin);
1764  }
1765 };
1766 
1767 /// Handle the clang \#pragma module build extension.
1768 struct PragmaModuleBuildHandler : public PragmaHandler {
1769  PragmaModuleBuildHandler() : PragmaHandler("build") {}
1770 
1771  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1772  Token &Tok) override {
1773  PP.HandlePragmaModuleBuild(Tok);
1774  }
1775 };
1776 
1777 /// Handle the clang \#pragma module load extension.
1778 struct PragmaModuleLoadHandler : public PragmaHandler {
1779  PragmaModuleLoadHandler() : PragmaHandler("load") {}
1780 
1781  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1782  Token &Tok) override {
1783  SourceLocation Loc = Tok.getLocation();
1784 
1785  // Read the module name.
1787  ModuleName;
1788  if (LexModuleName(PP, Tok, ModuleName))
1789  return;
1790 
1791  if (Tok.isNot(tok::eod))
1792  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1793 
1794  // Load the module, don't make it visible.
1795  PP.getModuleLoader().loadModule(Loc, ModuleName, Module::Hidden,
1796  /*IsInclusionDirective=*/false);
1797  }
1798 };
1799 
1800 /// PragmaPushMacroHandler - "\#pragma push_macro" saves the value of the
1801 /// macro on the top of the stack.
1802 struct PragmaPushMacroHandler : public PragmaHandler {
1803  PragmaPushMacroHandler() : PragmaHandler("push_macro") {}
1804 
1805  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1806  Token &PushMacroTok) override {
1807  PP.HandlePragmaPushMacro(PushMacroTok);
1808  }
1809 };
1810 
1811 /// PragmaPopMacroHandler - "\#pragma pop_macro" sets the value of the
1812 /// macro to the value on the top of the stack.
1813 struct PragmaPopMacroHandler : public PragmaHandler {
1814  PragmaPopMacroHandler() : PragmaHandler("pop_macro") {}
1815 
1816  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1817  Token &PopMacroTok) override {
1818  PP.HandlePragmaPopMacro(PopMacroTok);
1819  }
1820 };
1821 
1822 /// PragmaARCCFCodeAuditedHandler -
1823 /// \#pragma clang arc_cf_code_audited begin/end
1824 struct PragmaARCCFCodeAuditedHandler : public PragmaHandler {
1825  PragmaARCCFCodeAuditedHandler() : PragmaHandler("arc_cf_code_audited") {}
1826 
1827  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1828  Token &NameTok) override {
1829  SourceLocation Loc = NameTok.getLocation();
1830  bool IsBegin;
1831 
1832  Token Tok;
1833 
1834  // Lex the 'begin' or 'end'.
1835  PP.LexUnexpandedToken(Tok);
1836  const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo();
1837  if (BeginEnd && BeginEnd->isStr("begin")) {
1838  IsBegin = true;
1839  } else if (BeginEnd && BeginEnd->isStr("end")) {
1840  IsBegin = false;
1841  } else {
1842  PP.Diag(Tok.getLocation(), diag::err_pp_arc_cf_code_audited_syntax);
1843  return;
1844  }
1845 
1846  // Verify that this is followed by EOD.
1847  PP.LexUnexpandedToken(Tok);
1848  if (Tok.isNot(tok::eod))
1849  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1850 
1851  // The start location of the active audit.
1852  SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().second;
1853 
1854  // The start location we want after processing this.
1855  SourceLocation NewLoc;
1856 
1857  if (IsBegin) {
1858  // Complain about attempts to re-enter an audit.
1859  if (BeginLoc.isValid()) {
1860  PP.Diag(Loc, diag::err_pp_double_begin_of_arc_cf_code_audited);
1861  PP.Diag(BeginLoc, diag::note_pragma_entered_here);
1862  }
1863  NewLoc = Loc;
1864  } else {
1865  // Complain about attempts to leave an audit that doesn't exist.
1866  if (!BeginLoc.isValid()) {
1867  PP.Diag(Loc, diag::err_pp_unmatched_end_of_arc_cf_code_audited);
1868  return;
1869  }
1870  NewLoc = SourceLocation();
1871  }
1872 
1873  PP.setPragmaARCCFCodeAuditedInfo(NameTok.getIdentifierInfo(), NewLoc);
1874  }
1875 };
1876 
1877 /// PragmaAssumeNonNullHandler -
1878 /// \#pragma clang assume_nonnull begin/end
1879 struct PragmaAssumeNonNullHandler : public PragmaHandler {
1880  PragmaAssumeNonNullHandler() : PragmaHandler("assume_nonnull") {}
1881 
1882  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1883  Token &NameTok) override {
1884  SourceLocation Loc = NameTok.getLocation();
1885  bool IsBegin;
1886 
1887  Token Tok;
1888 
1889  // Lex the 'begin' or 'end'.
1890  PP.LexUnexpandedToken(Tok);
1891  const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo();
1892  if (BeginEnd && BeginEnd->isStr("begin")) {
1893  IsBegin = true;
1894  } else if (BeginEnd && BeginEnd->isStr("end")) {
1895  IsBegin = false;
1896  } else {
1897  PP.Diag(Tok.getLocation(), diag::err_pp_assume_nonnull_syntax);
1898  return;
1899  }
1900 
1901  // Verify that this is followed by EOD.
1902  PP.LexUnexpandedToken(Tok);
1903  if (Tok.isNot(tok::eod))
1904  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1905 
1906  // The start location of the active audit.
1907  SourceLocation BeginLoc = PP.getPragmaAssumeNonNullLoc();
1908 
1909  // The start location we want after processing this.
1910  SourceLocation NewLoc;
1911  PPCallbacks *Callbacks = PP.getPPCallbacks();
1912 
1913  if (IsBegin) {
1914  // Complain about attempts to re-enter an audit.
1915  if (BeginLoc.isValid()) {
1916  PP.Diag(Loc, diag::err_pp_double_begin_of_assume_nonnull);
1917  PP.Diag(BeginLoc, diag::note_pragma_entered_here);
1918  }
1919  NewLoc = Loc;
1920  if (Callbacks)
1921  Callbacks->PragmaAssumeNonNullBegin(NewLoc);
1922  } else {
1923  // Complain about attempts to leave an audit that doesn't exist.
1924  if (!BeginLoc.isValid()) {
1925  PP.Diag(Loc, diag::err_pp_unmatched_end_of_assume_nonnull);
1926  return;
1927  }
1928  NewLoc = SourceLocation();
1929  if (Callbacks)
1930  Callbacks->PragmaAssumeNonNullEnd(NewLoc);
1931  }
1932 
1933  PP.setPragmaAssumeNonNullLoc(NewLoc);
1934  }
1935 };
1936 
1937 /// Handle "\#pragma region [...]"
1938 ///
1939 /// The syntax is
1940 /// \code
1941 /// #pragma region [optional name]
1942 /// #pragma endregion [optional comment]
1943 /// \endcode
1944 ///
1945 /// \note This is
1946 /// <a href="http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx">editor-only</a>
1947 /// pragma, just skipped by compiler.
1948 struct PragmaRegionHandler : public PragmaHandler {
1949  PragmaRegionHandler(const char *pragma) : PragmaHandler(pragma) {}
1950 
1951  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1952  Token &NameTok) override {
1953  // #pragma region: endregion matches can be verified
1954  // __pragma(region): no sense, but ignored by msvc
1955  // _Pragma is not valid for MSVC, but there isn't any point
1956  // to handle a _Pragma differently.
1957  }
1958 };
1959 
1960 /// This handles parsing pragmas that take a macro name and optional message
1961 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok,
1962  const char *Pragma,
1963  std::string &MessageString) {
1964  PP.Lex(Tok);
1965  if (Tok.isNot(tok::l_paren)) {
1966  PP.Diag(Tok, diag::err_expected) << "(";
1967  return nullptr;
1968  }
1969 
1970  PP.LexUnexpandedToken(Tok);
1971  if (!Tok.is(tok::identifier)) {
1972  PP.Diag(Tok, diag::err_expected) << tok::identifier;
1973  return nullptr;
1974  }
1975  IdentifierInfo *II = Tok.getIdentifierInfo();
1976 
1977  if (!II->hasMacroDefinition()) {
1978  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II;
1979  return nullptr;
1980  }
1981 
1982  PP.Lex(Tok);
1983  if (Tok.is(tok::comma)) {
1984  PP.Lex(Tok);
1985  if (!PP.FinishLexStringLiteral(Tok, MessageString, Pragma,
1986  /*AllowMacroExpansion=*/true))
1987  return nullptr;
1988  }
1989 
1990  if (Tok.isNot(tok::r_paren)) {
1991  PP.Diag(Tok, diag::err_expected) << ")";
1992  return nullptr;
1993  }
1994  return II;
1995 }
1996 
1997 /// "\#pragma clang deprecated(...)"
1998 ///
1999 /// The syntax is
2000 /// \code
2001 /// #pragma clang deprecate(MACRO_NAME [, Message])
2002 /// \endcode
2003 struct PragmaDeprecatedHandler : public PragmaHandler {
2004  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
2005 
2006  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2007  Token &Tok) override {
2008  std::string MessageString;
2009 
2010  if (IdentifierInfo *II = HandleMacroAnnotationPragma(
2011  PP, Tok, "#pragma clang deprecated", MessageString)) {
2012  II->setIsDeprecatedMacro(true);
2013  PP.addMacroDeprecationMsg(II, std::move(MessageString),
2014  Tok.getLocation());
2015  }
2016  }
2017 };
2018 
2019 /// "\#pragma clang restrict_expansion(...)"
2020 ///
2021 /// The syntax is
2022 /// \code
2023 /// #pragma clang restrict_expansion(MACRO_NAME [, Message])
2024 /// \endcode
2025 struct PragmaRestrictExpansionHandler : public PragmaHandler {
2026  PragmaRestrictExpansionHandler() : PragmaHandler("restrict_expansion") {}
2027 
2028  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2029  Token &Tok) override {
2030  std::string MessageString;
2031 
2032  if (IdentifierInfo *II = HandleMacroAnnotationPragma(
2033  PP, Tok, "#pragma clang restrict_expansion", MessageString)) {
2034  II->setIsRestrictExpansion(true);
2035  PP.addRestrictExpansionMsg(II, std::move(MessageString),
2036  Tok.getLocation());
2037  }
2038  }
2039 };
2040 
2041 /// "\#pragma clang final(...)"
2042 ///
2043 /// The syntax is
2044 /// \code
2045 /// #pragma clang final(MACRO_NAME)
2046 /// \endcode
2047 struct PragmaFinalHandler : public PragmaHandler {
2048  PragmaFinalHandler() : PragmaHandler("final") {}
2049 
2050  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2051  Token &Tok) override {
2052  PP.Lex(Tok);
2053  if (Tok.isNot(tok::l_paren)) {
2054  PP.Diag(Tok, diag::err_expected) << "(";
2055  return;
2056  }
2057 
2058  PP.LexUnexpandedToken(Tok);
2059  if (!Tok.is(tok::identifier)) {
2060  PP.Diag(Tok, diag::err_expected) << tok::identifier;
2061  return;
2062  }
2063  IdentifierInfo *II = Tok.getIdentifierInfo();
2064 
2065  if (!II->hasMacroDefinition()) {
2066  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II;
2067  return;
2068  }
2069 
2070  PP.Lex(Tok);
2071  if (Tok.isNot(tok::r_paren)) {
2072  PP.Diag(Tok, diag::err_expected) << ")";
2073  return;
2074  }
2075  II->setIsFinal(true);
2076  PP.addFinalLoc(II, Tok.getLocation());
2077  }
2078 };
2079 
2080 } // namespace
2081 
2082 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
2083 /// \#pragma GCC poison/system_header/dependency and \#pragma once.
2084 void Preprocessor::RegisterBuiltinPragmas() {
2085  AddPragmaHandler(new PragmaOnceHandler());
2086  AddPragmaHandler(new PragmaMarkHandler());
2087  AddPragmaHandler(new PragmaPushMacroHandler());
2088  AddPragmaHandler(new PragmaPopMacroHandler());
2089  AddPragmaHandler(new PragmaMessageHandler(PPCallbacks::PMK_Message));
2090 
2091  // #pragma GCC ...
2092  AddPragmaHandler("GCC", new PragmaPoisonHandler());
2093  AddPragmaHandler("GCC", new PragmaSystemHeaderHandler());
2094  AddPragmaHandler("GCC", new PragmaDependencyHandler());
2095  AddPragmaHandler("GCC", new PragmaDiagnosticHandler("GCC"));
2096  AddPragmaHandler("GCC", new PragmaMessageHandler(PPCallbacks::PMK_Warning,
2097  "GCC"));
2098  AddPragmaHandler("GCC", new PragmaMessageHandler(PPCallbacks::PMK_Error,
2099  "GCC"));
2100  // #pragma clang ...
2101  AddPragmaHandler("clang", new PragmaPoisonHandler());
2102  AddPragmaHandler("clang", new PragmaSystemHeaderHandler());
2103  AddPragmaHandler("clang", new PragmaDebugHandler());
2104  AddPragmaHandler("clang", new PragmaDependencyHandler());
2105  AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
2106  AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
2107  AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
2108  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
2109  AddPragmaHandler("clang", new PragmaRestrictExpansionHandler());
2110  AddPragmaHandler("clang", new PragmaFinalHandler());
2111 
2112  // #pragma clang module ...
2113  auto *ModuleHandler = new PragmaNamespace("module");
2114  AddPragmaHandler("clang", ModuleHandler);
2115  ModuleHandler->AddPragma(new PragmaModuleImportHandler());
2116  ModuleHandler->AddPragma(new PragmaModuleBeginHandler());
2117  ModuleHandler->AddPragma(new PragmaModuleEndHandler());
2118  ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
2119  ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
2120 
2121  // Add region pragmas.
2122  AddPragmaHandler(new PragmaRegionHandler("region"));
2123  AddPragmaHandler(new PragmaRegionHandler("endregion"));
2124 
2125  // MS extensions.
2126  if (LangOpts.MicrosoftExt) {
2127  AddPragmaHandler(new PragmaWarningHandler());
2128  AddPragmaHandler(new PragmaExecCharsetHandler());
2129  AddPragmaHandler(new PragmaIncludeAliasHandler());
2130  AddPragmaHandler(new PragmaHdrstopHandler());
2131  AddPragmaHandler(new PragmaSystemHeaderHandler());
2132  }
2133 
2134  // Pragmas added by plugins
2135  for (const PragmaHandlerRegistry::entry &handler :
2136  PragmaHandlerRegistry::entries()) {
2137  AddPragmaHandler(handler.instantiate().release());
2138  }
2139 }
2140 
2141 /// Ignore all pragmas, useful for modes such as -Eonly which would otherwise
2142 /// warn about those pragmas being unknown.
2145  // Also ignore all pragmas in all namespaces created
2146  // in Preprocessor::RegisterBuiltinPragmas().
2147  AddPragmaHandler("GCC", new EmptyPragmaHandler());
2148  AddPragmaHandler("clang", new EmptyPragmaHandler());
2149 }
clang::ModuleMap::modules
llvm::iterator_range< module_iterator > modules() const
Definition: ModuleMap.h:725
clang::ModuleLoader::createModuleFromSource
virtual void createModuleFromSource(SourceLocation Loc, StringRef ModuleName, StringRef Source)=0
Attempt to create the given module from the specified source buffer.
clang::PPCallbacks::PWS_Once
@ PWS_Once
Definition: PPCallbacks.h:264
clang::Token::startToken
void startToken()
Reset all flags to cleared.
Definition: Token.h:171
PreprocessorLexer.h
clang::diag::Severity
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
Definition: DiagnosticIDs.h:82
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:434
clang::Preprocessor::HandlePragmaPopMacro
void HandlePragmaPopMacro(Token &Tok)
Handle #pragma pop_macro.
Definition: Pragma.cpp:638
clang::IdentifierInfo::hasMacroDefinition
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
Definition: IdentifierTable.h:202
clang::Preprocessor::HandlePragmaSystemHeader
void HandlePragmaSystemHeader(Token &SysHeaderTok)
HandlePragmaSystemHeader - Implement #pragma GCC system_header.
Definition: Pragma.cpp:472
clang::PPCallbacks::PragmaAssumeNonNullBegin
virtual void PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
Definition: PPCallbacks.h:293
clang::Preprocessor::CreateString
void CreateString(StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
Plop the specified string into a scratch buffer and set the specified token's location and length to ...
Definition: Preprocessor.cpp:488
clang::PreprocessorLexer::getFileEntry
OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
Definition: PreprocessorLexer.cpp:51
clang::Preprocessor::RemovePragmaHandler
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
Definition: Pragma.cpp:934
clang::PPCallbacks::PragmaDebug
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
Definition: PPCallbacks.h:212
clang::Preprocessor::getPreprocessorAllocator
llvm::BumpPtrAllocator & getPreprocessorAllocator()
Definition: Preprocessor.h:1076
clang::Preprocessor::setPragmaAssumeNonNullLoc
void setPragmaAssumeNonNullLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1860
clang::diag::Severity::Error
@ Error
Present this diagnostic as an error.
clang::Preprocessor::FinishLexStringLiteral
bool FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Complete the lexing of a string literal where the first token has already been lexed (see LexStringLi...
Definition: Preprocessor.cpp:1333
clang::IdentifierInfo::setChangedSinceDeserialization
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
Definition: IdentifierTable.h:397
clang::PragmaHandler::~PragmaHandler
virtual ~PragmaHandler()
clang::DeclaratorContext::File
@ File
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PPCallbacks::PragmaAssumeNonNullEnd
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
Definition: PPCallbacks.h:297
LexModuleName
static bool LexModuleName(Preprocessor &PP, Token &Tok, llvm::SmallVectorImpl< std::pair< IdentifierInfo *, SourceLocation >> &ModuleName)
Definition: Pragma.cpp:779
clang::PresumedLoc::getLine
unsigned getLine() const
Return the presumed line number of this location.
Definition: SourceLocation.h:337
clang::Preprocessor::HandlePragmaMark
void HandlePragmaMark(Token &MarkTok)
Definition: Pragma.cpp:420
clang::Preprocessor::getPPCallbacks
PPCallbacks * getPPCallbacks() const
Definition: Preprocessor.h:1162
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:881
clang::DiagnosticsEngine::popMappings
bool popMappings(SourceLocation Loc)
Pops the current DiagMappings off the top of the stack, causing the new top of the stack to be the ac...
Definition: Diagnostic.cpp:122
clang::SourceManager::isInMainFile
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
Definition: SourceManager.cpp:1599
clang::PPCallbacks::PWS_Disable
@ PWS_Disable
Definition: PPCallbacks.h:262
clang::Preprocessor::LexHeaderName
bool LexHeaderName(Token &Result, bool AllowMacroExpansion=true)
Lex a token, forming a header-name token if possible.
Definition: Preprocessor.cpp:997
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::Preprocessor::TUKind
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:292
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::PPCallbacks::PMK_Error
@ PMK_Error
#pragma GCC error has been invoked.
Definition: PPCallbacks.h:224
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
clang::SourceManager::noteSLocAddressSpaceUsage
void noteSLocAddressSpaceUsage(DiagnosticsEngine &Diag, Optional< unsigned > MaxNotes=32) const
Definition: SourceManager.cpp:2238
clang::Preprocessor::IgnorePragmas
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:2143
INT_MAX
#define INT_MAX
Definition: limits.h:46
clang::PreprocessorLexer
Definition: PreprocessorLexer.h:30
clang::IdentifierInfo::setIsFinal
void setIsFinal(bool Val)
Definition: IdentifierTable.h:257
clang::Lexer::Create_PragmaLexer
static Lexer * Create_PragmaLexer(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLen, Preprocessor &PP)
Create_PragmaLexer: Lexer constructor - Create a new lexer object for _Pragma expansion.
Definition: Lexer.cpp:195
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:181
Filename
StringRef Filename
Definition: Format.cpp:2715
CLWarnings.h
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
Module.h
clang::Token::isAtStartOfLine
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:270
clang::diagGroupFromCLWarningID
llvm::Optional< diag::Group > diagGroupFromCLWarningID(unsigned)
For cl.exe warning IDs that cleany map to clang diagnostic groups, returns the corresponding group.
Definition: CLWarnings.cpp:19
llvm::Optional< FileEntryRef >
clang::ComparisonCategoryType::First
@ First
clang::PPCallbacks::PragmaDiagnosticPush
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
Definition: PPCallbacks.h:238
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceManager.h
clang::SourceManager::getPresumedLoc
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Definition: SourceManager.cpp:1523
clang::PragmaNamespace::getIfNamespace
PragmaNamespace * getIfNamespace() override
getIfNamespace - If this is a namespace, return it.
Definition: Pragma.h:123
clang::DiagnosticsEngine::setSeverityForGroup
bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc=SourceLocation())
Change an entire diagnostic group (e.g.
Definition: Diagnostic.cpp:405
clang::Preprocessor::EnterToken
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Definition: Preprocessor.h:1698
clang::PreprocessorLexer::LexingRawMode
bool LexingRawMode
True if in raw mode.
Definition: PreprocessorLexer.h:68
LexModuleNameComponent
static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok, std::pair< IdentifierInfo *, SourceLocation > &ModuleNameComponent, bool First)
Definition: Pragma.cpp:758
clang::PragmaNamespace::IsEmpty
bool IsEmpty() const
Definition: Pragma.h:118
clang::Token::setAnnotationRange
void setAnnotationRange(SourceRange R)
Definition: Token.h:163
clang::SourceManager::AddLineNote
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
Definition: SourceManager.cpp:273
clang::PPCallbacks::PWS_Suppress
@ PWS_Suppress
Definition: PPCallbacks.h:265
clang::IdentifierInfo::isFromAST
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
Definition: IdentifierTable.h:385
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::Preprocessor::getCurrentFileLexer
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
Definition: PPLexerChange.cpp:49
Identifier
StringRef Identifier
Definition: Format.cpp:2723
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
clang::tok::isStringLiteral
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
Definition: TokenKinds.h:81
LiteralSupport.h
clang::Preprocessor::AddPragmaHandler
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
Definition: Pragma.cpp:903
End
SourceLocation End
Definition: USRLocFinder.cpp:167
TokenLexer.h
clang::Preprocessor::addFinalLoc
void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2663
clang::PreprocessorOptions::DisablePragmaDebugCrash
bool DisablePragmaDebugCrash
Prevents intended crashes when using #pragma clang __debug. For testing.
Definition: PreprocessorOptions.h:221
clang::EmptyPragmaHandler::HandlePragma
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken) override
Definition: Pragma.cpp:66
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:1065
Preprocessor.h
clang::ModuleLoader::loadModule
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
clang::Preprocessor::creatingPCHWithPragmaHdrStop
bool creatingPCHWithPragmaHdrStop()
True if creating a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:626
clang::TU_Prefix
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:920
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:78
clang::HeaderSearch::MarkFileIncludeOnce
void MarkFileIncludeOnce(const FileEntry *File)
Mark the specified file as a "once only" file due to #pragma once.
Definition: HeaderSearch.h:526
clang::index::SymbolKind::Namespace
@ Namespace
TokenKinds.h
clang::Preprocessor::GetIncludeFilenameSpelling
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
Definition: PPDirectives.cpp:1756
clang::dataflow::Literal
uint32_t Literal
Literals are represented as positive integers.
Definition: WatchedLiteralsSolver.cpp:55
clang::IdentifierInfo::isStr
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Definition: IdentifierTable.h:177
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::diag::Severity::Ignored
@ Ignored
Do not present this diagnostic, ignore it.
clang::Preprocessor::HandlePragmaOnce
void HandlePragmaOnce(Token &OnceTok)
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
Definition: Pragma.cpp:405
clang::SourceLocation::print
void print(raw_ostream &OS, const SourceManager &SM) const
Definition: SourceLocation.cpp:62
clang::PIK___pragma
@ PIK___pragma
The pragma was introduced via the Microsoft __pragma(token-string).
Definition: Pragma.h:47
clang::Module
Describes a module or submodule.
Definition: Module.h:98
clang::Module::Hidden
@ Hidden
All of the names in this module are hidden.
Definition: Module.h:336
clang::Module::findOrInferSubmodule
Module * findOrInferSubmodule(StringRef Name)
Definition: Module.cpp:339
clang::Preprocessor::getBuildingSubmodules
ArrayRef< BuildingSubmoduleInfo > getBuildingSubmodules() const
Get the list of submodules that we're currently building.
Definition: Preprocessor.h:1310
clang::Preprocessor::ParsePragmaPushOrPopMacro
IdentifierInfo * ParsePragmaPushOrPopMacro(Token &Tok)
ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
Definition: Pragma.cpp:560
clang::diag::Flavor::WarningOrError
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
clang::PragmaNamespace::RemovePragmaHandler
void RemovePragmaHandler(PragmaHandler *Handler)
RemovePragmaHandler - Remove the given handler from the namespace.
Definition: Pragma.cpp:97
Id
int Id
Definition: ASTDiff.cpp:189
hlsl::uint64_t
unsigned long uint64_t
Definition: hlsl_basic_types.h:25
Pragma.h
clang::PresumedLoc::getFilename
const char * getFilename() const
Return the presumed filename of this location.
Definition: SourceLocation.h:324
clang::PragmaNamespace::HandlePragma
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &Tok) override
Definition: Pragma.cpp:106
clang::SourceManager::getLineTableFilenameID
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
Definition: SourceManager.cpp:266
clang::Module::getTopLevelModuleName
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:603
clang::diag::Severity::Fatal
@ Fatal
Present this diagnostic as a fatal error.
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:93
clang::IdentifierInfo::setIsPoisoned
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
Definition: IdentifierTable.h:346
LangOptions.h
clang::PPCallbacks::PragmaExecCharsetPush
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
Definition: PPCallbacks.h:285
Diagnostic.h
LexDiagnostic.h
clang::PragmaHandler::getIfNamespace
virtual PragmaNamespace * getIfNamespace()
getIfNamespace - If this is a namespace, return it.
Definition: Pragma.h:79
clang::PragmaIntroducer::Kind
PragmaIntroducerKind Kind
Definition: Pragma.h:52
clang::PPCallbacks::PragmaWarning
virtual void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids)
Definition: PPCallbacks.h:271
clang::PragmaHandler::getName
StringRef getName() const
Definition: Pragma.h:73
clang::PPCallbacks::PragmaMessage
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
Definition: PPCallbacks.h:232
clang::Preprocessor::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Definition: Preprocessor.h:1899
ModuleLoader.h
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:98
clang::Preprocessor::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:1066
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1193
IdentifierTable.h
clang::Preprocessor::EnterSubmodule
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Definition: PPLexerChange.cpp:684
clang::Token::setAnnotationValue
void setAnnotationValue(void *val)
Definition: Token.h:232
llvm::SmallString
Definition: LLVM.h:37
clang::PreprocessorLexer::ParsingPreprocessorDirective
bool ParsingPreprocessorDirective
True when parsing #XXX; turns '\n' into a tok::eod token.
Definition: PreprocessorLexer.h:50
clang::Preprocessor::HandlePragmaPushMacro
void HandlePragmaPushMacro(Token &Tok)
Handle #pragma push_macro.
Definition: Pragma.cpp:615
clang::Preprocessor::getMacroInfo
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
Definition: Preprocessor.h:1258
clang::PragmaIntroducer
Describes how and where the pragma was introduced.
Definition: Pragma.h:51
clang::tok::OOS_DEFAULT
@ OOS_DEFAULT
Definition: TokenKinds.h:49
clang::PPCallbacks::PMK_Warning
@ PMK_Warning
#pragma GCC warning has been invoked.
Definition: PPCallbacks.h:221
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:99
clang::PPCallbacks::PMK_Message
@ PMK_Message
#pragma message has been invoked.
Definition: PPCallbacks.h:218
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:366
clang::ModuleMap
Definition: ModuleMap.h:75
clang::tok::OOS_ON
@ OOS_ON
Definition: TokenKinds.h:49
clang::Token::getRawIdentifier
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
Definition: Token.h:207
clang::Token::LeadingSpace
@ LeadingSpace
Definition: Token.h:76
clang::PragmaHandler
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
Definition: Pragma.h:65
clang::IdentifierInfo::setIsDeprecatedMacro
void setIsDeprecatedMacro(bool Val)
Definition: IdentifierTable.h:233
clang::Module::submodules
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:713
clang::diag::Severity::Warning
@ Warning
Present this diagnostic as a warning.
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:1069
clang::Preprocessor::HandlePragmaModuleBuild
void HandlePragmaModuleBuild(Token &Tok)
Definition: Pragma.cpp:795
IsHeaderFile
static bool IsHeaderFile(const std::string &Filename)
Definition: RewriteModernObjC.cpp:629
clang::PPCallbacks::PWS_Level1
@ PWS_Level1
Definition: PPCallbacks.h:266
clang::Preprocessor::LexOnOffSwitch
bool LexOnOffSwitch(tok::OnOffSwitch &Result)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
Definition: Pragma.cpp:956
clang::PresumedLoc::isInvalid
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Definition: SourceLocation.h:318
clang::Preprocessor::getSpelling
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
Definition: Preprocessor.h:1914
SourceLocation.h
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Preprocessor::HandlePragmaPoison
void HandlePragmaPoison()
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
Definition: Pragma.cpp:430
clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
Definition: MacroInfo.h:157
clang::PPCallbacks::SystemHeaderPragma
@ SystemHeaderPragma
Definition: PPCallbacks.h:40
clang::PragmaNamespace::AddPragma
void AddPragma(PragmaHandler *Handler)
AddPragma - Add a pragma to this namespace.
Definition: Pragma.cpp:91
clang::Preprocessor::usingPCHWithPragmaHdrStop
bool usingPCHWithPragmaHdrStop()
True if using a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:630
clang::IdentifierInfo::isPoisoned
bool isPoisoned() const
Return true if this token has been poisoned.
Definition: IdentifierTable.h:355
clang::Preprocessor::getPragmaARCCFCodeAuditedInfo
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1839
clang::EmptyPragmaHandler
EmptyPragmaHandler - A pragma handler which takes no action, which can be used to ignore particular p...
Definition: Pragma.h:84
clang::Preprocessor::dumpMacroInfo
void dumpMacroInfo(const IdentifierInfo *II)
Definition: PPMacroExpansion.cpp:259
Specifier
const NestedNameSpecifier * Specifier
Definition: USRLocFinder.cpp:173
Lexer.h
Value
Value
Definition: UninitializedValues.cpp:103
HeaderSearch.h
clang::Preprocessor::getPragmaAssumeNonNullLoc
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1854
clang::Preprocessor::appendDefMacroDirective
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
Definition: Preprocessor.h:1279
LLVM.h
clang::ModuleMap::lookupModuleQualified
Module * lookupModuleQualified(StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup.
Definition: ModuleMap.cpp:826
clang::EmptyPragmaHandler::EmptyPragmaHandler
EmptyPragmaHandler(StringRef Name=StringRef())
Definition: Pragma.cpp:64
clang::IdentifierInfo::setIsRestrictExpansion
void setIsRestrictExpansion(bool Val)
Definition: IdentifierTable.h:245
clang::diag::Flavor
Flavor
Flavors of diagnostics we can emit.
Definition: DiagnosticIDs.h:93
clang::PPCallbacks::PragmaDiagnosticPop
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic pop directive is read.
Definition: PPCallbacks.h:244
clang::PPCallbacks::PragmaWarningSpecifier
PragmaWarningSpecifier
Callback invoked when a #pragma warning directive is read.
Definition: PPCallbacks.h:260
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::Preprocessor::LexStringLiteral
bool LexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Lex a string literal, which may be the concatenation of multiple string literals and may even come fr...
Definition: Preprocessor.h:1604
clang::diag::Flavor::Remark
@ Remark
A diagnostic that indicates normal progress through compilation.
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Token::isAnnotation
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:120
clang::Preprocessor::getModuleImportLoc
SourceLocation getModuleImportLoc(Module *M) const
Definition: Preprocessor.h:1597
clang::Preprocessor::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:1060
clang::Preprocessor::getModuleLoader
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
Definition: Preprocessor.h:1087
clang::PragmaHandler::HandlePragma
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken)=0
clang::HeaderSearch::MarkFileSystemHeader
void MarkFileSystemHeader(const FileEntry *File)
Mark the specified file as a system header, e.g.
Definition: HeaderSearch.h:533
clang::PPCallbacks::PWS_Default
@ PWS_Default
Definition: PPCallbacks.h:261
clang::DiagnosticsEngine::dump
LLVM_DUMP_METHOD void dump() const
Definition: Diagnostic.cpp:104
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:196
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang::Preprocessor::CheckEndOfDirective
SourceLocation CheckEndOfDirective(const char *DirType, bool EnableMacros=false)
Ensure that the next token is a tok::eod token.
Definition: PPDirectives.cpp:415
clang
Definition: CalledOnceCheck.h:17
PPCallbacks.h
clang::FileEntry::getModificationTime
time_t getModificationTime() const
Definition: FileEntry.h:404
clang::Preprocessor::LookUpIdentifierInfo
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Definition: Preprocessor.cpp:712
MacroInfo.h
clang::PPCallbacks::PragmaMessageKind
PragmaMessageKind
Determines the kind of #pragma invoking a call to PragmaMessage.
Definition: PPCallbacks.h:216
clang::tok::OOS_OFF
@ OOS_OFF
Definition: TokenKinds.h:49
clang::Preprocessor::HandlePragmaHdrstop
void HandlePragmaHdrstop(Token &Tok)
Definition: Pragma.cpp:869
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:1062
clang::PragmaIntroducer::Loc
SourceLocation Loc
Definition: Pragma.h:53
clang::Preprocessor::addRestrictExpansionMsg
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2651
clang::Preprocessor::DiscardUntilEndOfDirective
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
Definition: PPDirectives.cpp:82
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::tok::OnOffSwitch
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:48
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::Preprocessor::LookupFile
Optional< FileEntryRef > LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool OpenFile=true, bool CacheFailures=true)
Given a "foo" or <foo> reference, look up the indicated file.
Definition: PPDirectives.cpp:951
clang::Preprocessor::isInPrimaryFile
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
Definition: PPLexerChange.cpp:34
clang::Module::dump
void dump() const
Dump the contents of this module to the given output stream.
Definition: APINotesYAMLCompiler.cpp:577
clang::Token::setKind
void setKind(tok::TokenKind K)
Definition: Token.h:94
clang::Preprocessor::makeModuleVisible
void makeModuleVisible(Module *M, SourceLocation Loc)
Definition: Preprocessor.cpp:1316
clang::PPCallbacks::PragmaExecCharsetPop
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
Definition: PPCallbacks.h:289
clang::HeaderSearch::AddIncludeAlias
void AddIncludeAlias(StringRef Source, StringRef Dest)
Map the source include name to the dest include name.
Definition: HeaderSearch.h:386
clang::Preprocessor::addMacroDeprecationMsg
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2639
clang::Preprocessor::HandlePragmaDependency
void HandlePragmaDependency(Token &DependencyTok)
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
Definition: Pragma.cpp:504
clang::Preprocessor::HandlePragmaIncludeAlias
void HandlePragmaIncludeAlias(Token &Tok)
Definition: Pragma.cpp:673
clang::DiagnosticsEngine::setSeverityForAll
void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, SourceLocation Loc=SourceLocation())
Add the specified mapping to all diagnostics of the specified flavor.
Definition: Diagnostic.cpp:489
clang::Preprocessor::setPragmaARCCFCodeAuditedInfo
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc)
Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1845
clang::DiagnosticsEngine::pushMappings
void pushMappings(SourceLocation Loc)
Copies the current DiagMappings and pushes the new copy onto the top of the stack.
Definition: Diagnostic.cpp:118
clang::Preprocessor::LeaveSubmodule
Module * LeaveSubmodule(bool ForPragma)
Definition: PPLexerChange.cpp:761
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
clang::PresumedLoc
Represents an unpacked "presumed" location which can be presented to the user.
Definition: SourceLocation.h:302
clang::Preprocessor::checkModuleIsAvailable
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
Definition: PPDirectives.cpp:1891
llvm::SmallVectorImpl
Definition: Randstruct.h:18
FileManager.h
clang::SrcMgr::C_System
@ C_System
Definition: SourceManager.h:81
clang::PragmaNamespace
PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, allowing hierarchical pragm...
Definition: Pragma.h:96
true
#define true
Definition: stdbool.h:21
clang::Preprocessor::LexUnexpandedToken
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
Definition: Preprocessor.h:1632
clang::PIK__Pragma
@ PIK__Pragma
The pragma was introduced via the C99 _Pragma(string-literal).
Definition: Pragma.h:41
PreprocessorOptions.h
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:129
clang::Preprocessor::appendMacroDirective
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
Definition: PPMacroExpansion.cpp:72
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:1070
Token.h
clang::PragmaNamespace::FindHandler
PragmaHandler * FindHandler(StringRef Name, bool IgnoreNull=true) const
FindHandler - Check to see if there is already a handler for the specified name.
Definition: Pragma.cpp:78
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:218
clang::Preprocessor::EnterAnnotationToken
void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
Enter an annotation token into the token stream.
Definition: PPDirectives.cpp:1804
clang::RISCV::Invalid
@ Invalid
Definition: RISCVVIntrinsicUtils.h:171
clang::PPCallbacks::PragmaWarningPush
virtual void PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
Definition: PPCallbacks.h:276
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:791
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:163
clang::PPCallbacks::PragmaWarningPop
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) directive is read.
Definition: PPCallbacks.h:280
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1383
clang::Preprocessor::parseSimpleIntegerLiteral
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
Definition: Preprocessor.cpp:1374
clang::PPCallbacks::PragmaDiagnostic
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition: PPCallbacks.h:249
clang::Token::hasUDSuffix
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix.
Definition: Token.h:295
clang::PPCallbacks::PWS_Error
@ PWS_Error
Definition: PPCallbacks.h:263