From patchwork Mon May 5 17:55:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 345795 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6117E140295 for ; Tue, 6 May 2014 03:55:18 +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=OaxdOEoiUJFJ+0bFLO8mavTEs3jekbu/9RONzKyKcYaUtzGMa+UhL JtbIaWJB3vQaZkTg0tw2RprI234WdrU2dqirWUhR7BaFLLc8YhcKexnUNMFAKLiZ 6EJ+MbDPV9Wj0o1+gMis7fz6TY4HFC8DnE1iEJ5RJ16kUt9eRykEV4= 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=aXkWWxXDSI4+4qXTtjY1NbSIS0o=; b=y1Vrywd4hALAoH8NeNzS RD+FMMcatKiaB/0FQngoUUkSc/s1T5C9cHyV+/7Q/TukeCnx8lQ2+7EhO89okVEh ndogAmM2el1TJ1xtYenvMItp2yRqwlu+aakLiQEVTLFPfWTqrEhlwo00BWsuxM41 3dz1xAEaHcz3ITCaA+lXnIk= Received: (qmail 4238 invoked by alias); 5 May 2014 17:55:11 -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 4222 invoked by uid 89); 5 May 2014 17:55:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS, T_TVD_MIME_NO_HEADERS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f176.google.com Received: from mail-pd0-f176.google.com (HELO mail-pd0-f176.google.com) (209.85.192.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 05 May 2014 17:55:09 +0000 Received: by mail-pd0-f176.google.com with SMTP id y13so6091029pdi.21 for ; Mon, 05 May 2014 10:55:07 -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=yEF/Vd8CIR5/8ZRLK2HsZOehAwuivHhIH3r2ksMdWdg=; b=REfUf1iUUsr4g9fdxgGIkxca0p6elIxdBvV+bSznkibu3gHv+zsaRsNvXFONEIo9lO cB2FOlMRAFW6+p5ReLGZWfQk1kKvBYMXz1buy/Vy5+GwxcwmA/TZwDYMe10BFMf5qnZD eCEOPHEdw/bljviiuOVGCmG4BCkxPfBUuOIzUTaoHfwtWnlHh8olNtm9izze49cGxG3+ Uer3vwXd74RcdVzSw3IKOx7q87De5TWHpLoIx7Sd3xIIfzi1S4fKiVP/1tCZ80AgRoGg Pn3+Yu+8taROEV/Td0HhPa1bCUq2jHasBuMsYQm8W/VladdP/r9l66DjyVjrr4LTZaZj 4nHw== X-Gm-Message-State: ALoCoQmNMQzmMmiOGsFPI9gmvu9g/znJb0MKJfz/1FE+85aNEQ/aw/f2lAce9fjrxTIN4pn0WJ6x X-Received: by 10.66.218.226 with SMTP id pj2mr31752121pac.134.1399312507628; Mon, 05 May 2014 10:55:07 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net. [71.133.8.30]) by mx.google.com with ESMTPSA id ai11sm24090411pac.30.2014.05.05.10.55.06 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 05 May 2014 10:55:06 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Use backend interface for struct field offsets Date: Mon, 05 May 2014 13:55:04 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This patch by Chris Manghane changes the Go frontend to use the backend interface for struct field offsets. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r d87cfc273ffc go/expressions.cc --- a/go/expressions.cc Mon May 05 13:21:55 2014 -0400 +++ b/go/expressions.cc Mon May 05 13:39:45 2014 -0400 @@ -14815,28 +14815,27 @@ tree Struct_field_offset_expression::do_get_tree(Translate_context* context) { - tree type_tree = type_to_tree(this->type_->get_backend(context->gogo())); - if (type_tree == error_mark_node) - return error_mark_node; - - tree val_type_tree = type_to_tree(this->type()->get_backend(context->gogo())); - go_assert(val_type_tree != error_mark_node); - const Struct_field_list* fields = this->type_->fields(); - tree struct_field_tree = TYPE_FIELDS(type_tree); Struct_field_list::const_iterator p; + unsigned i = 0; for (p = fields->begin(); p != fields->end(); - ++p, struct_field_tree = DECL_CHAIN(struct_field_tree)) - { - go_assert(struct_field_tree != NULL_TREE); - if (&*p == this->field_) - break; - } + ++p, ++i) + if (&*p == this->field_) + break; go_assert(&*p == this->field_); - return fold_convert_loc(BUILTINS_LOCATION, val_type_tree, - byte_position(struct_field_tree)); + Gogo* gogo = context->gogo(); + Btype* btype = this->type_->get_backend(gogo); + + size_t offset = gogo->backend()->type_field_offset(btype, i); + mpz_t offsetval; + mpz_init_set_ui(offsetval, offset); + Type* uptr_type = Type::lookup_integer_type("uintptr"); + Expression* ret = Expression::make_integer(&offsetval, uptr_type, + Linemap::predeclared_location()); + mpz_clear(offsetval); + return ret->get_tree(context); } // Dump ast representation for a struct field offset expression.