Author: Amy Huang Date: 2023-11-20T11:14:40-08:00 New Revision: 0ba5f6e6bd971d74c530e50587c69489e625ce8e
URL: https://github.com/llvm/llvm-project/commit/0ba5f6e6bd971d74c530e50587c69489e625ce8e DIFF: https://github.com/llvm/llvm-project/commit/0ba5f6e6bd971d74c530e50587c69489e625ce8e.diff LOG: Fix to attribute plugins reaching an unreachable (#70877) [0faee97](https://github.com/llvm/llvm-project/commit/0faee97a924adec76d5c7cd680c289ced51e6b5a) 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](https://github.com/llvm/llvm-project/commit/0faee97a924adec76d5c7cd680c289ced51e6b5a), and this patch fixes it. Bug: [70702](https://github.com/llvm/llvm-project/issues/70702) Added: Modified: clang/lib/Sema/ParsedAttr.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index f59b01efe7ed8f4..06c213267c7ef5d 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -193,9 +193,18 @@ bool ParsedAttr::isTypeAttr() const { return getInfo().IsType; } bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; } bool ParsedAttr::existsInTarget(const TargetInfo &Target) const { - return getInfo().existsInTarget(Target) && - getInfo().spellingExistsInTarget(Target, - getAttributeSpellingListIndex()); + Kind K = getParsedKind(); + + // If the attribute has a target-specific spelling, check that it exists. + // Only call this if the attr is not ignored/unknown. For most targets, this + // function just returns true. + bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute && + K != NoSemaHandlerAttribute; + bool TargetSpecificSpellingExists = + !HasSpelling || + getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex()); + + return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists; } bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits