From patchwork Thu Mar 19 15:19:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1258282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ucw.cz Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48jrDw4KQ7z9shr for ; Fri, 20 Mar 2020 02:19:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86CC7387700B; Thu, 19 Mar 2020 15:19:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 65E4C385E828 for ; Thu, 19 Mar 2020 15:19:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 65E4C385E828 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=hubicka@kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 0C4BD2810C4; Thu, 19 Mar 2020 16:19:50 +0100 (CET) Date: Thu, 19 Mar 2020 16:19:50 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Fix inliner ICE on alias with flatten attribute [PR92372] Message-ID: <20200319151949.GF44481@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-23.7 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, inliner ICEs upon trying to flatten alias. This patch fixes the ICE and also adds a warning that flattens on aliases makes no sense. Testing x86_64-linux in progress, intend to commit it after it finishes if there are no complains. gcc/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/92372 * cgraphunit.c (process_function_and_variable_attributes): * ipa-inline.c (ipa_inline): gcc/testsuite/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/92372 * gcc.c-torture/pr92372.c: New test. * gcc.dg/attr-flatten-1.c: New test. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index fd586366bb9..d7ed405bf2c 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -851,6 +851,14 @@ process_function_and_variable_attributes (cgraph_node *first, node = symtab->next_function (node)) { tree decl = node->decl; + + if (node->alias + && lookup_attribute ("flatten", DECL_ATTRIBUTES (decl))) + { + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "%" + " attribute attribute is ignored on aliases"); + } if (DECL_PRESERVE_P (decl)) node->mark_force_output (); else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl))) diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 6b6ba9aa4b6..302ce16a646 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -2634,6 +2634,9 @@ ipa_inline (void) { node = order[i]; if (node->definition + /* Do not try to flatten aliases. These may happen for example when + creating local aliases. */ + && !node->alias && lookup_attribute ("flatten", DECL_ATTRIBUTES (node->decl)) != NULL) order[j--] = order[i]; diff --git a/gcc/testsuite/gcc.c-torture/pr92372.c b/gcc/testsuite/gcc.c-torture/pr92372.c new file mode 100644 index 00000000000..72a13bb16f4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/pr92372.c @@ -0,0 +1,16 @@ +int fn2(int); +int fn3(int); + +__attribute__((flatten)) +int fn1(int p1) +{ + int a = fn2(p1); + return fn3(a); +} +__attribute__((flatten)) +int fn4(int p1) +{ + int j = fn2(p1); + return fn3(j); +} + diff --git a/gcc/testsuite/gcc.dg/attr-flatten-1.c b/gcc/testsuite/gcc.dg/attr-flatten-1.c new file mode 100644 index 00000000000..b2895e1287c --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-flatten-1.c @@ -0,0 +1,18 @@ +/* { dg-require-alias "" } */ +int fn2(int); +int fn3(int); + +__attribute__((flatten)) +int fn1(int p1) +{ + int a = fn2(p1); + return fn3(a); +} +__attribute__((flatten)) +__attribute__((alias("fn1"))) /* { dg-warning "ignored" } */ +int fn4(int p1); +int +test () +{ + return fn4(1); +}