Skip to content

Commit 3b99acb

Browse files
committed
[Attributes]: refactor to expose ParsedAttrInfo::acceptsLangOpts. NFC
We will use this function to filter code completion of attributes. Differential Revision: https://reviews.llvm.org/D107836
1 parent 08c04ca commit 3b99acb

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ New Pragmas in Clang
8686
Attribute Changes in Clang
8787
--------------------------
8888

89-
- ...
89+
- Attributes loaded as clang plugins which are sensitive to LangOpts must
90+
now override ``acceptsLangOpts`` instead of ``diagLangOpts``.
91+
Returning false will produce a generic "attribute ignored" diagnostic, as
92+
with clang's built-in attributes.
93+
If plugins want to provide richer diagnostics, they can do so when the
94+
attribute is handled instead, e.g. in ``handleDeclAttribute``.
95+
(This was changed in order to better support attributes in code completion).
9096

9197
Windows Support
9298
---------------

clang/include/clang/Sema/ParsedAttr.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ struct ParsedAttrInfo {
9292
const Decl *D) const {
9393
return true;
9494
}
95-
/// Check if this attribute is allowed by the language we are compiling, and
96-
/// issue a diagnostic if not.
97-
virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
98-
return true;
99-
}
95+
/// Check if this attribute is allowed by the language we are compiling.
96+
virtual bool acceptsLangOpts(const LangOptions &LO) const { return true; }
97+
10098
/// Check if this attribute is allowed when compiling for the given target.
10199
virtual bool existsInTarget(const TargetInfo &Target) const {
102100
return true;

clang/lib/Sema/ParsedAttr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ void ParsedAttr::getMatchRules(
180180
}
181181

182182
bool ParsedAttr::diagnoseLangOpts(Sema &S) const {
183-
return getInfo().diagLangOpts(S, *this);
183+
if (getInfo().acceptsLangOpts(S.getLangOpts()))
184+
return true;
185+
S.Diag(getLoc(), diag::warn_attribute_ignored) << *this;
186+
return false;
184187
}
185188

186189
bool ParsedAttr::isTargetSpecificAttr() const {

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3803,14 +3803,8 @@ static void GenerateLangOptRequirements(const Record &R,
38033803
if (LangOpts.empty())
38043804
return;
38053805

3806-
OS << "bool diagLangOpts(Sema &S, const ParsedAttr &Attr) ";
3807-
OS << "const override {\n";
3808-
OS << " auto &LangOpts = S.LangOpts;\n";
3809-
OS << " if (" << GenerateTestExpression(LangOpts) << ")\n";
3810-
OS << " return true;\n\n";
3811-
OS << " S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) ";
3812-
OS << "<< Attr;\n";
3813-
OS << " return false;\n";
3806+
OS << "bool acceptsLangOpts(const LangOptions &LangOpts) const override {\n";
3807+
OS << " return " << GenerateTestExpression(LangOpts) << ";\n";
38143808
OS << "}\n\n";
38153809
}
38163810

0 commit comments

Comments
 (0)