[clang] Fix to attribute plugins reaching an unreachable (PR #70877)
Amy Huang via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 16:53:37 PST 2023
https://github.com/amykhuang updated https://github.com/llvm/llvm-project/pull/70877
>From 8216d6bc5329d4fcb723db14e2c503cb718cb36d 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 2ed7200e8853fb5c2b51f57129d20b359bb54173 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