From patchwork Tue Aug 18 07:57:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1346690 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=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jDaQRxWS; dkim-atps=neutral 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 4BW3DJ3L03z9sPC for ; Tue, 18 Aug 2020 17:57:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E266393C8CE; Tue, 18 Aug 2020 07:57:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E266393C8CE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597737452; bh=5K5MKrptLR2TWJYqhl0awvDWjVmuHFVMUMdfaZWH42M=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jDaQRxWSdiEAYtmZ6htEV0ne+vcV8eZxd1C00pNfAB4SW0ozL5FI83Do1mSbTjdou uu1+T5cEms2SS9GRULM7zzGGJuznQy+PPnjTwEzGMWJPnhJXJHQl7eOrRN07DIILGX RmBcoMg7gn+J1GC536sZ14Qy3NXRpP0sYryn15NI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050::465:201]) by sourceware.org (Postfix) with ESMTPS id A0AD7393C8C6 for ; Tue, 18 Aug 2020 07:57:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A0AD7393C8C6 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4BW3D65xCgzQlVP; Tue, 18 Aug 2020 09:57:26 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id V0iyOjTlHpQS; Tue, 18 Aug 2020 09:57:23 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Fix ICE Segmentation fault during RTL pass: expand on armhf/armel/s390x Date: Tue, 18 Aug 2020 09:57:21 +0200 Message-Id: <20200818075721.1661853-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.21 / 15.00 / 15.00 X-Rspamd-Queue-Id: 98B8637F X-Rspamd-UID: 45aa42 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch fixes an ICE that occurred when RTL was expanding D front-end generated code. Now DECL_BY_REFERENCE is only ever set if the return type is TREE_ADDRESSABLE. Regstrapped on x86_64-linux-gnu{-m64,-m32,-mx32} configurations, committed to mainline and backported to releases/gcc-10. Regards Iain. --- gcc/d/ChangeLog: PR d/96301 * decl.cc (DeclVisitor::visit (FuncDeclaration *)): Only return non-trivial structs by invisible reference. gcc/testsuite/ChangeLog: PR d/96301 * gdc.dg/pr96301a.d: New test. * gdc.dg/pr96301b.d: New test. * gdc.dg/pr96301c.d: New test. --- gcc/d/decl.cc | 17 +++++++++++------ gcc/testsuite/gdc.dg/pr96301a.d | 31 +++++++++++++++++++++++++++++++ gcc/testsuite/gdc.dg/pr96301b.d | 25 +++++++++++++++++++++++++ gcc/testsuite/gdc.dg/pr96301c.d | 25 +++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr96301a.d create mode 100644 gcc/testsuite/gdc.dg/pr96301b.d create mode 100644 gcc/testsuite/gdc.dg/pr96301c.d diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 72c8a8cff06..295f780170a 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -958,11 +958,14 @@ public: { tree resdecl = DECL_RESULT (fndecl); - TREE_TYPE (resdecl) - = build_reference_type (TREE_TYPE (resdecl)); - DECL_BY_REFERENCE (resdecl) = 1; - TREE_ADDRESSABLE (resdecl) = 0; - relayout_decl (resdecl); + /* Return non-trivial structs by invisible reference. */ + if (TREE_ADDRESSABLE (TREE_TYPE (resdecl))) + { + TREE_TYPE (resdecl) = build_reference_type (TREE_TYPE (resdecl)); + DECL_BY_REFERENCE (resdecl) = 1; + TREE_ADDRESSABLE (resdecl) = 0; + relayout_decl (resdecl); + } if (d->nrvo_var) { @@ -972,7 +975,9 @@ public: DECL_NAME (resdecl) = DECL_NAME (var); /* Don't forget that we take its address. */ TREE_ADDRESSABLE (var) = 1; - resdecl = build_deref (resdecl); + + if (DECL_BY_REFERENCE (resdecl)) + resdecl = build_deref (resdecl); SET_DECL_VALUE_EXPR (var, resdecl); DECL_HAS_VALUE_EXPR_P (var) = 1; diff --git a/gcc/testsuite/gdc.dg/pr96301a.d b/gcc/testsuite/gdc.dg/pr96301a.d new file mode 100644 index 00000000000..314904bbd06 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301a.d @@ -0,0 +1,31 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301 +// { dg-additional-options "-fPIC" { target fpic } } +// { dg-do compile } +struct Type +{ + size_t length; + int* ptr; +} + +class Container +{ + Type children; + + void remove(void* data) + { + Type remove(Type range) + { + auto result = range; + if (result.front) + return result; + assert(0); + } + if (data) + remove(children); + } +} + +int front(Type a) +{ + return a.ptr[0]; +} diff --git a/gcc/testsuite/gdc.dg/pr96301b.d b/gcc/testsuite/gdc.dg/pr96301b.d new file mode 100644 index 00000000000..3d978beebc8 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301b.d @@ -0,0 +1,25 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301 +// { dg-additional-options "-fPIC" { target fpic } } +// { dg-do compile } +class Container +{ + int[100] children; + + void remove(void* data) + { + int[100] remove(int[100] range) + { + auto result = range; + if (result.front) + return result; + assert(0); + } + if (data) + remove(children); + } +} + +int front(int[100] a) +{ + return a.ptr[0]; +} diff --git a/gcc/testsuite/gdc.dg/pr96301c.d b/gcc/testsuite/gdc.dg/pr96301c.d new file mode 100644 index 00000000000..c9094625016 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96301c.d @@ -0,0 +1,25 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96301 +// { dg-additional-options "-fPIC" { target fpic } } +// { dg-do compile } +class Container +{ + int[] children; + + void remove(void* data) + { + int[] remove(int[] range) + { + auto result = range; + if (result.front) + return result; + assert(0); + } + if (data) + remove(children); + } +} + +int front(int[] a) +{ + return a.ptr[0]; +}