aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2025-03-31 07:51:04 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2025-03-31 07:51:04 +0200
commit94816c640adf33bb25c79b9a0d5a74d35724b650 (patch)
tree4b63021a106a1d4bc13cebbbc2dc684a70bde560 /gcc
parent78aed0ae5de801cc1e8220b214145300b28da562 (diff)
downloadgcc-94816c640adf33bb25c79b9a0d5a74d35724b650.zip
gcc-94816c640adf33bb25c79b9a0d5a74d35724b650.tar.gz
gcc-94816c640adf33bb25c79b9a0d5a74d35724b650.tar.bz2
c++: Honor noipa attribute for FE nothrow discovery [PR119518]
The following testcase has different code generation in bar depending on whether foo is defined or just declared. That is undesirable when it has noipa attribute, that attribute is documented to be a black box between caller and callee, so the caller shouldn't know about any implicitly determined properties of the callee and callee shouldn't know about its callers. E.g. the ipa-pure-const passes including nothrow discovery in there all honor noipa attribute, but the FE did not. 2025-03-31 Jakub Jelinek <jakub@redhat.com> PR c++/119518 * decl.cc (finish_function): Don't set TREE_NOTHROW for functions with "noipa" attribute even when we can prove they can't throw. * g++.dg/opt/pr119518.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/decl.cc3
-rw-r--r--gcc/testsuite/g++.dg/opt/pr119518.C20
2 files changed, 22 insertions, 1 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 7d10b22..2ed94fd 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -19454,7 +19454,8 @@ finish_function (bool inline_p)
&& !cp_function_chain->can_throw
&& !flag_non_call_exceptions
&& !decl_replaceable_p (fndecl,
- opt_for_fn (fndecl, flag_semantic_interposition)))
+ opt_for_fn (fndecl, flag_semantic_interposition))
+ && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
TREE_NOTHROW (fndecl) = 1;
cleanup:
diff --git a/gcc/testsuite/g++.dg/opt/pr119518.C b/gcc/testsuite/g++.dg/opt/pr119518.C
new file mode 100644
index 0000000..152b880
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr119518.C
@@ -0,0 +1,20 @@
+// PR c++/119518
+// { dg-do compile }
+// { dg-options "-O2 -fdump-tree-optimized" }
+// { dg-final { scan-tree-dump "S::~S \\\(&s\\\)" "optimized" } }
+
+[[gnu::noipa, noreturn]] void
+foo ()
+{
+ for (;;)
+ ;
+}
+
+struct S { ~S (); };
+
+void
+bar ()
+{
+ S s;
+ foo ();
+}