diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Diffstat (limited to 'contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp b/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp index e376fff90432..b026ae36fc0f 100644 --- a/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp +++ b/contrib/llvm-project/clang/lib/Lex/Preprocessor.cpp @@ -716,12 +716,14 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier) const { } // Update the token info (identifier info and appropriate token kind). + // FIXME: the raw_identifier may contain leading whitespace which is removed + // from the cleaned identifier token. The SourceLocation should be updated to + // refer to the non-whitespace character. For instance, the text "\\\nB" (a + // line continuation before 'B') is parsed as a single tok::raw_identifier and + // is cleaned to tok::identifier "B". After cleaning the token's length is + // still 3 and the SourceLocation refers to the location of the backslash. Identifier.setIdentifierInfo(II); - if (getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() && - getSourceManager().isInSystemHeader(Identifier.getLocation())) - Identifier.setKind(tok::identifier); - else - Identifier.setKind(II->getTokenID()); + Identifier.setKind(II->getTokenID()); return II; } @@ -1381,7 +1383,7 @@ bool Preprocessor::parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value) { void Preprocessor::addCommentHandler(CommentHandler *Handler) { assert(Handler && "NULL comment handler"); - assert(llvm::find(CommentHandlers, Handler) == CommentHandlers.end() && + assert(!llvm::is_contained(CommentHandlers, Handler) && "Comment handler already registered"); CommentHandlers.push_back(Handler); } @@ -1407,6 +1409,48 @@ bool Preprocessor::HandleComment(Token &result, SourceRange Comment) { return true; } +void Preprocessor::emitMacroDeprecationWarning(const Token &Identifier) const { + const MacroAnnotations &A = + getMacroAnnotations(Identifier.getIdentifierInfo()); + assert(A.DeprecationInfo && + "Macro deprecation warning without recorded annotation!"); + const MacroAnnotationInfo &Info = *A.DeprecationInfo; + if (Info.Message.empty()) + Diag(Identifier, diag::warn_pragma_deprecated_macro_use) + << Identifier.getIdentifierInfo() << 0; + else + Diag(Identifier, diag::warn_pragma_deprecated_macro_use) + << Identifier.getIdentifierInfo() << 1 << Info.Message; + Diag(Info.Location, diag::note_pp_macro_annotation) << 0; +} + +void Preprocessor::emitRestrictExpansionWarning(const Token &Identifier) const { + const MacroAnnotations &A = + getMacroAnnotations(Identifier.getIdentifierInfo()); + assert(A.RestrictExpansionInfo && + "Macro restricted expansion warning without recorded annotation!"); + const MacroAnnotationInfo &Info = *A.RestrictExpansionInfo; + if (Info.Message.empty()) + Diag(Identifier, diag::warn_pragma_restrict_expansion_macro_use) + << Identifier.getIdentifierInfo() << 0; + else + Diag(Identifier, diag::warn_pragma_restrict_expansion_macro_use) + << Identifier.getIdentifierInfo() << 1 << Info.Message; + Diag(Info.Location, diag::note_pp_macro_annotation) << 1; +} + +void Preprocessor::emitFinalMacroWarning(const Token &Identifier, + bool IsUndef) const { + const MacroAnnotations &A = + getMacroAnnotations(Identifier.getIdentifierInfo()); + assert(A.FinalAnnotationLoc && + "Final macro warning without recorded annotation!"); + + Diag(Identifier, diag::warn_pragma_final_macro) + << Identifier.getIdentifierInfo() << (IsUndef ? 0 : 1); + Diag(*A.FinalAnnotationLoc, diag::note_pp_macro_annotation) << 2; +} + ModuleLoader::~ModuleLoader() = default; CommentHandler::~CommentHandler() = default; |