From patchwork Sun Feb 10 09:13:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1039377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-495696-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gdcproject.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43y3Bx1NYxz9s5c for ; Sun, 10 Feb 2019 20:14:12 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=AxzCbLgKHCCXibxvEqz019Lo7LXhSMLMkD2ZzWu5GK0imc mx+WoQ04MBQ5vGfhczCLVzOzysOVea0lE0GC6v8jI+eLP9HzeYwiI1NFfWQKb9m+ JHHSbFa+dwc3qdKRoTyFr4VLh4DV4+s0uahu5GdjKA0J9C7bPaN9HCW+Fp/j8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=DHCdh6rAA4Hm0LDvXkhXTG+hsOc=; b=CxlUH65BULcRefBlN6K3 eq5/H3V/yq7yB/h2AGoSqz3oGrPM4/ONstS87gb+eEunKP+ih82IXz58Fgz69mAa qVmBCcmlhyn6AOldPsAc8qqaFjK4bl/HSKVTFnRLsBNAlpQ/kQoduAPdDchd8R43 +E+TYkzLOiGlcaSV794LLxo= Received: (qmail 17467 invoked by alias); 10 Feb 2019 09:14:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 17443 invoked by uid 89); 10 Feb 2019 09:14:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:Sun, MERGE, holds, Committed X-HELO: mail-qk1-f179.google.com Received: from mail-qk1-f179.google.com (HELO mail-qk1-f179.google.com) (209.85.222.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Feb 2019 09:14:00 +0000 Received: by mail-qk1-f179.google.com with SMTP id y140so4712284qkb.9 for ; Sun, 10 Feb 2019 01:14:00 -0800 (PST) MIME-Version: 1.0 From: Iain Buclaw Date: Sun, 10 Feb 2019 10:13:47 +0100 Message-ID: Subject: [PATCH, PR d/88989] Committed fix for ICE on recursive field initializers To: gcc-patches X-IsSubscribed: yes Hi, This patch merges the D front-end implementation with dmd upstream 39edbe17e. Only includes a backport from a latter version, fixing PR d/88989. Boostrapped and regression tested on x86_64-linux-gnu. Committed to trunk as r268740. diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index c1c6cc145c4..8b377015129 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -e21c07e84bd9668e1c0fc1f45e514c5fd76988e7 +39edbe17e7b5c761d780c9d1d4376a06df7bf3d8 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/dstruct.c b/gcc/d/dmd/dstruct.c index b44d63298e6..d35b005a47d 100644 --- a/gcc/d/dmd/dstruct.c +++ b/gcc/d/dmd/dstruct.c @@ -723,7 +723,14 @@ bool AggregateDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit) else if (vx->_init) { assert(!vx->_init->isVoidInitializer()); - e = vx->getConstInitializer(false); + if (vx->inuse) // https://issues.dlang.org/show_bug.cgi?id=18057 + { + vx->error(loc, "recursive initialization of field"); + errors = true; + e = NULL; + } + else + e = vx->getConstInitializer(false); } else { diff --git a/gcc/testsuite/gdc.test/compilable/interpret3.d b/gcc/testsuite/gdc.test/compilable/interpret3.d index 8e7025c7f59..386743e6ddc 100644 --- a/gcc/testsuite/gdc.test/compilable/interpret3.d +++ b/gcc/testsuite/gdc.test/compilable/interpret3.d @@ -7731,3 +7731,14 @@ bool foo17407() static assert(!foo17407); +/**************************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18057 +// Recursive field initializer causes segfault. + +struct RBNode(T) +{ + RBNode!T *copy = new RBNode!T; +} + +static assert(!__traits(compiles, { alias bug18057 = RBNode!int; })); + diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18057.d b/gcc/testsuite/gdc.test/fail_compilation/fail18057.d new file mode 100644 index 00000000000..5e2bab7f796 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail18057.d @@ -0,0 +1,16 @@ +/** +TEST_OUTPUT: +--- +fail_compilation/fail18057.d(16): Error: template instance RBNode!int `RBNode` is not a template declaration, it is a struct +fail_compilation/fail18057.d(13): Error: variable fail18057.RBNode.copy recursive initialization of field +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=18057 +// Recursive field initializer causes segfault. +struct RBNode +{ + RBNode *copy = new RBNode; +} + +alias bug18057 = RBNode!int; diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d b/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d new file mode 100644 index 00000000000..14abbfd346f --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail18057b.d @@ -0,0 +1,13 @@ +/** +TEST_OUTPUT: +--- +fail_compilation/fail18057b.d(12): Error: variable `fail18057b.Recursive.field` recursive initialization of field +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=18057 +// Recursive field initializer causes segfault. +struct Recursive +{ + int field = Recursive(); +}