From patchwork Wed Jul 11 14:22:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 942518 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-481360-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OA2Fuujn"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=golang-org.20150623.gappssmtp.com header.i=@golang-org.20150623.gappssmtp.com header.b="jsvx5A2J"; dkim-atps=neutral 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 41Qh9L6JzHzB4MN for ; Thu, 12 Jul 2018 00:22:29 +1000 (AEST) 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=wMB/3jMJFQrLMlDjmNbZnGerg9k1g4KGJZopAlSa533Hed xkNSOvyZRiwF/2zeo3qipaEqBihzrOltTYcBeUFr4Jcoh+Joz68SCJM+xdzJsCMR yVCRWDxL5Bb5SBVoKGpbrs0eA/B5C0wlxHQsOFXCWfgKhm/20OpWsCcMl4Rxk= 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=hRMKvYZOOD3c3PJG/P6iFAN3ulc=; b=OA2FuujnJDOBomxmyM/5 JSko0gNpcrBlSg8TKEbaem5X80melVMw/c/UJu404fyzTqvtnhG3Sn3PaOaUiNPe 0GdREAukayvfenKcDloiUOOq0gfahBmxs0aOdkTwY2ccwIlQn8VT+o+yCHd5myYu WVEp9bHlu4hl5BrFWHvP1cc= Received: (qmail 34952 invoked by alias); 11 Jul 2018 14:22:22 -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 34943 invoked by uid 89); 11 Jul 2018 14:22:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=flatten, gofrontend, HTo:D*googlegroups.com, expressions.cc X-HELO: mail-lj1-f174.google.com Received: from mail-lj1-f174.google.com (HELO mail-lj1-f174.google.com) (209.85.208.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 14:22:20 +0000 Received: by mail-lj1-f174.google.com with SMTP id q5-v6so19529426ljh.12 for ; Wed, 11 Jul 2018 07:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=nu+K03pdVQOlcYKqxxyPOyy9u2s0Y2t1Qqajripuqnk=; b=jsvx5A2Jnx5WZNAYw3pWs1ziKZQgYuv/LWiUmsoyfdQAR19L7ILwoYc00fDtQK/cm1 1Gh/xX4sMC+rKxWjiPB61Yamja7LlFOoLAUxWGBqHxKB0QBPcAe7Fk1ULfS6HQ2QhoPU Ww2m+mxoRngM5I3PjleaEqSM9DT6eTVCA25Doqhym7j04R+3wNpyW3no/CgD8/PxFwLI uuELrpbxvdn+mlVtaghlYVQi5namR1xa2Maw/iSLQ4YJ9bb7302AYy5jJSbKDla8muYx 3QANc9GHi9I1Drug94SThDwq3DwaAhMp0W0bjlBe5h290LLtY340Vx/0VJFbTS/iaduH F0bw== MIME-Version: 1.0 Received: by 2002:ab3:1d07:0:0:0:0:0 with HTTP; Wed, 11 Jul 2018 07:22:17 -0700 (PDT) From: Ian Lance Taylor Date: Wed, 11 Jul 2018 07:22:17 -0700 Message-ID: Subject: Go patch committed: Fix evaluation order of LHS index expressions To: gcc-patches , gofrontend-dev@googlegroups.com The Go spec says that when an index expression appears on the left hand side of an assignment, the operands should be evaluated. The gofrontend code was assuming that that only referred to the index operand. But discussion of https://golang.org/issue/23188 has clarified that this means both the slice/map/string operand and the index operand. This patch adjusts the gofrontend code accordingly, fixing the issue. The test case for this is in https://golang.org/cl/123115. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 262540) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -8ad67a72a4fa59efffc891e73ecf10020e3c565d +ea7ac7784791dca517b6681a02c39c11bf136755 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 262540) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -10898,6 +10898,20 @@ Array_index_expression::do_check_types(G } } +// The subexpressions of an array index must be evaluated in order. +// If this is indexing into an array, rather than a slice, then only +// the index should be evaluated. Since this is called for values on +// the left hand side of an assigment, evaluating the array, meaning +// copying the array, will cause a different array to be modified. + +bool +Array_index_expression::do_must_eval_subexpressions_in_order( + int* skip) const +{ + *skip = this->array_->type()->is_slice_type() ? 0 : 1; + return true; +} + // Flatten array indexing by using temporary variables for slices and indexes. Expression* Index: gcc/go/gofrontend/expressions.h =================================================================== --- gcc/go/gofrontend/expressions.h (revision 262540) +++ gcc/go/gofrontend/expressions.h (working copy) @@ -2771,12 +2771,10 @@ class Index_expression : public Parser_e this->location()); } + // This shouldn't be called--we don't know yet. bool - do_must_eval_subexpressions_in_order(int* skip) const - { - *skip = 1; - return true; - } + do_must_eval_subexpressions_in_order(int*) const + { go_unreachable(); } void do_dump_expression(Ast_dump_context*) const; @@ -2882,11 +2880,7 @@ class Array_index_expression : public Ex } bool - do_must_eval_subexpressions_in_order(int* skip) const - { - *skip = 1; - return true; - } + do_must_eval_subexpressions_in_order(int* skip) const; bool do_is_addressable() const; @@ -2965,11 +2959,8 @@ class String_index_expression : public E } bool - do_must_eval_subexpressions_in_order(int* skip) const - { - *skip = 1; - return true; - } + do_must_eval_subexpressions_in_order(int*) const + { return true; } Bexpression* do_get_backend(Translate_context*); @@ -3052,11 +3043,8 @@ class Map_index_expression : public Expr } bool - do_must_eval_subexpressions_in_order(int* skip) const - { - *skip = 1; - return true; - } + do_must_eval_subexpressions_in_order(int*) const + { return true; } // A map index expression is an lvalue but it is not addressable.