From patchwork Mon Sep 30 18:12:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 279205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 550F52C00E7 for ; Tue, 1 Oct 2013 04:12:51 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=NT/9Wy3bzYMV0binZEYRJw0I8fnuYqCWyC88ySMyD7dC3ZLWSXP00 gvrZkv8zulEkeBT4Zrl5RAIMKKMJQDoljiSHPzLKOs/xN95/CL0v0jN1VsJhuDi9 qjjjJfD2HJRgFhl8YqrAvmZEQ23AKmZLGC9QD3V2dvgyH+6XZHTLZk= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=qt26hM/3q77wOKxA1V2ujeF2doI=; b=mR1OzbC3Svv7haxtdUbZ yIt2ykKY9bpuS8BWM4Y+hq59iun3qkIqopdW4diqlBj2/RyIAS27A+v4APb7Czi6 qE/S8qWVV9qtQy3EmiXewTo8P17a5Gv5vB+pkPiG/UKzFe2AWzdhRlfQoQx7ehyp kv07t/ujuyXFvNgd1y1Lw04= Received: (qmail 20765 invoked by alias); 30 Sep 2013 18:12:44 -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 20752 invoked by uid 89); 30 Sep 2013 18:12:43 -0000 Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 30 Sep 2013 18:12:43 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, T_TVD_MIME_NO_HEADERS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f48.google.com Received: by mail-pa0-f48.google.com with SMTP id bj1so6211399pad.35 for ; Mon, 30 Sep 2013 11:12:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=6L4apDRo5a5Fx9Z9/9/WG52HCP7ozajZB/V8YE3Yzqg=; b=GSHTXtnWoRr98Kb7raYgdmFo96aiw6cS3mY5ZyQBrtkEAcZlkrpxgNPQU+nGYIixXp ICVYbmTjNx8SyH35DNEKN/kKcmN6gopxKM3jitaBJvPs0kScUx9ozQgQMK7k9n2InCgv j/m/xhSRs/0l4bmCr12jBXO8PP8CE5ux0Nz8E+7Ulk6deA7KltzmCV8w91homrwEND0L PEQ7ECoPmdigxCbEC8Dm5dCNGNq3ymoMFY+z8lXg//qRGaOGIhPXCWbwcSdjAReI0l1x 2g20NjQ9KHupkT6xxr3FnBHr8mGasXhBOugO/q8JSHE/Jt87PHi6KwR73YQZDzjIXJTv uRAw== X-Gm-Message-State: ALoCoQn1tC86zB3L4ONwRDuQfzfxIxfxBEvyQDXlIIfZm0UUaU2Oqj6EdpMRfFkkLxXUsFnxfcgqg74XGure/boiyzufq31YqYKljd9aJqCUc2cIUHVdp56wDR9+54q9bOWbpWlG9w1ASi+iabSfWb93v8DSsaID/BWF0FygJ7kg4hXwLUH4Rs4gxpv63NYrst7rgkTiRnpW3rfr20sxENwYRbfq1zz8bQ== X-Received: by 10.66.234.193 with SMTP id ug1mr29583450pac.92.1380564761048; Mon, 30 Sep 2013 11:12:41 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com ([172.29.167.242]) by mx.google.com with ESMTPSA id tx5sm2045502pbc.29.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 30 Sep 2013 11:12:40 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Use backend interface for variable expressions Date: Mon, 30 Sep 2013 11:12:38 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This patch from Chris Manghane changes the Go frontend to use the backend interface for variable expressions. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch. Ian 2013-09-30 Chris Manghane * go-gcc.cc (Backend::error_expression): New function. (Backend::var_expression): New function. (Backend::indirect_expression): New function. Index: gcc/go/go-gcc.cc =================================================================== --- gcc/go/go-gcc.cc (revision 202753) +++ gcc/go/go-gcc.cc (working copy) @@ -208,6 +208,16 @@ class Gcc_backend : public Backend Bexpression* zero_expression(Btype*); + Bexpression* + error_expression() + { return this->make_expression(error_mark_node); } + + Bexpression* + var_expression(Bvariable* var, Location); + + Bexpression* + indirect_expression(Bexpression* expr, bool known_valid, Location); + // Statements. Bstatement* @@ -848,6 +858,30 @@ Gcc_backend::zero_expression(Btype* btyp return tree_to_expr(ret); } +// An expression that references a variable. + +Bexpression* +Gcc_backend::var_expression(Bvariable* var, Location) +{ + tree ret = var->get_tree(); + if (ret == error_mark_node) + return this->error_expression(); + return tree_to_expr(ret); +} + +// An expression that indirectly references an expression. + +Bexpression* +Gcc_backend::indirect_expression(Bexpression* expr, bool known_valid, + Location location) +{ + tree ret = build_fold_indirect_ref_loc(location.gcc_location(), + expr->get_tree()); + if (known_valid) + TREE_THIS_NOTRAP(ret) = 1; + return tree_to_expr(ret); +} + // An expression as a statement. Bstatement* Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 202753) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -978,22 +978,19 @@ Var_expression::do_get_tree(Translate_co { Bvariable* bvar = this->variable_->get_backend_variable(context->gogo(), context->function()); - tree ret = var_to_tree(bvar); - if (ret == error_mark_node) - return error_mark_node; bool is_in_heap; + Location loc = this->location(); if (this->variable_->is_variable()) is_in_heap = this->variable_->var_value()->is_in_heap(); else if (this->variable_->is_result_variable()) is_in_heap = this->variable_->result_var_value()->is_in_heap(); else go_unreachable(); + + Bexpression* ret = context->backend()->var_expression(bvar, loc); if (is_in_heap) - { - ret = build_fold_indirect_ref_loc(this->location().gcc_location(), ret); - TREE_THIS_NOTRAP(ret) = 1; - } - return ret; + ret = context->backend()->indirect_expression(ret, true, loc); + return expr_to_tree(ret); } // Ast dump for variable expression. Index: gcc/go/gofrontend/backend.h =================================================================== --- gcc/go/gofrontend/backend.h (revision 202753) +++ gcc/go/gofrontend/backend.h (working copy) @@ -231,6 +231,22 @@ class Backend virtual Bexpression* zero_expression(Btype*) = 0; + // Create an error expression. This is used for cases which should + // not occur in a correct program, in order to keep the compilation + // going without crashing. + virtual Bexpression* + error_expression() = 0; + + // Create a reference to a variable. + virtual Bexpression* + var_expression(Bvariable* var, Location) = 0; + + // Create an expression that indirects through the pointer expression EXPR + // (i.e., return the expression for *EXPR). KNOWN_VALID is true if the pointer + // is known to point to a valid memory location. + virtual Bexpression* + indirect_expression(Bexpression* expr, bool known_valid, Location) = 0; + // Statements. // Create an error statement. This is used for cases which should