From patchwork Mon Nov 30 20:08:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1408466 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=pass (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=Z54cu6vm; 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 4ClGWY6LHXz9sVj for ; Tue, 1 Dec 2020 07:08:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C145F393BC38; Mon, 30 Nov 2020 20:08:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C145F393BC38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606766901; bh=yR8POz0nzRYpE5esF0SbQe7NofvULJT6DYoE8b12n8A=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Z54cu6vmpwaEGIqZWTMFtdaAYDDizRBGh9+r1Iph34NwuoQ/nMvLUgzLmn0JC+QGO w4xBCj70mnf3pYJZtWv/Kiw0kj7y3p2c0ou56zm/99aJy3ADeTZGgwqGlNdZEer4WT vF+0ODeQ+k2X34UCiBuh7aKq6IhLbms0VQIWQfWU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 06A3F393BC07 for ; Mon, 30 Nov 2020 20:08:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 06A3F393BC07 Received: by mail-ej1-x634.google.com with SMTP id s13so8925746ejr.1 for ; Mon, 30 Nov 2020 12:08:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=yR8POz0nzRYpE5esF0SbQe7NofvULJT6DYoE8b12n8A=; b=luwhh3Z9rNCoXp/OsKL5PBO5U1KPzY7KettJ07XOchnHMRH2m6BBba+/sVbV8MU3I2 fVNnkBq8ji3oNDO5L3zUf11O9ASvOf8Civ/OBKApJesn09lq4ItMYN6Ro9WyejWQB70x u4FUj+l1BZmPhKSqNPcpOXvQiTotBAbmy16dxcM7zMP9IoDMfLcsKLewn0UWw0SiwxXK 3y4iHo04gRn9xostcpg2WAfOcPS+QhHVe0/uzhbWhJRkgVYwnU0EjfzAkVIb/kGDs/+F O/OhsiRasGB8YyLSJue8a8TiiLbIYc+zOtUhTvXRhCBI22KKrdxv0PozfLX5vyYS+rRy 11OA== X-Gm-Message-State: AOAM532P0Yan0JUvzPVhFjpbw7PAXMnrDZ9rZRJPfpkpMV3OnY+i2cDj ctn70gDIWKFl99qq4mKoDXER36/zk3Sx8DLc3e75bw3mrxb7Xg== X-Google-Smtp-Source: ABdhPJzs2M407zp0uCVZlZoqaqmtKarNx7ciCba4j+awMFwB3GrA0cLzPZCnlsGOhtMUzJLSSb1XdMASDkXft03B1rI= X-Received: by 2002:a17:906:4049:: with SMTP id y9mr11953650ejj.442.1606766897684; Mon, 30 Nov 2020 12:08:17 -0800 (PST) MIME-Version: 1.0 Date: Mon, 30 Nov 2020 12:08:05 -0800 Message-ID: Subject: Go patch committed: Always use int context for index values To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch changes the Go frontend to always use a context that expects an int type when determining the type of an index value. This is for https://golang.org/issue/14844. This requires updating one of the tests in the testsuite to the source version. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 8d8fea8a57068a0c5f0c1df766679a25f4272481 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index af4d0526b2f..698969fc8c8 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -68b1c7659a6b25d537a4ff3365ab070fa6215b0b +af683486b4de5503b2b6d9ae974a2ab1eeb92290 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index dc7399ebb3a..d1546300d0e 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -12802,24 +12802,11 @@ Array_index_expression::do_determine_type(const Type_context*) this->array_->determine_type_no_context(); Type_context index_context(Type::lookup_integer_type("int"), false); - if (this->start_->is_constant()) - this->start_->determine_type(&index_context); - else - this->start_->determine_type_no_context(); + this->start_->determine_type(&index_context); if (this->end_ != NULL) - { - if (this->end_->is_constant()) - this->end_->determine_type(&index_context); - else - this->end_->determine_type_no_context(); - } + this->end_->determine_type(&index_context); if (this->cap_ != NULL) - { - if (this->cap_->is_constant()) - this->cap_->determine_type(&index_context); - else - this->cap_->determine_type_no_context(); - } + this->cap_->determine_type(&index_context); } // Check types of an array index. @@ -13488,17 +13475,9 @@ String_index_expression::do_determine_type(const Type_context*) this->string_->determine_type_no_context(); Type_context index_context(Type::lookup_integer_type("int"), false); - if (this->start_->is_constant()) - this->start_->determine_type(&index_context); - else - this->start_->determine_type_no_context(); + this->start_->determine_type(&index_context); if (this->end_ != NULL) - { - if (this->end_->is_constant()) - this->end_->determine_type(&index_context); - else - this->end_->determine_type_no_context(); - } + this->end_->determine_type(&index_context); } // Check types of a string index. diff --git a/gcc/testsuite/go.test/test/shift1.go b/gcc/testsuite/go.test/test/shift1.go index 04f5321b73f..d6a6c38839f 100644 --- a/gcc/testsuite/go.test/test/shift1.go +++ b/gcc/testsuite/go.test/test/shift1.go @@ -1,6 +1,6 @@ // errorcheck -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -18,13 +18,13 @@ func h(x float64) int { return 0 } var ( s uint = 33 u = 1.0 << s // ERROR "invalid operation|shift of non-integer operand" - v float32 = 1 << s // ERROR "invalid" "as type float32" + v float32 = 1 << s // ERROR "invalid" ) // non-constant shift expressions var ( - e1 = g(2.0 << s) // ERROR "invalid|shift of non-integer operand" "as type interface" - f1 = h(2 << s) // ERROR "invalid" "as type float64" + e1 = g(2.0 << s) // ERROR "invalid|shift of non-integer operand" + f1 = h(2 << s) // ERROR "invalid" g1 int64 = 1.1 << s // ERROR "truncated" ) @@ -66,8 +66,15 @@ func _() { u2 = 1<