From patchwork Wed Jan 31 18:36:08 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: 868035 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-472405-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tXubtOzX"; 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 3zWsQZ18B0z9ryv for ; Thu, 1 Feb 2018 05:36:21 +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=LHPfORq31xXStv7Aeav6qN8no7z/ei477sGTBqh3+DyxMr 4Tg5OLSK4gimcatCkyfJeH/R398YZ/g4ONZdkuOVjh6oRohBb6wcXCKo/4yiH9sF /ziXnKn/H4mpx7vrSjIbuglqoayXZCPIYK1iaFajeqZkFtnfSgvyWmsfU0eI4= 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=Bhsu0+Sh9yFxirKx8koq3tnWjjo=; b=tXubtOzXoqfQgawvGRO6 m0wHSsaIQ0iJqHlyUGcevpHYu0nZ11FFa13OHmLo+Zf2OajlYC/tYGHG1quy2c0w fbEMsC9VSSnfgvITAzc1U1ZGW4ri4oY9uEB3kYtf5otYIihb+C+jI0TXho/eFRWD qSbDOoR5KE3bQTAaYNAUnXc= Received: (qmail 97920 invoked by alias); 31 Jan 2018 18:36:13 -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 97902 invoked by uid 89); 31 Jan 2018 18:36:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=circular, retains X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Jan 2018 18:36:11 +0000 Received: by mail-wm0-f46.google.com with SMTP id v71so953339wmv.2 for ; Wed, 31 Jan 2018 10:36:11 -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=YvhkFL0TFNke9f2LQ33ScpgljYuNr7lZuSPyJhk+D0c=; b=D5dfBsiWvF0PVKHtE4tvuAZoQ3RJPraLV9NSZHPmnjJKTLGUqPVQbMQB++ZelsYvQ3 aEWXGq1BFcxh/3th7oDYnx9mdpZ9n3GPr54dSCtKqLT3qhh3x9QCsL6EiQV4GMJsFW4M emr8QGLxLYM5SgrDWYNKyBOOga9qv9G6N8B1zkE4h/GZIyrOjV43i//vh1WR+yY23ZEZ d8f/wA2pQw2ewuu+aP3duZkKK22WVGDZn7WzFH3qT3IoE0Q3b5CRJ1B35JwOhCD+Fp8z 8vAdxZAs51dtF9IKelDfO88VV8CRqZlBAovq0NCGews5N8IypsXV9rOf7Wd1h9Kyxxzo v33Q== X-Gm-Message-State: AKwxytdt7wURzruYER1IWfd7qTk6RKI5/FHLLe563qHAscPTjLndGGLp fNhVBRabr6BZSKHf88i4xIOxff8nIHxYCKdpq6Sw4gZQ X-Google-Smtp-Source: AH8x225qsiAMDqsRb7q/xmGKWpkfgmdwZTDhTeggUYi9UxUTBjwzb9MeC8pRE7y8+e1pXYZJvxV+gIIX4lMEyelhfZ8= X-Received: by 10.80.183.170 with SMTP id h39mr57842463ede.124.1517423769150; Wed, 31 Jan 2018 10:36:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.134.56 with HTTP; Wed, 31 Jan 2018 10:36:08 -0800 (PST) From: Ian Lance Taylor Date: Wed, 31 Jan 2018 10:36:08 -0800 Message-ID: Subject: Go patch committed: Lower expression types in lowering pass To: gcc-patches , gofrontend-dev@googlegroups.com This patch to the Go frontend, based on one by Cherry Zhang, lowers expression types in the lowering pass. This ensures that array types with complicated length expressions are handled correctly. This required some adjustment of constant expression types to not report too many errors for circular constant expressions. We now record error types in the Named_constant type. If we find the circularity due to lowering the Named_constant, we use that location for the error message; this retains the error location we used to use. This fixes https://golang.org/issue/23545 . 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 257249) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -17325c96ccbee4ad6bed1cd3d9517f7dfbdf3ea7 +65eaa9003db4effc9c5ffe9c955e9534ba5d7d15 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 257217) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -2847,8 +2847,16 @@ Const_expression::do_type() if (this->seen_ || nc->lowering()) { - this->report_error(_("constant refers to itself")); + if (nc->type() == NULL || !nc->type()->is_error_type()) + { + Location loc = this->location(); + if (!this->seen_) + loc = nc->location(); + go_error_at(loc, "constant refers to itself"); + } + this->set_is_error(); this->type_ = Type::make_error_type(); + nc->set_type(this->type_); return this->type_; } @@ -2868,6 +2876,9 @@ Const_expression::do_type() this->seen_ = false; + if (ret->is_error_type()) + nc->set_type(ret); + return ret; } Index: gcc/go/gofrontend/gogo.cc =================================================================== --- gcc/go/gofrontend/gogo.cc (revision 257217) +++ gcc/go/gofrontend/gogo.cc (working copy) @@ -2751,6 +2751,14 @@ Lower_parse_tree::expression(Expression* return TRAVERSE_EXIT; *pexpr = enew; } + + // Lower the type of this expression before the parent looks at it, + // in case the type contains an array that has expressions in its + // length. Skip an Unknown_expression, as at this point that means + // a composite literal key that does not have a type. + if ((*pexpr)->unknown_expression() == NULL) + Type::traverse((*pexpr)->type(), this); + return TRAVERSE_SKIP_COMPONENTS; } @@ -6855,6 +6863,16 @@ Result_variable::get_backend_variable(Go // Class Named_constant. +// Set the type of a named constant. This is only used to set the +// type to an error type. + +void +Named_constant::set_type(Type* t) +{ + go_assert(this->type_ == NULL || t->is_error_type()); + this->type_ = t; +} + // Traverse the initializer expression. int Index: gcc/go/gofrontend/gogo.h =================================================================== --- gcc/go/gofrontend/gogo.h (revision 257217) +++ gcc/go/gofrontend/gogo.h (working copy) @@ -2147,6 +2147,9 @@ class Named_constant type() const { return this->type_; } + void + set_type(Type* t); + Expression* expr() const { return this->expr_; }