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

Amy Huang via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 10:44:21 PST 2023


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

>From e24ee9cbc51d0f372c30512ce5722b2bc32e20d0 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 1/2] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..ad95a61d7587264 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,11 +193,20 @@ 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; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

>From c75681d0817bed88773635eb6b91eb483db29a50 Mon Sep 17 00:00:00 2001
From: Amy Huang <akhuang at google.com>
Date: Tue, 7 Nov 2023 14:51:06 -0800
Subject: [PATCH 2/2] clang-format

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

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index ad95a61d7587264..06c213267c7ef5d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -200,13 +200,13 @@ bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
   // function just returns true.
   bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
                      K != NoSemaHandlerAttribute;
-  bool TargetSpecificSpellingExists = !HasSpelling ||
-    getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+  bool TargetSpecificSpellingExists =
+      !HasSpelling ||
+      getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
 
   return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
-
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {



More information about the cfe-commits mailing list