[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

Amy Huang via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 31 17:05:12 PDT 2023


https://github.com/amykhuang created https://github.com/llvm/llvm-project/pull/70877

[0faee97](https://github.com/llvm/llvm-project/commit/0faee97a924adec76d5c7cd680c289ced51e6b5a) made the attribute plugin code hit an unreachable.

Bug: [70702](https://github.com/llvm/llvm-project/issues/70702)

>From bb896fbc4b7303bc0ef524bbff91e95610cb11ce Mon Sep 17 00:00:00 2001
From: Amy Huang <akhuang at google.com>
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..2d6d17e74f6e38d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,9 +193,13 @@ bool ParsedAttr::isTypeAttr() const { return getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
+  Kind K = getParsedKind();
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+                     K != NoSemaHandlerAttribute;
   return getInfo().existsInTarget(Target) &&
-         getInfo().spellingExistsInTarget(Target,
-                                          getAttributeSpellingListIndex());
+         (HasSpelling &&
+          getInfo().spellingExistsInTarget(Target,
+                                          getAttributeSpellingListIndex()));
 }
 
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }



More information about the cfe-commits mailing list