Pragma.cpp revision 4e4d08403ca5cfd4d558fa2936215d3a4e5a528d
1//===--- Pragma.cpp - Pragma registration and handling --------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PragmaHandler/PragmaTable interfaces and implements
11// pragma related methods of the Preprocessor class.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Lex/Pragma.h"
16#include "clang/Lex/HeaderSearch.h"
17#include "clang/Lex/LiteralSupport.h"
18#include "clang/Lex/Preprocessor.h"
19#include "clang/Lex/MacroInfo.h"
20#include "clang/Lex/LexDiagnostic.h"
21#include "clang/Basic/FileManager.h"
22#include "clang/Basic/SourceManager.h"
23#include "llvm/Support/CrashRecoveryContext.h"
24#include "llvm/Support/ErrorHandling.h"
25#include <algorithm>
26using namespace clang;
27
28// Out-of-line destructor to provide a home for the class.
29PragmaHandler::~PragmaHandler() {
30}
31
32//===----------------------------------------------------------------------===//
33// EmptyPragmaHandler Implementation.
34//===----------------------------------------------------------------------===//
35
36EmptyPragmaHandler::EmptyPragmaHandler() {}
37
38void EmptyPragmaHandler::HandlePragma(Preprocessor &PP,
39                                      PragmaIntroducerKind Introducer,
40                                      Token &FirstToken) {}
41
42//===----------------------------------------------------------------------===//
43// PragmaNamespace Implementation.
44//===----------------------------------------------------------------------===//
45
46
47PragmaNamespace::~PragmaNamespace() {
48  for (llvm::StringMap<PragmaHandler*>::iterator
49         I = Handlers.begin(), E = Handlers.end(); I != E; ++I)
50    delete I->second;
51}
52
53/// FindHandler - Check to see if there is already a handler for the
54/// specified name.  If not, return the handler for the null identifier if it
55/// exists, otherwise return null.  If IgnoreNull is true (the default) then
56/// the null handler isn't returned on failure to match.
57PragmaHandler *PragmaNamespace::FindHandler(StringRef Name,
58                                            bool IgnoreNull) const {
59  if (PragmaHandler *Handler = Handlers.lookup(Name))
60    return Handler;
61  return IgnoreNull ? 0 : Handlers.lookup(StringRef());
62}
63
64void PragmaNamespace::AddPragma(PragmaHandler *Handler) {
65  assert(!Handlers.lookup(Handler->getName()) &&
66         "A handler with this name is already registered in this namespace");
67  llvm::StringMapEntry<PragmaHandler *> &Entry =
68    Handlers.GetOrCreateValue(Handler->getName());
69  Entry.setValue(Handler);
70}
71
72void PragmaNamespace::RemovePragmaHandler(PragmaHandler *Handler) {
73  assert(Handlers.lookup(Handler->getName()) &&
74         "Handler not registered in this namespace");
75  Handlers.erase(Handler->getName());
76}
77
78void PragmaNamespace::HandlePragma(Preprocessor &PP,
79                                   PragmaIntroducerKind Introducer,
80                                   Token &Tok) {
81  // Read the 'namespace' that the directive is in, e.g. STDC.  Do not macro
82  // expand it, the user can have a STDC #define, that should not affect this.
83  PP.LexUnexpandedToken(Tok);
84
85  // Get the handler for this token.  If there is no handler, ignore the pragma.
86  PragmaHandler *Handler
87    = FindHandler(Tok.getIdentifierInfo() ? Tok.getIdentifierInfo()->getName()
88                                          : StringRef(),
89                  /*IgnoreNull=*/false);
90  if (Handler == 0) {
91    PP.Diag(Tok, diag::warn_pragma_ignored);
92    return;
93  }
94
95  // Otherwise, pass it down.
96  Handler->HandlePragma(PP, Introducer, Tok);
97}
98
99//===----------------------------------------------------------------------===//
100// Preprocessor Pragma Directive Handling.
101//===----------------------------------------------------------------------===//
102
103/// HandlePragmaDirective - The "#pragma" directive has been parsed.  Lex the
104/// rest of the pragma, passing it to the registered pragma handlers.
105void Preprocessor::HandlePragmaDirective(unsigned Introducer) {
106  ++NumPragma;
107
108  // Invoke the first level of pragma handlers which reads the namespace id.
109  Token Tok;
110  PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok);
111
112  // If the pragma handler didn't read the rest of the line, consume it now.
113  if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective())
114   || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective))
115    DiscardUntilEndOfDirective();
116}
117
118/// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
119/// return the first token after the directive.  The _Pragma token has just
120/// been read into 'Tok'.
121void Preprocessor::Handle_Pragma(Token &Tok) {
122  // Remember the pragma token location.
123  SourceLocation PragmaLoc = Tok.getLocation();
124
125  // Read the '('.
126  Lex(Tok);
127  if (Tok.isNot(tok::l_paren)) {
128    Diag(PragmaLoc, diag::err__Pragma_malformed);
129    return;
130  }
131
132  // Read the '"..."'.
133  Lex(Tok);
134  if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal)) {
135    Diag(PragmaLoc, diag::err__Pragma_malformed);
136    // Skip this token, and the ')', if present.
137    if (Tok.isNot(tok::r_paren))
138      Lex(Tok);
139    if (Tok.is(tok::r_paren))
140      Lex(Tok);
141    return;
142  }
143
144  if (Tok.hasUDSuffix()) {
145    Diag(Tok, diag::err_invalid_string_udl);
146    // Skip this token, and the ')', if present.
147    Lex(Tok);
148    if (Tok.is(tok::r_paren))
149      Lex(Tok);
150    return;
151  }
152
153  // Remember the string.
154  std::string StrVal = getSpelling(Tok);
155
156  // Read the ')'.
157  Lex(Tok);
158  if (Tok.isNot(tok::r_paren)) {
159    Diag(PragmaLoc, diag::err__Pragma_malformed);
160    return;
161  }
162
163  SourceLocation RParenLoc = Tok.getLocation();
164
165  // The _Pragma is lexically sound.  Destringize according to C99 6.10.9.1:
166  // "The string literal is destringized by deleting the L prefix, if present,
167  // deleting the leading and trailing double-quotes, replacing each escape
168  // sequence \" by a double-quote, and replacing each escape sequence \\ by a
169  // single backslash."
170  if (StrVal[0] == 'L')  // Remove L prefix.
171    StrVal.erase(StrVal.begin());
172  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
173         "Invalid string token!");
174
175  // Remove the front quote, replacing it with a space, so that the pragma
176  // contents appear to have a space before them.
177  StrVal[0] = ' ';
178
179  // Replace the terminating quote with a \n.
180  StrVal[StrVal.size()-1] = '\n';
181
182  // Remove escaped quotes and escapes.
183  for (unsigned i = 0, e = StrVal.size(); i != e-1; ++i) {
184    if (StrVal[i] == '\\' &&
185        (StrVal[i+1] == '\\' || StrVal[i+1] == '"')) {
186      // \\ -> '\' and \" -> '"'.
187      StrVal.erase(StrVal.begin()+i);
188      --e;
189    }
190  }
191
192  // Plop the string (including the newline and trailing null) into a buffer
193  // where we can lex it.
194  Token TmpTok;
195  TmpTok.startToken();
196  CreateString(&StrVal[0], StrVal.size(), TmpTok);
197  SourceLocation TokLoc = TmpTok.getLocation();
198
199  // Make and enter a lexer object so that we lex and expand the tokens just
200  // like any others.
201  Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
202                                        StrVal.size(), *this);
203
204  EnterSourceFileWithLexer(TL, 0);
205
206  // With everything set up, lex this as a #pragma directive.
207  HandlePragmaDirective(PIK__Pragma);
208
209  // Finally, return whatever came after the pragma directive.
210  return Lex(Tok);
211}
212
213/// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
214/// is not enclosed within a string literal.
215void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
216  // Remember the pragma token location.
217  SourceLocation PragmaLoc = Tok.getLocation();
218
219  // Read the '('.
220  Lex(Tok);
221  if (Tok.isNot(tok::l_paren)) {
222    Diag(PragmaLoc, diag::err__Pragma_malformed);
223    return;
224  }
225
226  // Get the tokens enclosed within the __pragma(), as well as the final ')'.
227  SmallVector<Token, 32> PragmaToks;
228  int NumParens = 0;
229  Lex(Tok);
230  while (Tok.isNot(tok::eof)) {
231    PragmaToks.push_back(Tok);
232    if (Tok.is(tok::l_paren))
233      NumParens++;
234    else if (Tok.is(tok::r_paren) && NumParens-- == 0)
235      break;
236    Lex(Tok);
237  }
238
239  if (Tok.is(tok::eof)) {
240    Diag(PragmaLoc, diag::err_unterminated___pragma);
241    return;
242  }
243
244  PragmaToks.front().setFlag(Token::LeadingSpace);
245
246  // Replace the ')' with an EOD to mark the end of the pragma.
247  PragmaToks.back().setKind(tok::eod);
248
249  Token *TokArray = new Token[PragmaToks.size()];
250  std::copy(PragmaToks.begin(), PragmaToks.end(), TokArray);
251
252  // Push the tokens onto the stack.
253  EnterTokenStream(TokArray, PragmaToks.size(), true, true);
254
255  // With everything set up, lex this as a #pragma directive.
256  HandlePragmaDirective(PIK___pragma);
257
258  // Finally, return whatever came after the pragma directive.
259  return Lex(Tok);
260}
261
262/// HandlePragmaOnce - Handle #pragma once.  OnceTok is the 'once'.
263///
264void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
265  if (isInPrimaryFile()) {
266    Diag(OnceTok, diag::pp_pragma_once_in_main_file);
267    return;
268  }
269
270  // Get the current file lexer we're looking at.  Ignore _Pragma 'files' etc.
271  // Mark the file as a once-only file now.
272  HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
273}
274
275void Preprocessor::HandlePragmaMark() {
276  assert(CurPPLexer && "No current lexer?");
277  if (CurLexer)
278    CurLexer->ReadToEndOfLine();
279  else
280    CurPTHLexer->DiscardToEndOfLine();
281}
282
283
284/// HandlePragmaPoison - Handle #pragma GCC poison.  PoisonTok is the 'poison'.
285///
286void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
287  Token Tok;
288
289  while (1) {
290    // Read the next token to poison.  While doing this, pretend that we are
291    // skipping while reading the identifier to poison.
292    // This avoids errors on code like:
293    //   #pragma GCC poison X
294    //   #pragma GCC poison X
295    if (CurPPLexer) CurPPLexer->LexingRawMode = true;
296    LexUnexpandedToken(Tok);
297    if (CurPPLexer) CurPPLexer->LexingRawMode = false;
298
299    // If we reached the end of line, we're done.
300    if (Tok.is(tok::eod)) return;
301
302    // Can only poison identifiers.
303    if (Tok.isNot(tok::raw_identifier)) {
304      Diag(Tok, diag::err_pp_invalid_poison);
305      return;
306    }
307
308    // Look up the identifier info for the token.  We disabled identifier lookup
309    // by saying we're skipping contents, so we need to do this manually.
310    IdentifierInfo *II = LookUpIdentifierInfo(Tok);
311
312    // Already poisoned.
313    if (II->isPoisoned()) continue;
314
315    // If this is a macro identifier, emit a warning.
316    if (II->hasMacroDefinition())
317      Diag(Tok, diag::pp_poisoning_existing_macro);
318
319    // Finally, poison it!
320    II->setIsPoisoned();
321    if (II->isFromAST())
322      II->setChangedSinceDeserialization();
323  }
324}
325
326/// HandlePragmaSystemHeader - Implement #pragma GCC system_header.  We know
327/// that the whole directive has been parsed.
328void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) {
329  if (isInPrimaryFile()) {
330    Diag(SysHeaderTok, diag::pp_pragma_sysheader_in_main_file);
331    return;
332  }
333
334  // Get the current file lexer we're looking at.  Ignore _Pragma 'files' etc.
335  PreprocessorLexer *TheLexer = getCurrentFileLexer();
336
337  // Mark the file as a system header.
338  HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
339
340
341  PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
342  if (PLoc.isInvalid())
343    return;
344
345  unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename());
346
347  // Notify the client, if desired, that we are in a new source file.
348  if (Callbacks)
349    Callbacks->FileChanged(SysHeaderTok.getLocation(),
350                           PPCallbacks::SystemHeaderPragma, SrcMgr::C_System);
351
352  // Emit a line marker.  This will change any source locations from this point
353  // forward to realize they are in a system header.
354  // Create a line note with this information.
355  SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine(), FilenameID,
356                        false, false, true, false);
357}
358
359/// HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
360///
361void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
362  Token FilenameTok;
363  CurPPLexer->LexIncludeFilename(FilenameTok);
364
365  // If the token kind is EOD, the error has already been diagnosed.
366  if (FilenameTok.is(tok::eod))
367    return;
368
369  // Reserve a buffer to get the spelling.
370  SmallString<128> FilenameBuffer;
371  bool Invalid = false;
372  StringRef Filename = getSpelling(FilenameTok, FilenameBuffer, &Invalid);
373  if (Invalid)
374    return;
375
376  bool isAngled =
377    GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
378  // If GetIncludeFilenameSpelling set the start ptr to null, there was an
379  // error.
380  if (Filename.empty())
381    return;
382
383  // Search include directories for this file.
384  const DirectoryLookup *CurDir;
385  const FileEntry *File = LookupFile(Filename, isAngled, 0, CurDir, NULL, NULL,
386                                     NULL);
387  if (File == 0) {
388    if (!SuppressIncludeNotFoundError)
389      Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
390    return;
391  }
392
393  const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry();
394
395  // If this file is older than the file it depends on, emit a diagnostic.
396  if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) {
397    // Lex tokens at the end of the message and include them in the message.
398    std::string Message;
399    Lex(DependencyTok);
400    while (DependencyTok.isNot(tok::eod)) {
401      Message += getSpelling(DependencyTok) + " ";
402      Lex(DependencyTok);
403    }
404
405    // Remove the trailing ' ' if present.
406    if (!Message.empty())
407      Message.erase(Message.end()-1);
408    Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message;
409  }
410}
411
412/// HandlePragmaComment - Handle the microsoft #pragma comment extension.  The
413/// syntax is:
414///   #pragma comment(linker, "foo")
415/// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user.
416/// "foo" is a string, which is fully macro expanded, and permits string
417/// concatenation, embedded escape characters etc.  See MSDN for more details.
418void Preprocessor::HandlePragmaComment(Token &Tok) {
419  SourceLocation CommentLoc = Tok.getLocation();
420  Lex(Tok);
421  if (Tok.isNot(tok::l_paren)) {
422    Diag(CommentLoc, diag::err_pragma_comment_malformed);
423    return;
424  }
425
426  // Read the identifier.
427  Lex(Tok);
428  if (Tok.isNot(tok::identifier)) {
429    Diag(CommentLoc, diag::err_pragma_comment_malformed);
430    return;
431  }
432
433  // Verify that this is one of the 5 whitelisted options.
434  // FIXME: warn that 'exestr' is deprecated.
435  const IdentifierInfo *II = Tok.getIdentifierInfo();
436  if (!II->isStr("compiler") && !II->isStr("exestr") && !II->isStr("lib") &&
437      !II->isStr("linker") && !II->isStr("user")) {
438    Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind);
439    return;
440  }
441
442  // Read the optional string if present.
443  Lex(Tok);
444  std::string ArgumentString;
445  if (Tok.is(tok::comma)) {
446    Lex(Tok); // eat the comma.
447
448    // We need at least one string.
449    if (Tok.isNot(tok::string_literal)) {
450      Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
451      return;
452    }
453
454    // String concatenation allows multiple strings, which can even come from
455    // macro expansion.
456    // "foo " "bar" "Baz"
457    SmallVector<Token, 4> StrToks;
458    while (Tok.is(tok::string_literal)) {
459      if (Tok.hasUDSuffix())
460        Diag(Tok, diag::err_invalid_string_udl);
461      StrToks.push_back(Tok);
462      Lex(Tok);
463    }
464
465    // Concatenate and parse the strings.
466    StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);
467    assert(Literal.isAscii() && "Didn't allow wide strings in");
468    if (Literal.hadError)
469      return;
470    if (Literal.Pascal) {
471      Diag(StrToks[0].getLocation(), diag::err_pragma_comment_malformed);
472      return;
473    }
474
475    ArgumentString = Literal.GetString();
476  }
477
478  // FIXME: If the kind is "compiler" warn if the string is present (it is
479  // ignored).
480  // FIXME: 'lib' requires a comment string.
481  // FIXME: 'linker' requires a comment string, and has a specific list of
482  // things that are allowable.
483
484  if (Tok.isNot(tok::r_paren)) {
485    Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
486    return;
487  }
488  Lex(Tok);  // eat the r_paren.
489
490  if (Tok.isNot(tok::eod)) {
491    Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
492    return;
493  }
494
495  // If the pragma is lexically sound, notify any interested PPCallbacks.
496  if (Callbacks)
497    Callbacks->PragmaComment(CommentLoc, II, ArgumentString);
498}
499
500/// HandlePragmaMessage - Handle the microsoft and gcc #pragma message
501/// extension.  The syntax is:
502///   #pragma message(string)
503/// OR, in GCC mode:
504///   #pragma message string
505/// string is a string, which is fully macro expanded, and permits string
506/// concatenation, embedded escape characters, etc... See MSDN for more details.
507void Preprocessor::HandlePragmaMessage(Token &Tok) {
508  SourceLocation MessageLoc = Tok.getLocation();
509  Lex(Tok);
510  bool ExpectClosingParen = false;
511  switch (Tok.getKind()) {
512  case tok::l_paren:
513    // We have a MSVC style pragma message.
514    ExpectClosingParen = true;
515    // Read the string.
516    Lex(Tok);
517    break;
518  case tok::string_literal:
519    // We have a GCC style pragma message, and we just read the string.
520    break;
521  default:
522    Diag(MessageLoc, diag::err_pragma_message_malformed);
523    return;
524  }
525
526  // We need at least one string.
527  if (Tok.isNot(tok::string_literal)) {
528    Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
529    return;
530  }
531
532  // String concatenation allows multiple strings, which can even come from
533  // macro expansion.
534  // "foo " "bar" "Baz"
535  SmallVector<Token, 4> StrToks;
536  while (Tok.is(tok::string_literal)) {
537    if (Tok.hasUDSuffix())
538      Diag(Tok, diag::err_invalid_string_udl);
539    StrToks.push_back(Tok);
540    Lex(Tok);
541  }
542
543  // Concatenate and parse the strings.
544  StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);
545  assert(Literal.isAscii() && "Didn't allow wide strings in");
546  if (Literal.hadError)
547    return;
548  if (Literal.Pascal) {
549    Diag(StrToks[0].getLocation(), diag::err_pragma_message_malformed);
550    return;
551  }
552
553  StringRef MessageString(Literal.GetString());
554
555  if (ExpectClosingParen) {
556    if (Tok.isNot(tok::r_paren)) {
557      Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
558      return;
559    }
560    Lex(Tok);  // eat the r_paren.
561  }
562
563  if (Tok.isNot(tok::eod)) {
564    Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
565    return;
566  }
567
568  // Output the message.
569  Diag(MessageLoc, diag::warn_pragma_message) << MessageString;
570
571  // If the pragma is lexically sound, notify any interested PPCallbacks.
572  if (Callbacks)
573    Callbacks->PragmaMessage(MessageLoc, MessageString);
574}
575
576/// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
577/// Return the IdentifierInfo* associated with the macro to push or pop.
578IdentifierInfo *Preprocessor::ParsePragmaPushOrPopMacro(Token &Tok) {
579  // Remember the pragma token location.
580  Token PragmaTok = Tok;
581
582  // Read the '('.
583  Lex(Tok);
584  if (Tok.isNot(tok::l_paren)) {
585    Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
586      << getSpelling(PragmaTok);
587    return 0;
588  }
589
590  // Read the macro name string.
591  Lex(Tok);
592  if (Tok.isNot(tok::string_literal)) {
593    Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
594      << getSpelling(PragmaTok);
595    return 0;
596  }
597
598  if (Tok.hasUDSuffix()) {
599    Diag(Tok, diag::err_invalid_string_udl);
600    return 0;
601  }
602
603  // Remember the macro string.
604  std::string StrVal = getSpelling(Tok);
605
606  // Read the ')'.
607  Lex(Tok);
608  if (Tok.isNot(tok::r_paren)) {
609    Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
610      << getSpelling(PragmaTok);
611    return 0;
612  }
613
614  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
615         "Invalid string token!");
616
617  // Create a Token from the string.
618  Token MacroTok;
619  MacroTok.startToken();
620  MacroTok.setKind(tok::raw_identifier);
621  CreateString(&StrVal[1], StrVal.size() - 2, MacroTok);
622
623  // Get the IdentifierInfo of MacroToPushTok.
624  return LookUpIdentifierInfo(MacroTok);
625}
626
627/// HandlePragmaPushMacro - Handle #pragma push_macro.
628/// The syntax is:
629///   #pragma push_macro("macro")
630void Preprocessor::HandlePragmaPushMacro(Token &PushMacroTok) {
631  // Parse the pragma directive and get the macro IdentifierInfo*.
632  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PushMacroTok);
633  if (!IdentInfo) return;
634
635  // Get the MacroInfo associated with IdentInfo.
636  MacroInfo *MI = getMacroInfo(IdentInfo);
637
638  MacroInfo *MacroCopyToPush = 0;
639  if (MI) {
640    // Make a clone of MI.
641    MacroCopyToPush = CloneMacroInfo(*MI);
642
643    // Allow the original MacroInfo to be redefined later.
644    MI->setIsAllowRedefinitionsWithoutWarning(true);
645  }
646
647  // Push the cloned MacroInfo so we can retrieve it later.
648  PragmaPushMacroInfo[IdentInfo].push_back(MacroCopyToPush);
649}
650
651/// HandlePragmaPopMacro - Handle #pragma pop_macro.
652/// The syntax is:
653///   #pragma pop_macro("macro")
654void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) {
655  SourceLocation MessageLoc = PopMacroTok.getLocation();
656
657  // Parse the pragma directive and get the macro IdentifierInfo*.
658  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PopMacroTok);
659  if (!IdentInfo) return;
660
661  // Find the vector<MacroInfo*> associated with the macro.
662  llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> >::iterator iter =
663    PragmaPushMacroInfo.find(IdentInfo);
664  if (iter != PragmaPushMacroInfo.end()) {
665    // Release the MacroInfo currently associated with IdentInfo.
666    MacroInfo *CurrentMI = getMacroInfo(IdentInfo);
667    if (CurrentMI) {
668      if (CurrentMI->isWarnIfUnused())
669        WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc());
670      ReleaseMacroInfo(CurrentMI);
671    }
672
673    // Get the MacroInfo we want to reinstall.
674    MacroInfo *MacroToReInstall = iter->second.back();
675
676    // Reinstall the previously pushed macro.
677    setMacroInfo(IdentInfo, MacroToReInstall);
678
679    // Pop PragmaPushMacroInfo stack.
680    iter->second.pop_back();
681    if (iter->second.size() == 0)
682      PragmaPushMacroInfo.erase(iter);
683  } else {
684    Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push)
685      << IdentInfo->getName();
686  }
687}
688
689void Preprocessor::HandlePragmaIncludeAlias(Token &Tok) {
690  // We will either get a quoted filename or a bracketed filename, and we
691  // have to track which we got.  The first filename is the source name,
692  // and the second name is the mapped filename.  If the first is quoted,
693  // the second must be as well (cannot mix and match quotes and brackets).
694
695  // Get the open paren
696  Lex(Tok);
697  if (Tok.isNot(tok::l_paren)) {
698    Diag(Tok, diag::warn_pragma_include_alias_expected) << "(";
699    return;
700  }
701
702  // We expect either a quoted string literal, or a bracketed name
703  Token SourceFilenameTok;
704  CurPPLexer->LexIncludeFilename(SourceFilenameTok);
705  if (SourceFilenameTok.is(tok::eod)) {
706    // The diagnostic has already been handled
707    return;
708  }
709
710  StringRef SourceFileName;
711  SmallString<128> FileNameBuffer;
712  if (SourceFilenameTok.is(tok::string_literal) ||
713      SourceFilenameTok.is(tok::angle_string_literal)) {
714    SourceFileName = getSpelling(SourceFilenameTok, FileNameBuffer);
715  } else if (SourceFilenameTok.is(tok::less)) {
716    // This could be a path instead of just a name
717    FileNameBuffer.push_back('<');
718    SourceLocation End;
719    if (ConcatenateIncludeName(FileNameBuffer, End))
720      return; // Diagnostic already emitted
721    SourceFileName = FileNameBuffer.str();
722  } else {
723    Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
724    return;
725  }
726  FileNameBuffer.clear();
727
728  // Now we expect a comma, followed by another include name
729  Lex(Tok);
730  if (Tok.isNot(tok::comma)) {
731    Diag(Tok, diag::warn_pragma_include_alias_expected) << ",";
732    return;
733  }
734
735  Token ReplaceFilenameTok;
736  CurPPLexer->LexIncludeFilename(ReplaceFilenameTok);
737  if (ReplaceFilenameTok.is(tok::eod)) {
738    // The diagnostic has already been handled
739    return;
740  }
741
742  StringRef ReplaceFileName;
743  if (ReplaceFilenameTok.is(tok::string_literal) ||
744      ReplaceFilenameTok.is(tok::angle_string_literal)) {
745    ReplaceFileName = getSpelling(ReplaceFilenameTok, FileNameBuffer);
746  } else if (ReplaceFilenameTok.is(tok::less)) {
747    // This could be a path instead of just a name
748    FileNameBuffer.push_back('<');
749    SourceLocation End;
750    if (ConcatenateIncludeName(FileNameBuffer, End))
751      return; // Diagnostic already emitted
752    ReplaceFileName = FileNameBuffer.str();
753  } else {
754    Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
755    return;
756  }
757
758  // Finally, we expect the closing paren
759  Lex(Tok);
760  if (Tok.isNot(tok::r_paren)) {
761    Diag(Tok, diag::warn_pragma_include_alias_expected) << ")";
762    return;
763  }
764
765  // Now that we have the source and target filenames, we need to make sure
766  // they're both of the same type (angled vs non-angled)
767  StringRef OriginalSource = SourceFileName;
768
769  bool SourceIsAngled =
770    GetIncludeFilenameSpelling(SourceFilenameTok.getLocation(),
771                                SourceFileName);
772  bool ReplaceIsAngled =
773    GetIncludeFilenameSpelling(ReplaceFilenameTok.getLocation(),
774                                ReplaceFileName);
775  if (!SourceFileName.empty() && !ReplaceFileName.empty() &&
776      (SourceIsAngled != ReplaceIsAngled)) {
777    unsigned int DiagID;
778    if (SourceIsAngled)
779      DiagID = diag::warn_pragma_include_alias_mismatch_angle;
780    else
781      DiagID = diag::warn_pragma_include_alias_mismatch_quote;
782
783    Diag(SourceFilenameTok.getLocation(), DiagID)
784      << SourceFileName
785      << ReplaceFileName;
786
787    return;
788  }
789
790  // Now we can let the include handler know about this mapping
791  getHeaderSearchInfo().AddIncludeAlias(OriginalSource, ReplaceFileName);
792}
793
794/// AddPragmaHandler - Add the specified pragma handler to the preprocessor.
795/// If 'Namespace' is non-null, then it is a token required to exist on the
796/// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
797void Preprocessor::AddPragmaHandler(StringRef Namespace,
798                                    PragmaHandler *Handler) {
799  PragmaNamespace *InsertNS = PragmaHandlers;
800
801  // If this is specified to be in a namespace, step down into it.
802  if (!Namespace.empty()) {
803    // If there is already a pragma handler with the name of this namespace,
804    // we either have an error (directive with the same name as a namespace) or
805    // we already have the namespace to insert into.
806    if (PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace)) {
807      InsertNS = Existing->getIfNamespace();
808      assert(InsertNS != 0 && "Cannot have a pragma namespace and pragma"
809             " handler with the same name!");
810    } else {
811      // Otherwise, this namespace doesn't exist yet, create and insert the
812      // handler for it.
813      InsertNS = new PragmaNamespace(Namespace);
814      PragmaHandlers->AddPragma(InsertNS);
815    }
816  }
817
818  // Check to make sure we don't already have a pragma for this identifier.
819  assert(!InsertNS->FindHandler(Handler->getName()) &&
820         "Pragma handler already exists for this identifier!");
821  InsertNS->AddPragma(Handler);
822}
823
824/// RemovePragmaHandler - Remove the specific pragma handler from the
825/// preprocessor. If \arg Namespace is non-null, then it should be the
826/// namespace that \arg Handler was added to. It is an error to remove
827/// a handler that has not been registered.
828void Preprocessor::RemovePragmaHandler(StringRef Namespace,
829                                       PragmaHandler *Handler) {
830  PragmaNamespace *NS = PragmaHandlers;
831
832  // If this is specified to be in a namespace, step down into it.
833  if (!Namespace.empty()) {
834    PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace);
835    assert(Existing && "Namespace containing handler does not exist!");
836
837    NS = Existing->getIfNamespace();
838    assert(NS && "Invalid namespace, registered as a regular pragma handler!");
839  }
840
841  NS->RemovePragmaHandler(Handler);
842
843  // If this is a non-default namespace and it is now empty, remove
844  // it.
845  if (NS != PragmaHandlers && NS->IsEmpty()) {
846    PragmaHandlers->RemovePragmaHandler(NS);
847    delete NS;
848  }
849}
850
851bool Preprocessor::LexOnOffSwitch(tok::OnOffSwitch &Result) {
852  Token Tok;
853  LexUnexpandedToken(Tok);
854
855  if (Tok.isNot(tok::identifier)) {
856    Diag(Tok, diag::ext_on_off_switch_syntax);
857    return true;
858  }
859  IdentifierInfo *II = Tok.getIdentifierInfo();
860  if (II->isStr("ON"))
861    Result = tok::OOS_ON;
862  else if (II->isStr("OFF"))
863    Result = tok::OOS_OFF;
864  else if (II->isStr("DEFAULT"))
865    Result = tok::OOS_DEFAULT;
866  else {
867    Diag(Tok, diag::ext_on_off_switch_syntax);
868    return true;
869  }
870
871  // Verify that this is followed by EOD.
872  LexUnexpandedToken(Tok);
873  if (Tok.isNot(tok::eod))
874    Diag(Tok, diag::ext_pragma_syntax_eod);
875  return false;
876}
877
878namespace {
879/// PragmaOnceHandler - "#pragma once" marks the file as atomically included.
880struct PragmaOnceHandler : public PragmaHandler {
881  PragmaOnceHandler() : PragmaHandler("once") {}
882  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
883                            Token &OnceTok) {
884    PP.CheckEndOfDirective("pragma once");
885    PP.HandlePragmaOnce(OnceTok);
886  }
887};
888
889/// PragmaMarkHandler - "#pragma mark ..." is ignored by the compiler, and the
890/// rest of the line is not lexed.
891struct PragmaMarkHandler : public PragmaHandler {
892  PragmaMarkHandler() : PragmaHandler("mark") {}
893  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
894                            Token &MarkTok) {
895    PP.HandlePragmaMark();
896  }
897};
898
899/// PragmaPoisonHandler - "#pragma poison x" marks x as not usable.
900struct PragmaPoisonHandler : public PragmaHandler {
901  PragmaPoisonHandler() : PragmaHandler("poison") {}
902  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
903                            Token &PoisonTok) {
904    PP.HandlePragmaPoison(PoisonTok);
905  }
906};
907
908/// PragmaSystemHeaderHandler - "#pragma system_header" marks the current file
909/// as a system header, which silences warnings in it.
910struct PragmaSystemHeaderHandler : public PragmaHandler {
911  PragmaSystemHeaderHandler() : PragmaHandler("system_header") {}
912  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
913                            Token &SHToken) {
914    PP.HandlePragmaSystemHeader(SHToken);
915    PP.CheckEndOfDirective("pragma");
916  }
917};
918struct PragmaDependencyHandler : public PragmaHandler {
919  PragmaDependencyHandler() : PragmaHandler("dependency") {}
920  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
921                            Token &DepToken) {
922    PP.HandlePragmaDependency(DepToken);
923  }
924};
925
926struct PragmaDebugHandler : public PragmaHandler {
927  PragmaDebugHandler() : PragmaHandler("__debug") {}
928  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
929                            Token &DepToken) {
930    Token Tok;
931    PP.LexUnexpandedToken(Tok);
932    if (Tok.isNot(tok::identifier)) {
933      PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
934      return;
935    }
936    IdentifierInfo *II = Tok.getIdentifierInfo();
937
938    if (II->isStr("assert")) {
939      llvm_unreachable("This is an assertion!");
940    } else if (II->isStr("crash")) {
941      *(volatile int*) 0x11 = 0;
942    } else if (II->isStr("llvm_fatal_error")) {
943      llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
944    } else if (II->isStr("llvm_unreachable")) {
945      llvm_unreachable("#pragma clang __debug llvm_unreachable");
946    } else if (II->isStr("overflow_stack")) {
947      DebugOverflowStack();
948    } else if (II->isStr("handle_crash")) {
949      llvm::CrashRecoveryContext *CRC =llvm::CrashRecoveryContext::GetCurrent();
950      if (CRC)
951        CRC->HandleCrash();
952    } else {
953      PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
954        << II->getName();
955    }
956  }
957
958// Disable MSVC warning about runtime stack overflow.
959#ifdef _MSC_VER
960    #pragma warning(disable : 4717)
961#endif
962  void DebugOverflowStack() {
963    DebugOverflowStack();
964  }
965#ifdef _MSC_VER
966    #pragma warning(default : 4717)
967#endif
968
969};
970
971/// PragmaDiagnosticHandler - e.g. '#pragma GCC diagnostic ignored "-Wformat"'
972struct PragmaDiagnosticHandler : public PragmaHandler {
973private:
974  const char *Namespace;
975public:
976  explicit PragmaDiagnosticHandler(const char *NS) :
977    PragmaHandler("diagnostic"), Namespace(NS) {}
978  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
979                            Token &DiagToken) {
980    SourceLocation DiagLoc = DiagToken.getLocation();
981    Token Tok;
982    PP.LexUnexpandedToken(Tok);
983    if (Tok.isNot(tok::identifier)) {
984      PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
985      return;
986    }
987    IdentifierInfo *II = Tok.getIdentifierInfo();
988    PPCallbacks *Callbacks = PP.getPPCallbacks();
989
990    diag::Mapping Map;
991    if (II->isStr("warning"))
992      Map = diag::MAP_WARNING;
993    else if (II->isStr("error"))
994      Map = diag::MAP_ERROR;
995    else if (II->isStr("ignored"))
996      Map = diag::MAP_IGNORE;
997    else if (II->isStr("fatal"))
998      Map = diag::MAP_FATAL;
999    else if (II->isStr("pop")) {
1000      if (!PP.getDiagnostics().popMappings(DiagLoc))
1001        PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop);
1002      else if (Callbacks)
1003        Callbacks->PragmaDiagnosticPop(DiagLoc, Namespace);
1004      return;
1005    } else if (II->isStr("push")) {
1006      PP.getDiagnostics().pushMappings(DiagLoc);
1007      if (Callbacks)
1008        Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace);
1009      return;
1010    } else {
1011      PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1012      return;
1013    }
1014
1015    PP.LexUnexpandedToken(Tok);
1016
1017    // We need at least one string.
1018    if (Tok.isNot(tok::string_literal)) {
1019      PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
1020      return;
1021    }
1022
1023    // String concatenation allows multiple strings, which can even come from
1024    // macro expansion.
1025    // "foo " "bar" "Baz"
1026    SmallVector<Token, 4> StrToks;
1027    while (Tok.is(tok::string_literal)) {
1028      StrToks.push_back(Tok);
1029      PP.LexUnexpandedToken(Tok);
1030    }
1031
1032    if (Tok.isNot(tok::eod)) {
1033      PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
1034      return;
1035    }
1036
1037    // Concatenate and parse the strings.
1038    StringLiteralParser Literal(&StrToks[0], StrToks.size(), PP);
1039    assert(Literal.isAscii() && "Didn't allow wide strings in");
1040    if (Literal.hadError)
1041      return;
1042    if (Literal.Pascal) {
1043      PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1044      return;
1045    }
1046
1047    StringRef WarningName(Literal.GetString());
1048
1049    if (WarningName.size() < 3 || WarningName[0] != '-' ||
1050        WarningName[1] != 'W') {
1051      PP.Diag(StrToks[0].getLocation(),
1052              diag::warn_pragma_diagnostic_invalid_option);
1053      return;
1054    }
1055
1056    if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.substr(2),
1057                                                      Map, DiagLoc))
1058      PP.Diag(StrToks[0].getLocation(),
1059              diag::warn_pragma_diagnostic_unknown_warning) << WarningName;
1060    else if (Callbacks)
1061      Callbacks->PragmaDiagnostic(DiagLoc, Namespace, Map, WarningName);
1062  }
1063};
1064
1065/// PragmaCommentHandler - "#pragma comment ...".
1066struct PragmaCommentHandler : public PragmaHandler {
1067  PragmaCommentHandler() : PragmaHandler("comment") {}
1068  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1069                            Token &CommentTok) {
1070    PP.HandlePragmaComment(CommentTok);
1071  }
1072};
1073
1074/// PragmaIncludeAliasHandler - "#pragma include_alias("...")".
1075struct PragmaIncludeAliasHandler : public PragmaHandler {
1076  PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}
1077  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1078                            Token &IncludeAliasTok) {
1079      PP.HandlePragmaIncludeAlias(IncludeAliasTok);
1080  }
1081};
1082
1083/// PragmaMessageHandler - "#pragma message("...")".
1084struct PragmaMessageHandler : public PragmaHandler {
1085  PragmaMessageHandler() : PragmaHandler("message") {}
1086  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1087                            Token &CommentTok) {
1088    PP.HandlePragmaMessage(CommentTok);
1089  }
1090};
1091
1092/// PragmaPushMacroHandler - "#pragma push_macro" saves the value of the
1093/// macro on the top of the stack.
1094struct PragmaPushMacroHandler : public PragmaHandler {
1095  PragmaPushMacroHandler() : PragmaHandler("push_macro") {}
1096  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1097                            Token &PushMacroTok) {
1098    PP.HandlePragmaPushMacro(PushMacroTok);
1099  }
1100};
1101
1102
1103/// PragmaPopMacroHandler - "#pragma pop_macro" sets the value of the
1104/// macro to the value on the top of the stack.
1105struct PragmaPopMacroHandler : public PragmaHandler {
1106  PragmaPopMacroHandler() : PragmaHandler("pop_macro") {}
1107  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1108                            Token &PopMacroTok) {
1109    PP.HandlePragmaPopMacro(PopMacroTok);
1110  }
1111};
1112
1113// Pragma STDC implementations.
1114
1115/// PragmaSTDC_FENV_ACCESSHandler - "#pragma STDC FENV_ACCESS ...".
1116struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
1117  PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
1118  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1119                            Token &Tok) {
1120    tok::OnOffSwitch OOS;
1121    if (PP.LexOnOffSwitch(OOS))
1122     return;
1123    if (OOS == tok::OOS_ON)
1124      PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
1125  }
1126};
1127
1128/// PragmaSTDC_CX_LIMITED_RANGEHandler - "#pragma STDC CX_LIMITED_RANGE ...".
1129struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
1130  PragmaSTDC_CX_LIMITED_RANGEHandler()
1131    : PragmaHandler("CX_LIMITED_RANGE") {}
1132  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1133                            Token &Tok) {
1134    tok::OnOffSwitch OOS;
1135    PP.LexOnOffSwitch(OOS);
1136  }
1137};
1138
1139/// PragmaSTDC_UnknownHandler - "#pragma STDC ...".
1140struct PragmaSTDC_UnknownHandler : public PragmaHandler {
1141  PragmaSTDC_UnknownHandler() {}
1142  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1143                            Token &UnknownTok) {
1144    // C99 6.10.6p2, unknown forms are not allowed.
1145    PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
1146  }
1147};
1148
1149/// PragmaARCCFCodeAuditedHandler -
1150///   #pragma clang arc_cf_code_audited begin/end
1151struct PragmaARCCFCodeAuditedHandler : public PragmaHandler {
1152  PragmaARCCFCodeAuditedHandler() : PragmaHandler("arc_cf_code_audited") {}
1153  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
1154                            Token &NameTok) {
1155    SourceLocation Loc = NameTok.getLocation();
1156    bool IsBegin;
1157
1158    Token Tok;
1159
1160    // Lex the 'begin' or 'end'.
1161    PP.LexUnexpandedToken(Tok);
1162    const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo();
1163    if (BeginEnd && BeginEnd->isStr("begin")) {
1164      IsBegin = true;
1165    } else if (BeginEnd && BeginEnd->isStr("end")) {
1166      IsBegin = false;
1167    } else {
1168      PP.Diag(Tok.getLocation(), diag::err_pp_arc_cf_code_audited_syntax);
1169      return;
1170    }
1171
1172    // Verify that this is followed by EOD.
1173    PP.LexUnexpandedToken(Tok);
1174    if (Tok.isNot(tok::eod))
1175      PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1176
1177    // The start location of the active audit.
1178    SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedLoc();
1179
1180    // The start location we want after processing this.
1181    SourceLocation NewLoc;
1182
1183    if (IsBegin) {
1184      // Complain about attempts to re-enter an audit.
1185      if (BeginLoc.isValid()) {
1186        PP.Diag(Loc, diag::err_pp_double_begin_of_arc_cf_code_audited);
1187        PP.Diag(BeginLoc, diag::note_pragma_entered_here);
1188      }
1189      NewLoc = Loc;
1190    } else {
1191      // Complain about attempts to leave an audit that doesn't exist.
1192      if (!BeginLoc.isValid()) {
1193        PP.Diag(Loc, diag::err_pp_unmatched_end_of_arc_cf_code_audited);
1194        return;
1195      }
1196      NewLoc = SourceLocation();
1197    }
1198
1199    PP.setPragmaARCCFCodeAuditedLoc(NewLoc);
1200  }
1201};
1202
1203}  // end anonymous namespace
1204
1205
1206/// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
1207/// #pragma GCC poison/system_header/dependency and #pragma once.
1208void Preprocessor::RegisterBuiltinPragmas() {
1209  AddPragmaHandler(new PragmaOnceHandler());
1210  AddPragmaHandler(new PragmaMarkHandler());
1211  AddPragmaHandler(new PragmaPushMacroHandler());
1212  AddPragmaHandler(new PragmaPopMacroHandler());
1213  AddPragmaHandler(new PragmaMessageHandler());
1214
1215  // #pragma GCC ...
1216  AddPragmaHandler("GCC", new PragmaPoisonHandler());
1217  AddPragmaHandler("GCC", new PragmaSystemHeaderHandler());
1218  AddPragmaHandler("GCC", new PragmaDependencyHandler());
1219  AddPragmaHandler("GCC", new PragmaDiagnosticHandler("GCC"));
1220  // #pragma clang ...
1221  AddPragmaHandler("clang", new PragmaPoisonHandler());
1222  AddPragmaHandler("clang", new PragmaSystemHeaderHandler());
1223  AddPragmaHandler("clang", new PragmaDebugHandler());
1224  AddPragmaHandler("clang", new PragmaDependencyHandler());
1225  AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
1226  AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
1227
1228  AddPragmaHandler("STDC", new PragmaSTDC_FENV_ACCESSHandler());
1229  AddPragmaHandler("STDC", new PragmaSTDC_CX_LIMITED_RANGEHandler());
1230  AddPragmaHandler("STDC", new PragmaSTDC_UnknownHandler());
1231
1232  // MS extensions.
1233  if (LangOpts.MicrosoftExt) {
1234    AddPragmaHandler(new PragmaCommentHandler());
1235    AddPragmaHandler(new PragmaIncludeAliasHandler());
1236  }
1237}
1238