[clang] [[clang::always_destroy]] attribute silences warn-exit-time-destructor (PR #86486)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 26 05:36:09 PDT 2024
https://github.com/AaronBallman updated https://github.com/llvm/llvm-project/pull/86486
>From 016152bc21c2625db77d3e31a7123bcf08114133 Mon Sep 17 00:00:00 2001
From: ycdtosa <ycdtosa at gmail.com>
Date: Mon, 25 Mar 2024 10:28:02 +0000
Subject: [PATCH 1/8] add test for [[clang::always-destroy]] attribute
user wants the warning silenced by the attribute
so no warning should be issued
---
clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
clang/test/SemaCXX/warn-exit-time-destructors.cpp | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ee732679417e37..7070ea00cff275 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16202,7 +16202,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
// Emit warning for non-trivial dtor in global scope (a real global,
// class-static, function-static).
- Diag(VD->getLocation(), diag::warn_exit_time_destructor);
+ if (!VD->hasAttr<AlwaysDestroyAttr>())
+ Diag(VD->getLocation(), diag::warn_exit_time_destructor);
// TODO: this should be re-enabled for static locals by !CXAAtExit
if (!VD->isStaticLocal())
diff --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
index 2f14243cb48c47..8bd798c036333e 100644
--- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp
+++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -51,6 +51,11 @@ struct A { ~A(); };
}
namespace test5 {
+struct A { ~A(); };
+[[clang::always_destroy]] A a; // no warning
+}
+
+namespace test6 {
#if __cplusplus >= 202002L
#define CPP20_CONSTEXPR constexpr
#else
@@ -68,3 +73,4 @@ namespace test5 {
T t; // expected-warning {{exit-time destructor}}
#undef CPP20_CONSTEXPR
}
+
>From b9492928df4e9864b664dc99e34d372215e2fab9 Mon Sep 17 00:00:00 2001
From: ycdtosa <ycdtosa at gmail.com>
Date: Mon, 25 Mar 2024 17:53:51 +0000
Subject: [PATCH 2/8] add test for static variable inside a function
---
clang/test/SemaCXX/warn-exit-time-destructors.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/test/SemaCXX/warn-exit-time-destructors.cpp b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
index 8bd798c036333e..55ae37d7368f88 100644
--- a/clang/test/SemaCXX/warn-exit-time-destructors.cpp
+++ b/clang/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -51,8 +51,12 @@ struct A { ~A(); };
}
namespace test5 {
-struct A { ~A(); };
-[[clang::always_destroy]] A a; // no warning
+ struct A { ~A(); };
+ [[clang::always_destroy]] A a; // no warning
+
+ void func() {
+ [[clang::always_destroy]] static A a; // no warning
+ }
}
namespace test6 {
>From 127abc398d4ed059d761e4b70f0c9d14a8ac1c29 Mon Sep 17 00:00:00 2001
From: ycdtosa <ycdtosa at gmail.com>
Date: Mon, 25 Mar 2024 18:05:26 +0000
Subject: [PATCH 3/8] update documentation
---
clang/docs/ReleaseNotes.rst | 4 ++++
clang/include/clang/Basic/AttrDocs.td | 3 +++
2 files changed, 7 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..46e135123aada9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -289,6 +289,10 @@ Improvements to Clang's diagnostics
- Clang now correctly diagnoses no arguments to a variadic macro parameter as a C23/C++20 extension.
Fixes #GH84495.
+- Clang no longer emits the ``exit-time destructor`` warning on static variables explicitly
+ annotated with the ``clang::always_destroy`` attribute.
+ Fixes #GH68686, #GH86486
+
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 9de14f608fd114..968f620dc3738c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6069,6 +6069,9 @@ def AlwaysDestroyDocs : Documentation {
The ``always_destroy`` attribute specifies that a variable with static or thread
storage duration should have its exit-time destructor run. This attribute is the
default unless clang was invoked with -fno-c++-static-destructors.
+
+If a variable is explicity declared with this attribute clang will silence the
+exit-time destructor warning.
}];
}
>From 7f2ac7ddb89ea5eb05ff420b8570cfdd71192fe1 Mon Sep 17 00:00:00 2001
From: ycdtosa <ycdtosa at gmail.com>
Date: Mon, 25 Mar 2024 18:10:42 +0000
Subject: [PATCH 4/8] fix typo
---
clang/include/clang/Basic/AttrDocs.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 968f620dc3738c..cbd8610a9fc767 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6070,7 +6070,7 @@ The ``always_destroy`` attribute specifies that a variable with static or thread
storage duration should have its exit-time destructor run. This attribute is the
default unless clang was invoked with -fno-c++-static-destructors.
-If a variable is explicity declared with this attribute clang will silence the
+If a variable is explicitly declared with this attribute clang will silence the
exit-time destructor warning.
}];
}
>From c94fd729e4d43125049cba0d3be08d1ec71a102e Mon Sep 17 00:00:00 2001
From: ycdtosa <ycdtosa at gmail.com>
Date: Tue, 26 Mar 2024 08:52:01 +0000
Subject: [PATCH 5/8] fix trailing spaces in ReleaseNotes.rst
---
clang/docs/ReleaseNotes.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46e135123aada9..8afe416957f263 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -289,8 +289,8 @@ Improvements to Clang's diagnostics
- Clang now correctly diagnoses no arguments to a variadic macro parameter as a C23/C++20 extension.
Fixes #GH84495.
-- Clang no longer emits the ``exit-time destructor`` warning on static variables explicitly
- annotated with the ``clang::always_destroy`` attribute.
+- Clang no longer emits the ``exit-time destructor`` warning on static variables explicitly
+ annotated with the ``clang::always_destroy`` attribute.
Fixes #GH68686, #GH86486
Improvements to Clang's time-trace
>From 92c1e0e29febfbaf82a415640037b2af093c1ec4 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Tue, 26 Mar 2024 08:32:51 -0400
Subject: [PATCH 6/8] Update clang/docs/ReleaseNotes.rst
---
clang/docs/ReleaseNotes.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8afe416957f263..892086d5196e3d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -289,7 +289,7 @@ Improvements to Clang's diagnostics
- Clang now correctly diagnoses no arguments to a variadic macro parameter as a C23/C++20 extension.
Fixes #GH84495.
-- Clang no longer emits the ``exit-time destructor`` warning on static variables explicitly
+- Clang no longer emits a ``-Wexit-time destructor`` warning on static variables explicitly
annotated with the ``clang::always_destroy`` attribute.
Fixes #GH68686, #GH86486
>From 462f87cb314c9768a5ac3e38a17e6167488c753a Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Tue, 26 Mar 2024 08:32:57 -0400
Subject: [PATCH 7/8] Update clang/include/clang/Basic/AttrDocs.td
---
clang/include/clang/Basic/AttrDocs.td | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index cbd8610a9fc767..7ed161c4882e38 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6070,8 +6070,8 @@ The ``always_destroy`` attribute specifies that a variable with static or thread
storage duration should have its exit-time destructor run. This attribute is the
default unless clang was invoked with -fno-c++-static-destructors.
-If a variable is explicitly declared with this attribute clang will silence the
-exit-time destructor warning.
+If a variable is explicitly declared with this attribute, Clang will silence
+otherwise applicable ``-Wexit-time-destructor`` warnings.
}];
}
>From 60d9a7f701d582cda8de643bef8de62a1553d85d Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Tue, 26 Mar 2024 08:36:01 -0400
Subject: [PATCH 8/8] Update clang/docs/ReleaseNotes.rst
---
clang/docs/ReleaseNotes.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 892086d5196e3d..07dfbea9d0f6d9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -289,7 +289,7 @@ Improvements to Clang's diagnostics
- Clang now correctly diagnoses no arguments to a variadic macro parameter as a C23/C++20 extension.
Fixes #GH84495.
-- Clang no longer emits a ``-Wexit-time destructor`` warning on static variables explicitly
+- Clang no longer emits a ``-Wexit-time destructors`` warning on static variables explicitly
annotated with the ``clang::always_destroy`` attribute.
Fixes #GH68686, #GH86486
More information about the cfe-commits
mailing list