aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Parse/Parser.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Parse/Parser.cpp66
1 files changed, 50 insertions, 16 deletions
diff --git a/contrib/llvm-project/clang/lib/Parse/Parser.cpp b/contrib/llvm-project/clang/lib/Parse/Parser.cpp
index 764d4e8e9d52..9b0f921b4269 100644
--- a/contrib/llvm-project/clang/lib/Parse/Parser.cpp
+++ b/contrib/llvm-project/clang/lib/Parse/Parser.cpp
@@ -227,6 +227,38 @@ bool Parser::expectIdentifier() {
return true;
}
+void Parser::checkCompoundToken(SourceLocation FirstTokLoc,
+ tok::TokenKind FirstTokKind, CompoundToken Op) {
+ if (FirstTokLoc.isInvalid())
+ return;
+ SourceLocation SecondTokLoc = Tok.getLocation();
+
+ // If either token is in a macro, we expect both tokens to come from the same
+ // macro expansion.
+ if ((FirstTokLoc.isMacroID() || SecondTokLoc.isMacroID()) &&
+ PP.getSourceManager().getFileID(FirstTokLoc) !=
+ PP.getSourceManager().getFileID(SecondTokLoc)) {
+ Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro)
+ << (FirstTokKind == Tok.getKind()) << FirstTokKind << Tok.getKind()
+ << static_cast<int>(Op) << SourceRange(FirstTokLoc);
+ Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here)
+ << (FirstTokKind == Tok.getKind()) << Tok.getKind()
+ << SourceRange(SecondTokLoc);
+ return;
+ }
+
+ // We expect the tokens to abut.
+ if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) {
+ SourceLocation SpaceLoc = PP.getLocForEndOfToken(FirstTokLoc);
+ if (SpaceLoc.isInvalid())
+ SpaceLoc = FirstTokLoc;
+ Diag(SpaceLoc, diag::warn_compound_token_split_by_whitespace)
+ << (FirstTokKind == Tok.getKind()) << FirstTokKind << Tok.getKind()
+ << static_cast<int>(Op) << SourceRange(FirstTokLoc, SecondTokLoc);
+ return;
+ }
+}
+
//===----------------------------------------------------------------------===//
// Error recovery.
//===----------------------------------------------------------------------===//
@@ -552,9 +584,10 @@ bool Parser::ParseFirstTopLevelDecl(DeclGroupPtrTy &Result) {
// declaration. C++ doesn't have this restriction. We also don't want to
// complain if we have a precompiled header, although technically if the PCH
// is empty we should still emit the (pedantic) diagnostic.
+ // If the main file is a header, we're only pretending it's a TU; don't warn.
bool NoTopLevelDecls = ParseTopLevelDecl(Result, true);
if (NoTopLevelDecls && !Actions.getASTContext().getExternalSource() &&
- !getLangOpts().CPlusPlus)
+ !getLangOpts().CPlusPlus && !getLangOpts().IsHeaderFile)
Diag(diag::ext_empty_translation_unit);
return NoTopLevelDecls;
@@ -750,6 +783,9 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
case tok::annot_pragma_fenv_access:
HandlePragmaFEnvAccess();
return nullptr;
+ case tok::annot_pragma_fenv_round:
+ HandlePragmaFEnvRound();
+ return nullptr;
case tok::annot_pragma_float_control:
HandlePragmaFloatControl();
return nullptr;
@@ -865,7 +901,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
// A function definition cannot start with any of these keywords.
{
SourceLocation DeclEnd;
- return ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs);
+ return ParseDeclaration(DeclaratorContext::File, DeclEnd, attrs);
}
case tok::kw_static:
@@ -875,7 +911,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
<< 0;
SourceLocation DeclEnd;
- return ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs);
+ return ParseDeclaration(DeclaratorContext::File, DeclEnd, attrs);
}
goto dont_know;
@@ -886,7 +922,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
// Inline namespaces. Allowed as an extension even in C++03.
if (NextKind == tok::kw_namespace) {
SourceLocation DeclEnd;
- return ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs);
+ return ParseDeclaration(DeclaratorContext::File, DeclEnd, attrs);
}
// Parse (then ignore) 'inline' prior to a template instantiation. This is
@@ -895,7 +931,7 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
<< 1;
SourceLocation DeclEnd;
- return ParseDeclaration(DeclaratorContext::FileContext, DeclEnd, attrs);
+ return ParseDeclaration(DeclaratorContext::File, DeclEnd, attrs);
}
}
goto dont_know;
@@ -909,9 +945,8 @@ Parser::ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
diag::warn_cxx98_compat_extern_template :
diag::ext_extern_template) << SourceRange(ExternLoc, TemplateLoc);
SourceLocation DeclEnd;
- return Actions.ConvertDeclToDeclGroup(
- ParseExplicitInstantiation(DeclaratorContext::FileContext, ExternLoc,
- TemplateLoc, DeclEnd, attrs));
+ return Actions.ConvertDeclToDeclGroup(ParseExplicitInstantiation(
+ DeclaratorContext::File, ExternLoc, TemplateLoc, DeclEnd, attrs));
}
goto dont_know;
@@ -1092,11 +1127,11 @@ Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
if (getLangOpts().CPlusPlus && isTokenStringLiteral() &&
DS.getStorageClassSpec() == DeclSpec::SCS_extern &&
DS.getParsedSpecifiers() == DeclSpec::PQ_StorageClassSpecifier) {
- Decl *TheDecl = ParseLinkage(DS, DeclaratorContext::FileContext);
+ Decl *TheDecl = ParseLinkage(DS, DeclaratorContext::File);
return Actions.ConvertDeclToDeclGroup(TheDecl);
}
- return ParseDeclGroup(DS, DeclaratorContext::FileContext);
+ return ParseDeclGroup(DS, DeclaratorContext::File);
}
Parser::DeclGroupPtrTy
@@ -1193,7 +1228,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
Scope::CompoundStmtScope);
Scope *ParentScope = getCurScope()->getParent();
- D.setFunctionDefinitionKind(FDK_Definition);
+ D.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
Decl *DP = Actions.HandleDeclarator(ParentScope, D,
TemplateParameterLists);
D.complete(DP);
@@ -1224,7 +1259,7 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D,
Scope::CompoundStmtScope);
Scope *ParentScope = getCurScope()->getParent();
- D.setFunctionDefinitionKind(FDK_Definition);
+ D.setFunctionDefinitionKind(FunctionDefinitionKind::Definition);
Decl *FuncDecl = Actions.HandleDeclarator(ParentScope, D,
MultiTemplateParamsArg());
D.complete(FuncDecl);
@@ -1405,7 +1440,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
}
// Parse the first declarator attached to this declspec.
- Declarator ParmDeclarator(DS, DeclaratorContext::KNRTypeListContext);
+ Declarator ParmDeclarator(DS, DeclaratorContext::KNRTypeList);
ParseDeclarator(ParmDeclarator);
// Handle the full declarator list.
@@ -1691,9 +1726,8 @@ Parser::TryAnnotateName(CorrectionCandidateCallback *CCC) {
return ANK_Success;
}
- case Sema::NC_ContextIndependentExpr:
- Tok.setKind(Actions.isUnevaluatedContext() ? tok::annot_uneval_primary_expr
- : tok::annot_primary_expr);
+ case Sema::NC_OverloadSet:
+ Tok.setKind(tok::annot_overload_set);
setExprAnnotation(Tok, Classification.getExpression());
Tok.setAnnotationEndLoc(NameLoc);
if (SS.isNotEmpty())