[clang] [clang] [NFC] Split checkAttributesAfterMerging() to multiple functions (PR #115464)
Boaz Brickner via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 8 03:20:12 PST 2024
https://github.com/bricknerb created https://github.com/llvm/llvm-project/pull/115464
None
>From 01200ae10a21ad408b08eda542e759f9d3d76cbb Mon Sep 17 00:00:00 2001
From: Boaz Brickner <brickner at google.com>
Date: Fri, 8 Nov 2024 12:18:21 +0100
Subject: [PATCH] [clang] [NFC] Split checkAttributesAfterMerging() to multiple
functions
---
clang/lib/Sema/SemaDecl.cpp | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c9cd81a48fbe51..2c52f98b1c8f3d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6868,11 +6868,7 @@ void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
}
}
-static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
- // Ensure that an auto decl is deduced otherwise the checks below might cache
- // the wrong linkage.
- assert(S.ParsingInitForAutoVars.count(&ND) == 0);
-
+static void checkWeakAttr(Sema &S, NamedDecl &ND) {
// 'weak' only applies to declarations with external linkage.
if (WeakAttr *Attr = ND.getAttr<WeakAttr>()) {
if (!ND.isExternallyVisible()) {
@@ -6880,13 +6876,18 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
ND.dropAttr<WeakAttr>();
}
}
+}
+
+static void checkWeakRefAttr(Sema &S, NamedDecl &ND) {
if (WeakRefAttr *Attr = ND.getAttr<WeakRefAttr>()) {
if (ND.isExternallyVisible()) {
S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
ND.dropAttrs<WeakRefAttr, AliasAttr>();
}
}
+}
+static void checkAliasAttr(Sema &S, NamedDecl &ND) {
if (auto *VD = dyn_cast<VarDecl>(&ND)) {
if (VD->hasInit()) {
if (const auto *Attr = VD->getAttr<AliasAttr>()) {
@@ -6897,7 +6898,9 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
}
}
}
+}
+static void checkSelectAnyAttr(Sema &S, NamedDecl &ND) {
// 'selectany' only applies to externally visible variable declarations.
// It does not apply to functions.
if (SelectAnyAttr *Attr = ND.getAttr<SelectAnyAttr>()) {
@@ -6907,12 +6910,17 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
ND.dropAttr<SelectAnyAttr>();
}
}
+}
+static void checkHybridPatchableAttr(Sema &S, NamedDecl &ND) {
if (HybridPatchableAttr *Attr = ND.getAttr<HybridPatchableAttr>()) {
if (!ND.isExternallyVisible())
S.Diag(Attr->getLocation(),
diag::warn_attribute_hybrid_patchable_non_extern);
}
+}
+
+static void checkInheritableAttr(Sema &S, NamedDecl &ND) {
if (const InheritableAttr *Attr = getDLLAttr(&ND)) {
auto *VD = dyn_cast<VarDecl>(&ND);
bool IsAnonymousNS = false;
@@ -6937,7 +6945,9 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
ND.setInvalidDecl();
}
}
+}
+static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND) {
// Check the attributes on the function type and function params, if any.
if (const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
// Don't declare this variable in the second operand of the for-statement;
@@ -6989,6 +6999,20 @@ static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
}
}
+static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND) {
+ // Ensure that an auto decl is deduced otherwise the checks below might cache
+ // the wrong linkage.
+ assert(S.ParsingInitForAutoVars.count(&ND) == 0);
+
+ checkWeakAttr(S, ND);
+ checkWeakRefAttr(S, ND);
+ checkAliasAttr(S, ND);
+ checkSelectAnyAttr(S, ND);
+ checkHybridPatchableAttr(S, ND);
+ checkInheritableAttr(S, ND);
+ checkLifetimeBoundAttr(S, ND);
+}
+
static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl,
NamedDecl *NewDecl,
bool IsSpecialization,
More information about the cfe-commits
mailing list