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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id E57063858004 for ; Mon, 22 Feb 2021 22:53:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E57063858004 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-tenlMX0uPXCU4FgWcW4oJw-1; Mon, 22 Feb 2021 17:53:30 -0500 X-MC-Unique: tenlMX0uPXCU4FgWcW4oJw-1 Received: by mail-qt1-f199.google.com with SMTP id h13so4855878qti.21 for ; Mon, 22 Feb 2021 14:53:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1PW8SlFjH6kypzU7AYe/FxWql5EF76/mgthogKd51XU=; b=uMV2DVXBn3oz+B/nZ4EVnM3TzJ5IVau5FGTmGK4Y8r4uKZ4KTTTMRWcXAtU5lCSvUf E1iQY3nFeqXgSK6sIl1QH0HJIu2TX/p0kA2AW3LJE/uvLR/gqm27+FQznTD2GTPi0Ig9 EgAykUju6IJlxpvFVZuppkChVu/JNMXMpmdJGDHdj+SqhU9O1Zv+lxsjcpBsrz+mKE2z MTdQ5J1hTkhDUNn1/2mZW0O4Nkg/5hC3RQsNqfmIff97+WZfTyS+ndxIAlAMttkhNFY+ VBhn81SVx6Z/lmeVMaeQqIk0taXstxNLmfQE46r5Ko66LL8WUGYAVctLOvU7k6IMFf4S JTRA== X-Gm-Message-State: AOAM531TNQm5csqBEoCH+NZ0LD1zsgTWO7Pm8qLruRwFoykVOl1TtfyT n7XBbTP0/4OYpYhBOaly+UT114ale4331nlNEde/Ka1TgD5cdpdGo8sVBYadsBh1zdvOTPjMfAj bpgRJWgoibwcXNe2RzEQEF5EZr5EG/7j6m3codudHTyQ2m54XJq+IAQC5yaoAkkzCUQ== X-Received: by 2002:aed:3926:: with SMTP id l35mr22525328qte.340.1614034409784; Mon, 22 Feb 2021 14:53:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRWpibzGPUV3S+4paijTpXQHFXMDr6oB+aFnTfVHoe8JA8DqCVSazsv4YLdEfMbgxJGZMLzA== X-Received: by 2002:aed:3926:: with SMTP id l35mr22525310qte.340.1614034409366; Mon, 22 Feb 2021 14:53:29 -0800 (PST) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id c143sm13445260qkg.83.2021.02.22.14.53.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Feb 2021 14:53:28 -0800 (PST) Subject: Re: [PATCH] C++: target attribute - local decl To: =?UTF-8?Q?Martin_Li=c5=a1ka?= , gcc-patches@gcc.gnu.org References: <15035626-d39b-cb2a-f9b6-272503b16ba5@suse.cz> From: Jason Merrill Message-ID: <43c9c10d-077a-633d-92d4-d769c5838e6f@redhat.com> Date: Mon, 22 Feb 2021 17:53:27 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <15035626-d39b-cb2a-f9b6-272503b16ba5@suse.cz> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Feb 2021 22:53:34 -0000 On 2/18/21 7:15 AM, Martin Liška wrote: > We crash when target attribute get_function_versions_dispatcher is called > for a function that is not registered in call graph. This fixes that > by emitting a new error. > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? > Thanks, > Martin > > gcc/cp/ChangeLog: > >     PR c++/99108 >     * call.c (get_function_version_dispatcher): Do not parse >     target attribute for a function with a missing declaration. > > gcc/testsuite/ChangeLog: > >     PR c++/99108 >     * g++.target/i386/pr99108.C: New test. > --- >  gcc/cp/call.c                           |  8 +++++++- >  gcc/testsuite/g++.target/i386/pr99108.C | 18 ++++++++++++++++++ >  2 files changed, 25 insertions(+), 1 deletion(-) >  create mode 100644 gcc/testsuite/g++.target/i386/pr99108.C > > diff --git a/gcc/cp/call.c b/gcc/cp/call.c > index 186feef6fe3..844853e504e 100644 > --- a/gcc/cp/call.c > +++ b/gcc/cp/call.c > @@ -8386,8 +8386,14 @@ get_function_version_dispatcher (tree fn) >            && DECL_FUNCTION_VERSIONED (fn)); > >    gcc_assert (targetm.get_function_versions_dispatcher); > -  dispatcher_decl = targetm.get_function_versions_dispatcher (fn); > +  if (cgraph_node::get (fn) == NULL) > +    { > +      error_at (DECL_SOURCE_LOCATION (fn), "missing declaration " > +        "for a multiversioned function"); This seems like the wrong message. The declaration isn't missing, you're using its source location for the error. Do you mean "definition"? But adding definitions earlier in the file doesn't help. And having file-scope declarations without definitions is fine. The problem seems to be with the handling of local decls. If DECL_LOCAL_DECL_P, you need to look at DECL_LOCAL_DECL_ALIAS to find the namespace-scope decl. But then if there is no preceding namespace-scope declaration, the new decl created by push_local_extern_decl_alias doesn't have a cgraph node, either. I guess maybe_function_versions also needs to look through DECL_LOCAL_DECL_ALIAS. > +      return NULL; > +    } > > +  dispatcher_decl = targetm.get_function_versions_dispatcher (fn); >    if (dispatcher_decl == NULL) >      { >        error_at (input_location, "use of multiversioned function " > diff --git a/gcc/testsuite/g++.target/i386/pr99108.C > b/gcc/testsuite/g++.target/i386/pr99108.C > new file mode 100644 > index 00000000000..b0c4ffa2688 > --- /dev/null > +++ b/gcc/testsuite/g++.target/i386/pr99108.C > @@ -0,0 +1,18 @@ > +/* PR c++/99108 */ > +/* { dg-do compile { target c++20 } } */ > +/* { dg-require-ifunc "" }  */ > + > +struct A { > +  void foo(auto); > +}; > +void A::foo(auto) > +{ > +  int f(void) __attribute__((target("default"))); > +  int f(void) __attribute__((target("arch=atom"))); /* { dg-error > "missing declaration for a multiversioned function" } */ > +  int b = f(); > +} > +void bar(void) > +{ > +  A c; > +  c.foo(7); > +}