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 5181D3858D35 for ; Tue, 23 Apr 2024 03:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5181D3858D35 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 5181D3858D35 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=1713841467; cv=none; b=sbXujvgeMyBdA9y2GOb7xIc6LDjbooon/fPgV4zg6RHtzE6xBrfVEqs6FqWAgb/DWmKmQEn4qmksZKtdExgUm3XeWnExov1tBuv44vWMQBfwQIh+vXKcE+VtPFQGFHbPvU67lmscLcVfStoBALkWyUyuyM6d1WmOMnqVwov6JZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713841467; c=relaxed/simple; bh=LBHASb7jyyi6S4BJOzIgcdWR/gVzidU23Hm0yzvaFaA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=LEGov1QCofRStpZhvpHnnELfLRihElZFfIaY4kyBAXR55oFoX74q2bI2vZRSlJhh4ecHuMMX32huUN2zevOVTsPJ1+SiBidqeCtfCegB8rH6zl44TP7NN9EOz/XzWcYULFa2P8phxDCYL8cbJPyprRMfJvjGJoo5TlNhvQDfHo4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713841465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CXTXpoHyofizRRC9GyPzKjAzKHxn5JXiZUkuHFpjpmw=; b=fRDnpikS5VbLXPQpvIpr0QjcR3UgcMiEIYiik3H959KkY64czqe6H1K/gWEpR4Tsx4afGl 9kvkFcORt8htLsKRjPy2LjcxjJ54lFYiNWR2ur1zntmbolA/QQG8fDvSYXrgGxhCKkp5ab jDkiPR4dIOzuo3ryp4H4J6z0Kv9ds1I= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-MBkO_fAaPOa64ELMtiAjtg-1; Mon, 22 Apr 2024 23:04:21 -0400 X-MC-Unique: MBkO_fAaPOa64ELMtiAjtg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6993c176044so127806256d6.0 for ; Mon, 22 Apr 2024 20:04:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713841461; x=1714446261; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CXTXpoHyofizRRC9GyPzKjAzKHxn5JXiZUkuHFpjpmw=; b=tzHmmoJ7hxs1F7UWQpSGrG09ZXbY0r5Jh2S/HM+GfB+hEJe3s3ImUbw91WkN6MXUPS K6VJv88A5wUF6ii4fnTbBHCu2OkiWkq4jlVZKXRenWgwkiNnbxicbfWzPedGp0HOPbT8 zYEAtryt/xeKgqgYyqFg2pVrHngHQ1yFv4jyq7uiyxMpnUKrYZeOONyFqLKWQjnZkouK eLThk8pMeW9bYw8UAmkYioi8f17r3rcYnPiHWwXNu5wzJwm86jW+p0I83QSaJRE7ygow YCi05xFrk2SjowHVkF7RMXl2XoDUHtXagChFJgCyHxHMzKb2aV/rQ6VmSPSoph9Z1bEM vvoA== X-Gm-Message-State: AOJu0YxUuq9ksP3U93Bu+5MVEkWEJe8zUirw0OZ+y/FU+YHEg01lX8ai MADavA8KXUpj5BalCcnIcsqVa/+s9GcanaZCEg1RnNEUIUEYB0blhEdZa4OABDc+t7+apufe9nQ ORu4DwmMj/LVbW0guXrxN6XVvfv/0i+LEgJFdASeC/iz3Gq0ki91SOP3E7AleWRI= X-Received: by 2002:a05:6214:1252:b0:69f:8d76:2c12 with SMTP id r18-20020a056214125200b0069f8d762c12mr3127631qvv.17.1713841461132; Mon, 22 Apr 2024 20:04:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcQoPNTCc6UfDFTjVA3zBUA4mk7nLHOAkwjUGK/qtLklgdwSLLl+FEdJmGu62LLtw0mwgFkA== X-Received: by 2002:a05:6214:1252:b0:69f:8d76:2c12 with SMTP id r18-20020a056214125200b0069f8d762c12mr3127613qvv.17.1713841460773; Mon, 22 Apr 2024 20:04:20 -0700 (PDT) Received: from [192.168.1.130] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id ez4-20020ad45904000000b00690c77505bdsm3928429qvb.37.2024.04.22.20.04.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 20:04:20 -0700 (PDT) Message-ID: Date: Mon, 22 Apr 2024 23:04:19 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: Copy over DECL_DISREGARD_INLINE_LIMITS flag to inheriting ctors [PR114784] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.6 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: On 4/22/24 08:54, Jakub Jelinek wrote: > 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? OK. > Do you want to copy other flags (and which ones and in which places), > is that ok to be deferred till stage 1? Most of the others don't seem like they should be copied, but rather determined from the function body as usual. Maybe DECL_FUNCTION_SPECIFIC_TARGET would make sense. Either way, it can wait for 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 >