Hi! 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. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2025-03-28 Jakub Jelinek <ja...@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. --- gcc/cp/decl.cc.jj 2025-03-27 19:13:58.000000000 +0100 +++ gcc/cp/decl.cc 2025-03-28 16:41:18.054543572 +0100 @@ -19452,7 +19452,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: --- gcc/testsuite/g++.dg/opt/pr119518.C.jj 2025-03-28 16:53:37.226583530 +0100 +++ gcc/testsuite/g++.dg/opt/pr119518.C 2025-03-28 16:54:58.663485368 +0100 @@ -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 (); +} Jakub