Skip to content

Commit 0ba5f6e

Browse files
authored
Fix to attribute plugins reaching an unreachable (#70877)
[0faee97](0faee97) broke attribute plugins. Specifically, it added a call to `getAttributeSpellingListIndex()` in situations that reached an unreachable statement. This patch adds a check before calling that to avoid hitting the unreachable. `clang/test/Frontend/plugin-attribute.cpp` has been broken since [0faee97](0faee97), and this patch fixes it. Bug: [70702](#70702)
1 parent 2404477 commit 0ba5f6e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

clang/lib/Sema/ParsedAttr.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,18 @@ bool ParsedAttr::isTypeAttr() const { return getInfo().IsType; }
193193
bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
194194

195195
bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
196-
return getInfo().existsInTarget(Target) &&
197-
getInfo().spellingExistsInTarget(Target,
198-
getAttributeSpellingListIndex());
196+
Kind K = getParsedKind();
197+
198+
// If the attribute has a target-specific spelling, check that it exists.
199+
// Only call this if the attr is not ignored/unknown. For most targets, this
200+
// function just returns true.
201+
bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
202+
K != NoSemaHandlerAttribute;
203+
bool TargetSpecificSpellingExists =
204+
!HasSpelling ||
205+
getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
206+
207+
return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
199208
}
200209

201210
bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }

0 commit comments

Comments
 (0)