[clang] [Clang] add fix-it hints for unknown attributes (PR #141305)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue May 27 09:35:29 PDT 2025


================
@@ -7867,15 +7867,16 @@ void Sema::checkUnusedDeclAttributes(Declarator &D) {
 
 void Sema::DiagnoseUnknownAttribute(const ParsedAttr &AL) {
   std::string NormalizedFullName = '\'' + AL.getNormalizedFullName() + '\'';
+  SourceRange NR = AL.getNormalizedRange();
+  SourceLocation Loc = NR.getBegin();
+
   if (auto CorrectedFullName =
           AL.getCorrectedFullName(Context.getTargetInfo(), getLangOpts())) {
-    Diag(AL.getNormalizedRange().getBegin(),
-         diag::warn_unknown_attribute_ignored_suggestion)
-        << NormalizedFullName << *CorrectedFullName << AL.getNormalizedRange();
+    Diag(Loc, diag::warn_unknown_attribute_ignored_suggestion)
+        << NormalizedFullName << *CorrectedFullName
+        << FixItHint::CreateReplacement(NR, *CorrectedFullName) << NR;
   } else {
-    Diag(AL.getNormalizedRange().getBegin(),
-         diag::warn_unknown_attribute_ignored)
-        << NormalizedFullName << AL.getNormalizedRange();
+    Diag(Loc, diag::warn_unknown_attribute_ignored) << NormalizedFullName << NR;
----------------
AaronBallman wrote:

The ones I'd look at replacing are:

* `ProhibitCXX11Attributes`
* `ParseCXX11AttributeArgs`
* `checkUnusedDeclAttributes`
* maybe `CheckAttrTarget`?
* `ActOnBaseSpecifier` just looks odd to me; we diagnose an unknown attribute but if we knew about the attribute, we'd diagnose it anyway. Probably something we want to address separately?
* `ProcessStmtAttribute`


https://github.com/llvm/llvm-project/pull/141305


More information about the cfe-commits mailing list