Skip to content

Commit 66b876c

Browse files
committed
Pass the source range when diagnosing an unknown attribute
This way, the whole attribute gets highlighted with diagnostics instead of just the scope name in an attribute like [[clang::unknown]].
1 parent d87fd09 commit 66b876c

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,8 @@ void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
15931593
if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
15941594
continue;
15951595
if (AL.getKind() == ParsedAttr::UnknownAttribute)
1596-
Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL;
1596+
Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
1597+
<< AL << AL.getRange();
15971598
else {
15981599
Diag(AL.getLoc(), DiagID) << AL;
15991600
AL.setInvalid();

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,8 @@ bool Sema::CheckAttrNoArgs(const ParsedAttr &Attrs) {
20552055
bool Sema::CheckAttrTarget(const ParsedAttr &AL) {
20562056
// Check whether the attribute is valid on the current target.
20572057
if (!AL.existsInTarget(Context.getTargetInfo())) {
2058-
Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL;
2058+
Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
2059+
<< AL << AL.getRange();
20592060
AL.setInvalid();
20602061
return true;
20612062
}
@@ -7362,7 +7363,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
73627363
AL.isDeclspecAttribute()
73637364
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
73647365
: (unsigned)diag::warn_unknown_attribute_ignored)
7365-
<< AL;
7366+
<< AL << AL.getRange();
73667367
return;
73677368
}
73687369

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,7 @@ Sema::ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange,
26122612
Diag(AL.getLoc(), AL.getKind() == ParsedAttr::UnknownAttribute
26132613
? (unsigned)diag::warn_unknown_attribute_ignored
26142614
: (unsigned)diag::err_base_specifier_attribute)
2615-
<< AL;
2615+
<< AL << AL.getRange();
26162616
}
26172617

26182618
TypeSourceInfo *TInfo = nullptr;

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const ParsedAttr &A,
409409
S.Diag(A.getLoc(), A.isDeclspecAttribute()
410410
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
411411
: (unsigned)diag::warn_unknown_attribute_ignored)
412-
<< A;
412+
<< A << A.getRange();
413413
return nullptr;
414414
case ParsedAttr::AT_FallThrough:
415415
return handleFallThroughAttr(S, St, A, Range);

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8091,7 +8091,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type,
80918091
if (attr.isCXX11Attribute() && TAL == TAL_DeclChunk)
80928092
state.getSema().Diag(attr.getLoc(),
80938093
diag::warn_unknown_attribute_ignored)
8094-
<< attr;
8094+
<< attr << attr.getRange();
80958095
break;
80968096

80978097
case ParsedAttr::IgnoredAttribute:

0 commit comments

Comments
 (0)