From patchwork Wed Aug 26 08:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1351703 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=OOMuPpsT; 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 4BbzFV1Z8Kz9sTR for ; Wed, 26 Aug 2020 18:15:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4317A386184A; Wed, 26 Aug 2020 08:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4317A386184A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598429740; bh=ZxF2BazaxcJj4r2oUztBT3GkRqDrh1EeZJXGKjHLUN0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OOMuPpsTsnLzL2dU+zN/RpAUF0L0St9qYoDDyaestfyGdh5NBUALxee0Gg03nzasy SRZv4WPAmxr5R3882jwo9UK79kMcNwpQDON2jCQUuwr4OOCSLxrDJTG/2vfj4TLshz l/oUGfj/+sIxLLi9S+Dw+ZwTQw/HkN7krwMv85KY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id 76063386182E for ; Wed, 26 Aug 2020 08:15:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 76063386182E 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-102.mailbox.org (Postfix) with ESMTPS id 4BbzFN2DBzzKmT4; Wed, 26 Aug 2020 10:15:36 +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 Whywst91mor0; Wed, 26 Aug 2020 10:15:32 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Merge upstream dmd e49192807 Date: Wed, 26 Aug 2020 10:15:31 +0200 Message-Id: <20200826081531.451358-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.44 / 15.00 / 15.00 X-Rspamd-Queue-Id: F045017A1 X-Rspamd-UID: c0583e X-Spam-Status: No, score=-15.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, 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 merges the D front-end implementation with upstream dmd e49192807. 1. Removes prelude assert for constructors and destructors. To trigger these asserts one needed to construct or destruct an aggregate at the null memory location. This would crash upon any data member access, which is required for a constructor or destructor to do anything useful. 2. Disables bounds checking in foreach statements, when the array is either a static or dynamic array. If we trust the array `.length' to be correct, then all elements are between `[0 .. length]', and can't can't be out of bounds. Regstrapped on x86_64-linux-gnu/-m32/-mx32, committed to mainline. Regards Iain --- gcc/d/ChangeLog: * dmd/MERGE: Merge upstream dmd e49192807 --- gcc/d/dmd/MERGE | 2 +- gcc/d/dmd/func.c | 82 +++++++++++++++------------------------- gcc/d/dmd/statementsem.c | 4 +- 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index 276406c7696..4676645f971 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -fe5f388d8e5d97dccaa4ef1349f931c36a2cbc46 +e49192807967c6f11252683a731c5a0159ef36da 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/func.c b/gcc/d/dmd/func.c index f8e9601dbec..dbc5fa6352c 100644 --- a/gcc/d/dmd/func.c +++ b/gcc/d/dmd/func.c @@ -30,7 +30,7 @@ #include "visitor.h" #include "objc.h" -Expression *addInvariant(Loc loc, Scope *sc, AggregateDeclaration *ad, VarDeclaration *vthis, bool direct); +Expression *addInvariant(AggregateDeclaration *ad, VarDeclaration *vthis); bool checkReturnEscape(Scope *sc, Expression *e, bool gag); bool checkReturnEscapeRef(Scope *sc, Expression *e, bool gag); bool checkNestedRef(Dsymbol *s, Dsymbol *p); @@ -1648,7 +1648,7 @@ void FuncDeclaration::semantic3(Scope *sc) Statement *fpreinv = NULL; if (addPreInvariant()) { - Expression *e = addInvariant(loc, sc, ad, vthis, isDtorDeclaration() != NULL); + Expression *e = addInvariant(ad, vthis); if (e) fpreinv = new ExpStatement(Loc(), e); } @@ -1657,7 +1657,7 @@ void FuncDeclaration::semantic3(Scope *sc) Statement *fpostinv = NULL; if (addPostInvariant()) { - Expression *e = addInvariant(loc, sc, ad, vthis, isCtorDeclaration() != NULL); + Expression *e = addInvariant(ad, vthis); if (e) fpostinv = new ExpStatement(Loc(), e); } @@ -4154,67 +4154,47 @@ bool FuncDeclaration::addPostInvariant() * Input: * ad aggregate with the invariant * vthis variable with 'this' - * direct call invariant directly * Returns: * void expression that calls the invariant */ -Expression *addInvariant(Loc loc, Scope *sc, AggregateDeclaration *ad, VarDeclaration *vthis, bool direct) +Expression *addInvariant(AggregateDeclaration *ad, VarDeclaration *vthis) { Expression *e = NULL; - if (direct) - { - // Call invariant directly only if it exists - FuncDeclaration *inv = ad->inv; - ClassDeclaration *cd = ad->isClassDeclaration(); - while (!inv && cd) - { - cd = cd->baseClass; - if (!cd) - break; - inv = cd->inv; - } - if (inv) - { - #if 1 - // Workaround for bugzilla 13394: For the correct mangling, - // run attribute inference on inv if needed. - inv->functionSemantic(); - #endif - - //e = new DsymbolExp(Loc(), inv); - //e = new CallExp(Loc(), e); - //e = e->semantic(sc2); - - /* Bugzilla 13113: Currently virtual invariant calls completely - * bypass attribute enforcement. - * Change the behavior of pre-invariant call by following it. - */ - e = new ThisExp(Loc()); - e->type = vthis->type; - e = new DotVarExp(Loc(), e, inv, false); - e->type = inv->type; - e = new CallExp(Loc(), e); - e->type = Type::tvoid; - } + // Call invariant directly only if it exists + FuncDeclaration *inv = ad->inv; + ClassDeclaration *cd = ad->isClassDeclaration(); + + while (!inv && cd) + { + cd = cd->baseClass; + if (!cd) + break; + inv = cd->inv; } - else + if (inv) { #if 1 // Workaround for bugzilla 13394: For the correct mangling, // run attribute inference on inv if needed. - if (ad->isStructDeclaration() && ad->inv) - ad->inv->functionSemantic(); + inv->functionSemantic(); #endif - // Call invariant virtually - Expression *v = new ThisExp(Loc()); - v->type = vthis->type; - if (ad->isStructDeclaration()) - v = v->addressOf(); - e = new StringExp(Loc(), const_cast("null this")); - e = new AssertExp(loc, v, e); - e = semantic(e, sc); + //e = new DsymbolExp(Loc(), inv); + //e = new CallExp(Loc(), e); + //e = e->semantic(sc2); + + /* https://issues.dlang.org/show_bug.cgi?id=13113 + * Currently virtual invariant calls completely + * bypass attribute enforcement. + * Change the behavior of pre-invariant call by following it. + */ + e = new ThisExp(Loc()); + e->type = vthis->type; + e = new DotVarExp(Loc(), e, inv, false); + e->type = inv->type; + e = new CallExp(Loc(), e); + e->type = Type::tvoid; } return e; } diff --git a/gcc/d/dmd/statementsem.c b/gcc/d/dmd/statementsem.c index 90493475fff..42f885d4175 100644 --- a/gcc/d/dmd/statementsem.c +++ b/gcc/d/dmd/statementsem.c @@ -1188,7 +1188,9 @@ public: } // T value = tmp[key]; - fs->value->_init = new ExpInitializer(loc, new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, fs->key))); + IndexExp *indexExp = new IndexExp(loc, new VarExp(loc, tmp), new VarExp(loc, fs->key)); + indexExp->indexIsInBounds = true; // disabling bounds checking in foreach statements. + fs->value->_init = new ExpInitializer(loc, indexExp); Statement *ds = new ExpStatement(loc, fs->value); if (dim == 2)