From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 48A62384AB57; Tue, 23 Apr 2024 06:39:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48A62384AB57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713854388; bh=9lhmva/WGCMgPU+BUQSHhDzO0xTcyqVxAghjB3qMpzs=; h=From:To:Subject:Date:From; b=J70ZfUtC839FBpuP8SnHuSfbPQVMLRd3NIfJkCIHEWxNZOkN4mDpyyiMDPwIIM6+s nGZtKnNYBxBxxMcsRSKNh66bAw9MMBpB1g6cxvLAT/aJhWg2dJRu4ppMO5t49eWYpU WKCasB2MLjQyzM6fTg8VN8XiCJB2GKEzWm67Rq8s= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10086] c++: Copy over DECL_DISREGARD_INLINE_LIMITS flag to inheriting ctors [PR114784] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: cf51fe706ea0219beb5bb85e81606d372ca9635e X-Git-Newrev: aa73eb97a1e3c84564fa71158d09f9c5582c4d2e Message-Id: <20240423063948.48A62384AB57@sourceware.org> Date: Tue, 23 Apr 2024 06:39:48 +0000 (GMT) List-Id: https://gcc.gnu.org/g:aa73eb97a1e3c84564fa71158d09f9c5582c4d2e commit r14-10086-gaa73eb97a1e3c84564fa71158d09f9c5582c4d2e Author: Jakub Jelinek Date: Tue Apr 23 08:36:15 2024 +0200 c++: Copy over DECL_DISREGARD_INLINE_LIMITS flag to inheriting ctors [PR114784] The following testcase is rejected with error: inlining failed in call to 'always_inline' '...': call is unlikely and code size would grow errors. The problem is that starting with the r14-2149 change we try to copy most of the attributes from the inherited to inheriting ctor, but don't copy associated flags that decl_attributes sets. Now, the other clone_attrs user, cp/optimize.cc (maybe_clone_body) copies over DECL_COMDAT (clone) = DECL_COMDAT (fn); DECL_WEAK (clone) = DECL_WEAK (fn); if (DECL_ONE_ONLY (fn)) cgraph_node::get_create (clone)->set_comdat_group (cxx_comdat_group (clone)); DECL_USE_TEMPLATE (clone) = DECL_USE_TEMPLATE (fn); DECL_EXTERNAL (clone) = DECL_EXTERNAL (fn); DECL_INTERFACE_KNOWN (clone) = DECL_INTERFACE_KNOWN (fn); DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn); DECL_VISIBILITY (clone) = DECL_VISIBILITY (fn); DECL_VISIBILITY_SPECIFIED (clone) = DECL_VISIBILITY_SPECIFIED (fn); DECL_DLLIMPORT_P (clone) = DECL_DLLIMPORT_P (fn); DECL_DISREGARD_INLINE_LIMITS (clone) = DECL_DISREGARD_INLINE_LIMITS (fn); The following patch just copies DECL_DISREGARD_INLINE_LIMITS to fix this exact bug, not really sure which other flags should be copied and which shouldn't. Plus there are tons of other flags, some of which might need to be copied too, some of which might not, perhaps in both places, like: DECL_UNINLINABLE, maybe DECL_PRESERVE_P, TREE_USED, maybe DECL_USER_ALIGN/DECL_ALIGN, maybe DECL_WEAK, maybe DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT, DECL_NO_LIMIT_STACK. TREE_READONLY, DECL_PURE_P, TREE_THIS_VOLATILE (for const, pure and noreturn attributes) probably makes no sense, DECL_IS_RETURNS_TWICE neither (returns_twice ctor?). What about TREE_NOTHROW? DECL_FUNCTION_SPECIFIC_OPTIMIZATION, DECL_FUNCTION_SPECIFIC_TARGET... Anyway, another problem is that if inherited_ctor is a TEMPLATE_DECL, as also can be seen in the using D::D; case in the testcase, then DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor)); attempts to copy the attributes from the TEMPLATE_DECL which doesn't have them. The following patch copies them from STRIP_TEMPLATE (inherited_ctor) which does. E.g. DECL_DECLARED_CONSTEXPR_P works fine as the macro itself uses STRIP_TEMPLATE too, but not 100% sure about other macros used on inherited_ctor earlier. 2024-04-23 Jakub Jelinek PR c++/114784 * method.cc (implicitly_declare_fn): Call clone_attrs on DECL_ATTRIBUTES on STRIP_TEMPLATE (inherited_ctor) rather than inherited_ctor. Also copy DECL_DISREGARD_INLINE_LIMITS flag from it. * g++.dg/cpp0x/inh-ctor39.C: New test. Diff: --- gcc/cp/method.cc | 5 ++- gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc index 98c10e6a8b5..08a3d34fb01 100644 --- a/gcc/cp/method.cc +++ b/gcc/cp/method.cc @@ -3307,8 +3307,11 @@ implicitly_declare_fn (special_function_kind kind, tree type, /* Copy constexpr from the inherited constructor even if the inheriting constructor doesn't satisfy the requirements. */ constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor); + tree inherited_ctor_fn = STRIP_TEMPLATE (inherited_ctor); /* Also copy any attributes. */ - DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor)); + DECL_ATTRIBUTES (fn) = clone_attrs (DECL_ATTRIBUTES (inherited_ctor_fn)); + DECL_DISREGARD_INLINE_LIMITS (fn) + = DECL_DISREGARD_INLINE_LIMITS (inherited_ctor_fn); } /* Add the "this" parameter. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C new file mode 100644 index 00000000000..89c0d8d87a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C @@ -0,0 +1,55 @@ +// PR c++/114784 +// { dg-do compile { target c++11 } } +// { dg-additional-options "-O2" } + +template +struct A { + [[gnu::always_inline]] A (int t) { foo ().bar (t, {}); } + [[gnu::always_inline]] A (long long t) { foo ().bar (t, {}); } + T foo (); +}; + +struct B : A { + using A::A; + [[gnu::always_inline]] B (long long v) : A (v) {} + template + void bar (T &&, int); + char b; +}; + +struct C { + C (int v) : a(v) { } + C (long long v) : a(v) { } + B a; +}; + +static C +baz () +{ + C x(0); + C y(0LL); + return 0; +} + +[[gnu::cold]] int +qux () +{ + baz (); + return 0; +} + +template +struct D { + template + [[gnu::always_inline]] D (T) { d = sizeof (T); } + D(); + int d; +}; +template +struct E : D { + using D::D; +}; + +E c = {}; +E d = 1; +E e = 1.0;