aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-04-23 08:36:15 +0200
committerJakub Jelinek <jakub@redhat.com>2024-04-23 08:36:15 +0200
commitaa73eb97a1e3c84564fa71158d09f9c5582c4d2e (patch)
treee3114bb689d13805a91b1d115c90d8c3930bde48
parentcf51fe706ea0219beb5bb85e81606d372ca9635e (diff)
downloadgcc-aa73eb97a1e3c84564fa71158d09f9c5582c4d2e.zip
gcc-aa73eb97a1e3c84564fa71158d09f9c5582c4d2e.tar.gz
gcc-aa73eb97a1e3c84564fa71158d09f9c5582c4d2e.tar.bz2
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<T>::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 <jakub@redhat.com> 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.
-rw-r--r--gcc/cp/method.cc5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C55
2 files changed, 59 insertions, 1 deletions
diff --git a/gcc/cp/method.cc b/gcc/cp/method.cc
index 98c10e6..08a3d34 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 0000000..89c0d8d
--- /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 <typename T>
+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<B> {
+ using A<B>::A;
+ [[gnu::always_inline]] B (long long v) : A (v) {}
+ template <typename T>
+ 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 <typename>
+struct D {
+ template <typename T>
+ [[gnu::always_inline]] D (T) { d = sizeof (T); }
+ D();
+ int d;
+};
+template <typename T>
+struct E : D<T> {
+ using D<T>::D;
+};
+
+E<char> c = {};
+E<char> d = 1;
+E<char> e = 1.0;