diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -92,11 +92,9 @@ const Decl *D) const { return true; } - /// Check if this attribute is allowed by the language we are compiling, and - /// issue a diagnostic if not. - virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const { - return true; - } + /// Check if this attribute is allowed by the language we are compiling. + virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; } + /// Check if this attribute is allowed when compiling for the given target. virtual bool existsInTarget(const TargetInfo &Target) const { return true; diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -180,7 +180,10 @@ } bool ParsedAttr::diagnoseLangOpts(Sema &S) const { - return getInfo().diagLangOpts(S, *this); + if (getInfo().acceptsLangOpts(S.getLangOpts())) + return true; + S.Diag(getLoc(), diag::warn_attribute_ignored) << *this; + return false; } bool ParsedAttr::isTargetSpecificAttr() const { diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -3803,14 +3803,8 @@ if (LangOpts.empty()) return; - OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) "; - OS << "const override {\n"; - OS << " auto &LangOpts = S.LangOpts;\n"; - OS << " if (" << GenerateTestExpression(LangOpts) << ")\n"; - OS << " return true;\n\n"; - OS << " S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) "; - OS << "<< Attr;\n"; - OS << " return false;\n"; + OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n"; + OS << " return " << GenerateTestExpression(LangOpts) << ";\n"; OS << "}\n\n"; }