From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6F4273858D35 for ; Mon, 22 Apr 2024 15:54:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F4273858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F4273858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713801251; cv=none; b=FXKjdhZ87Is2XYTlbN7dZsH0pfMmuy8cCaoREifgus1i63C9saChV2yPcN0cMDsS51RX2b5UrLKG00OZ91SKAo8K15nagz4uVoZJrTxXJD1UjnAJIp2Udp2C+vOZllFUkPOSbj0xTAI042nxcKqyCUrCJOoJQFdmq9aY2rooqRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713801251; c=relaxed/simple; bh=422dZgw252WX80A5PD/59U103ti7yYIf4udpQRRgi/4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xun65EyUUbWCZcI26pu/7pAsp0i/ATc128tE7RExO4W8loauuvffvp2ABpodsd1qrc6XsemXUnL4okYtUr0bMCAzYehUkOTxJso8EGvJptTL8Eiv9tOtOaoH3R89GGXCiaC+GoV/5uNSj8i1suEcDJwxGNZAqJDYIq6E2cx9Bfg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713801248; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=KgdjzdVy5n1NkmpNgN9iqLe+hSbUxGdAcn0dWYyuzI8=; b=FI3ed42r0pK68uIMf6DGeqSWKD/nW1aWw7JAXq+yK/vO+d5iJtHqe9FSQ6NHSrFGendja+ 6WtnE2EjJTvlOLXFx0xDpOx+7TU7lPhPiMWe/tLGEliwzDugBXa0VvhrQBba6WpnVhSJ6x X8AVOL0Lco1H/xcXR63SYDKVUUrXlfg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-5-KWDJD6OTmyTpYO9JEIEQ-1; Mon, 22 Apr 2024 11:54:07 -0400 X-MC-Unique: 5-KWDJD6OTmyTpYO9JEIEQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9B843C0EAC7 for ; Mon, 22 Apr 2024 15:54:06 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A57B840C5C2; Mon, 22 Apr 2024 15:54:06 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 43MFs5n93663055 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 22 Apr 2024 17:54:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 43MFs4UZ3663054; Mon, 22 Apr 2024 17:54:04 +0200 Date: Mon, 22 Apr 2024 17:54:04 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Copy over DECL_DISREGARD_INLINE_LIMITS flag to inheriting ctors [PR114784] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi! 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. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Do you want to copy other flags (and which ones and in which places), is that ok to be deferred till stage 1? 2024-04-22 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. --- gcc/cp/method.cc.jj 2024-04-20 00:02:56.702387748 +0200 +++ gcc/cp/method.cc 2024-04-22 12:51:36.395722484 +0200 @@ -3307,8 +3307,11 @@ implicitly_declare_fn (special_function_ /* 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. */ --- gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C.jj 2024-04-22 13:02:10.490836357 +0200 +++ gcc/testsuite/g++.dg/cpp0x/inh-ctor39.C 2024-04-22 13:01:50.088122255 +0200 @@ -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; Jakub