From patchwork Wed Apr 13 07:58:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 52841 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C4C5385741A for ; Wed, 13 Apr 2022 07:58:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C4C5385741A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649836728; bh=Sq19JaBqxlaOCdTGRR2DEgEHpNMSJFe4pz/oWKs567w=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=sXpLDxjvfvNvX+XueLjkbn5FUM6o40Zdht4lAiwk3SchjuCykwHXJd5Fkhy6hF4sI jIcWJnjKsQnLHm8clYHnJEcD2N3YVd4CMHDPb5tsOmVA11QDTkFUo2yfHLf7EtuWsS 89hz+EqCRcmqkh5eqNb9R10wPZuyn1JF48glsdvo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B9F2D3858C27 for ; Wed, 13 Apr 2022 07:58:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9F2D3858C27 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-aI1JT4o9Mbmre6axa23qFA-1; Wed, 13 Apr 2022 03:58:16 -0400 X-MC-Unique: aI1JT4o9Mbmre6axa23qFA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C6CD6802809; Wed, 13 Apr 2022 07:58:15 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83E6040F06A; Wed, 13 Apr 2022 07:58:15 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 23D7wDo03650409 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Apr 2022 09:58:13 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 23D7wBUL3650408; Wed, 13 Apr 2022 09:58:11 +0200 Date: Wed, 13 Apr 2022 09:58:11 +0200 To: Richard Biener , Jeff Law Subject: [PATCH] attribs: Restrict decl_attributes DECL_FUNCTION_SPECIFIC_TARGET changes to targets that care about target attributes/pragmas [PR105234] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following code is rejected e.g. on mips64el-linux (but I think many other targets which don't support target attribute or pragma). The problem is that the change to decl_attributes below is done unconditionally and with just #pragma GCC push_options/pop_options pair we have target_option_default_node NULL, but after popping options target_option_current_node becomes non-NULL and this decl_attribute spot fills in DECL_FUNCTION_SPECIFIC_TARGET of a subset of a functions. Those appearing before push_options/pop_options will have it NULL and as target_option_default_node is also NULL on those targets, the default can_inline_p will refuse to inline any functions defined with NULL DECL_FUNCTION_SPECIFIC_TARGET into any function with non-NULL DECL_FUNCTION_SPECIFIC_TARGET (even when nothing in the options really changed). The following patch restricts that snippet to targets that care (initialize target_option_default_node to non-NULL to the command line options early) which include all targets that actually implement target attribute and/or pragma. Bootstrapped/regtested on x86_64-linux and i686-linux, tested on the testcase with cross-compiler to mips64el-linux, ok for trunk? 2022-04-13 Jakub Jelinek PR target/105234 * attribs.cc (decl_attributes): Don't set DECL_FUNCTION_SPECIFIC_TARGET if target_option_default_node is NULL. * gcc.c-torture/compile/pr105234.c: New test. Jakub --- gcc/attribs.cc.jj 2022-02-04 14:36:53.947620076 +0100 +++ gcc/attribs.cc 2022-04-12 12:52:36.630967329 +0200 @@ -636,15 +636,20 @@ decl_attributes (tree *node, tree attrib && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)) { DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node; - tree cur_tree - = build_target_option_node (&global_options, &global_options_set); - tree old_tree = DECL_FUNCTION_SPECIFIC_TARGET (*node); - if (!old_tree) - old_tree = target_option_default_node; - /* The changes on optimization options can cause the changes in - target options, update it accordingly if it's changed. */ - if (old_tree != cur_tree) - DECL_FUNCTION_SPECIFIC_TARGET (*node) = cur_tree; + /* Don't set DECL_FUNCTION_SPECIFIC_TARGET for targets that don't + support #pragma GCC target or target attribute. */ + if (target_option_default_node) + { + tree cur_tree + = build_target_option_node (&global_options, &global_options_set); + tree old_tree = DECL_FUNCTION_SPECIFIC_TARGET (*node); + if (!old_tree) + old_tree = target_option_default_node; + /* The changes on optimization options can cause the changes in + target options, update it accordingly if it's changed. */ + if (old_tree != cur_tree) + DECL_FUNCTION_SPECIFIC_TARGET (*node) = cur_tree; + } } /* If this is a function and the user used #pragma GCC target, add the --- gcc/testsuite/gcc.c-torture/compile/pr105234.c.jj 2022-04-12 13:07:55.021142913 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr105234.c 2022-04-12 13:07:43.596302442 +0200 @@ -0,0 +1,14 @@ +/* PR target/105234 */ +/* { dg-do compile } */ + +static inline __attribute__((always_inline)) int foo (int x) { return x + 1; } +#pragma GCC push_options +static inline __attribute__((always_inline)) int bar (int x) { return x + 2; } +#pragma GCC pop_options +static inline __attribute__((always_inline)) int baz (int x) { return x + 3; } + +int +qux (void) +{ + return foo (bar (baz (42))); +}