From patchwork Thu Aug 20 23:10:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1348686 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=8.43.85.97; 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=YZRZ7v1w; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4BXgPN5rbyz9sTF for ; Fri, 21 Aug 2020 09:11:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFD483861881; Thu, 20 Aug 2020 23:10:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFD483861881 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597965059; bh=DwxizE4F0tDbUtgnzBUhkshMrbkLqPHxkJ+bqY4sqXQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YZRZ7v1woyvM4tTJlG0MLtmz+Yrzn8dQKR254QkhllX2MS2dESpcCOk7mdyNkCpXl 6FFUWCpQzgLM0uuwsel1G884738ckJXJPJ4yjXNpiKR/0EekRvSASuNp97tsGb3JOL nYGCZCVg5k9oZqwzBz+jVuKwAdyaahJuZ3dtgblw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050::465:202]) by sourceware.org (Postfix) with ESMTPS id 24C3F3861027 for ; Thu, 20 Aug 2020 23:10:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 24C3F3861027 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4BXgPC5P3KzQlFd; Fri, 21 Aug 2020 01:10:55 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id SWfHlPgXG5Qn; Fri, 21 Aug 2020 01:10:52 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Merge upstream dmd 1b5a53d01. Date: Fri, 21 Aug 2020 01:10:50 +0200 Message-Id: <20200820231050.3544677-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 1.26 / 15.00 / 15.00 X-Rspamd-Queue-Id: AA1D4271 X-Rspamd-UID: 74d4f2 X-Spam-Status: No, score=-15.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 in setValue at dmd/dinterpret.c:7046 This was originally seen when running the testsuite for a 16-bit target, however, it could be reproduced on 32-bit using long[] as well. Regstrapped on x86_64-linux-gnu/-m32/-mx32, committed to mainline and backported to gcc-10 branch. Regards Iain. --- gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd 1b5a53d01. --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/ctfeexpr.c | 2 +- gcc/d/dmd/dinterpret.c | 9 ----- .../gdc.test/compilable/interpret3.d | 38 +++++++++++++++++++ .../gdc.test/fail_compilation/reg6769.d | 29 ++++++++++++++ 5 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gdc.test/fail_compilation/reg6769.d diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index daa3e565ff7..d0e5f442247 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -c2274e56a3220ea636c6199fd06cd54fcdf6bad9 +1b5a53d01c465109ce47edf49ace6143b69b118b 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/ctfeexpr.c b/gcc/d/dmd/ctfeexpr.c index 5230647e626..ee38033ac82 100644 --- a/gcc/d/dmd/ctfeexpr.c +++ b/gcc/d/dmd/ctfeexpr.c @@ -1913,7 +1913,7 @@ bool isCtfeValueValid(Expression *newval) // e1 should be a CTFE reference Expression *e1 = ((AddrExp *)newval)->e1; return tb->ty == Tpointer && - ((e1->op == TOKstructliteral && isCtfeValueValid(e1)) || + (((e1->op == TOKstructliteral || e1->op == TOKarrayliteral) && isCtfeValueValid(e1)) || (e1->op == TOKvar) || (e1->op == TOKdotvar && isCtfeReferenceValid(e1)) || (e1->op == TOKindex && isCtfeReferenceValid(e1)) || diff --git a/gcc/d/dmd/dinterpret.c b/gcc/d/dmd/dinterpret.c index dd1105c03bd..74c5b40741f 100644 --- a/gcc/d/dmd/dinterpret.c +++ b/gcc/d/dmd/dinterpret.c @@ -1947,15 +1947,6 @@ public: Type *elemtype = ((TypeArray *)(val->type))->next; d_uns64 elemsize = elemtype->size(); - // It's OK to cast from fixed length to dynamic array, eg &int[3] to int[]* - if (val->type->ty == Tsarray && pointee->ty == Tarray && - elemsize == pointee->nextOf()->size()) - { - new(pue) AddrExp(e->loc, val, e->type); - result = pue->exp(); - return; - } - // It's OK to cast from fixed length to fixed length array, eg &int[n] to int[d]*. if (val->type->ty == Tsarray && pointee->ty == Tsarray && elemsize == pointee->nextOf()->size()) diff --git a/gcc/testsuite/gdc.test/compilable/interpret3.d b/gcc/testsuite/gdc.test/compilable/interpret3.d index 14d1a12c240..6e7304d742e 100644 --- a/gcc/testsuite/gdc.test/compilable/interpret3.d +++ b/gcc/testsuite/gdc.test/compilable/interpret3.d @@ -3235,6 +3235,44 @@ int ctfeSort6250() static assert(ctfeSort6250() == 57); +/**************************************************/ + +long[]* simple6250b(long[]* x) { return x; } + +void swap6250b(long[]* lhs, long[]* rhs) +{ + long[] kk = *lhs; + assert(simple6250b(lhs) == lhs); + lhs = simple6250b(lhs); + assert(kk[0] == 18); + assert((*lhs)[0] == 18); + assert((*rhs)[0] == 19); + *lhs = *rhs; + assert((*lhs)[0] == 19); + *rhs = kk; + assert(*rhs == kk); + assert(kk[0] == 18); + assert((*rhs)[0] == 18); +} + +long ctfeSort6250b() +{ + long[][2] x; + long[3] a = [17, 18, 19]; + x[0] = a[1 .. 2]; + x[1] = a[2 .. $]; + assert(x[0][0] == 18); + assert(x[0][1] == 19); + swap6250b(&x[0], &x[1]); + assert(x[0][0] == 19); + assert(x[1][0] == 18); + a[1] = 57; + assert(x[0][0] == 19); + return x[1][0]; +} + +static assert(ctfeSort6250b() == 57); + /************************************************** 6672 circular references in array **************************************************/ diff --git a/gcc/testsuite/gdc.test/fail_compilation/reg6769.d b/gcc/testsuite/gdc.test/fail_compilation/reg6769.d new file mode 100644 index 00000000000..b11fac925a0 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/reg6769.d @@ -0,0 +1,29 @@ +/* +TEST_OUTPUT +--- +fail_compilation/reg6769.d(14): Error: reinterpreting cast from `int[]` to `int[7]*` is not supported in CTFE +fail_compilation/reg6769.d(27): called from here: `reg6769a([0, 1, 2, 3, 4, 5, 6])` +fail_compilation/reg6769.d(27): while evaluating: `static assert(reg6769a([0, 1, 2, 3, 4, 5, 6]) == 1)` +fail_compilation/reg6769.d(20): Error: reinterpreting cast from `int[7]` to `int[]*` is not supported in CTFE +fail_compilation/reg6769.d(28): called from here: `reg6769b([0, 1, 2, 3, 4, 5, 6])` +fail_compilation/reg6769.d(28): while evaluating: `static assert(reg6769b([0, 1, 2, 3, 4, 5, 6]) == 1)` +--- +*/ +int reg6769a(int[] a) +{ + int[7]* b = cast(int[7]*)&a; + return (*b)[1]; +} + +int reg6769b(int[7] a) +{ + int[]* b = cast(int[]*)&a; + return (*b)[1]; +} + +void main() +{ + // Both should never succeed, run-time would raise a SEGV. + static assert(reg6769a([0,1,2,3,4,5,6]) == 1); + static assert(reg6769b([0,1,2,3,4,5,6]) == 1); +}