From patchwork Fri Jun 14 18:00:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 251479 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 CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 840912C00A1 for ; Sat, 15 Jun 2013 04:00:35 +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=G0D5X5ESwy/vclcdIa3PrCF398dp8OIk5KDdIIefYM18WPhrpiIDu RA4S75T2P/iYXtFM10bwnD/sPPZGoi2/YjMDSjSFRENV/0mcO3RcgJXN1eL4xxSH en5MFsMlqolh+YQtxVMyGcH0qntWubrrsHtTUtpxk+txzmqEmf7ZEw= 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=7Yd/2J/c6zeS/ovkrVtAQCgB++0=; b=e1hrYSWXCOqGY4qOog0g TiROpAiXCKKnFmV4zYIMFzrLV8PU83m3RH1blzl4MvmEYg9ra00RrlIrCgtodykH KpYE6wt/2pVd5wGQiiJddZ/avtmb8gBczQ2dwP3vtSSxpbhuhV/0a4Vi5AIRzvro z2sNVKhqFEjdY/XCyr9PeBw= Received: (qmail 5803 invoked by alias); 14 Jun 2013 18:00:17 -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 5715 invoked by uid 89); 14 Jun 2013 18:00:12 -0000 X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, TW_CC autolearn=ham version=3.3.1 Received: from mail-pd0-f172.google.com (HELO mail-pd0-f172.google.com) (209.85.192.172) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 14 Jun 2013 18:00:11 +0000 Received: by mail-pd0-f172.google.com with SMTP id z10so806423pdj.31 for ; Fri, 14 Jun 2013 11:00:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type:x-gm-message-state; bh=rN++XNFsf7GKswvCAh3jj1wHf8JsC5SUqsW9i2C8fG0=; b=OrYeS+DzzHfrGHjTxxJyV4HtQtU4ndYJdZ99Ih8P0pBJp04FI8oYSSmoWUJmokqrGr 1vS4WGIcr/xwEHxGA183w9x7xxxfCQk7gdXaYto4+o/85w81cCQNZ+R3pamphMnNvX6b 0TTxA+a6GE+tWTWUJsmt9bUaKjDc0nzFdcU1mbLW79463I5Y/a7wo07kp7wt1BaPcY1q V7LjqGwta0LwlgeTtFdtSwh9GxtUk9OF/f7WwtwlaIpbzlAjQWAdYtxB8Y2WyTzbPmuZ N/PBWiFJ+YwuAsShUBvdeQ/tRrnc0iWSFPKBkRHqjVS5xyjXQ2rDITua3DlSElhFeNob d06w== X-Received: by 10.66.233.98 with SMTP id tv2mr3617923pac.124.1371232810034; Fri, 14 Jun 2013 11:00:10 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com ([2620:0:1000:3204:1096:8e7a:4c30:69e6]) by mx.google.com with ESMTPSA id pl9sm3099834pbc.5.2013.06.14.11.00.08 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 14 Jun 2013 11:00:09 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org Subject: Go patch committed: Fix unsafe.Offsetof Date: Fri, 14 Jun 2013 11:00:07 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkv/3dPPBRWWXkzmKjoP3GUMMJjsDn0Jccy60A1Ek2H7+szB/9BvG0sioTjrJjUP0FCP9/S8FVkvCjry6/ATUxQ8bkrJgG32oUDgzvfHsz6nYWlcRv6oJI4eHXM4H53H5z7PLaUzMXNHZ4eEKJP079Kft3WTa2r4xVjd/uHY5IENtVbReidqhDcwoY7dEvnSXpFcrpo6dX0bI2aCA+KN3iTFnL3XcuRMvg3JfBmv7y0ZHIwyf4= X-Virus-Found: No This gccgo patch from Rémy Oudompheng fixes unsafe.Offsetof applied to a field in an embedded struct. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch. Ian diff -r ea256b8b5c75 go/expressions.cc --- a/go/expressions.cc Wed Jun 12 15:27:10 2013 -0700 +++ b/go/expressions.cc Fri Jun 14 10:56:49 2013 -0700 @@ -7279,19 +7279,31 @@ Field_reference_expression* farg = arg->field_reference_expression(); if (farg == NULL) return false; - Expression* struct_expr = farg->expr(); - Type* st = struct_expr->type(); - if (st->struct_type() == NULL) - return false; - if (st->named_type() != NULL) - st->named_type()->convert(this->gogo_); - unsigned int offset; - if (!st->struct_type()->backend_field_offset(this->gogo_, - farg->field_index(), - &offset)) - return false; + unsigned int total_offset = 0; + while (true) + { + Expression* struct_expr = farg->expr(); + Type* st = struct_expr->type(); + if (st->struct_type() == NULL) + return false; + if (st->named_type() != NULL) + st->named_type()->convert(this->gogo_); + unsigned int offset; + if (!st->struct_type()->backend_field_offset(this->gogo_, + farg->field_index(), + &offset)) + return false; + total_offset += offset; + if (farg->implicit() && struct_expr->field_reference_expression() != NULL) + { + // Go up until we reach the original base. + farg = struct_expr->field_reference_expression(); + continue; + } + break; + } nc->set_unsigned_long(Type::lookup_integer_type("uintptr"), - static_cast(offset)); + static_cast(total_offset)); return true; } else if (this->code_ == BUILTIN_REAL || this->code_ == BUILTIN_IMAG) diff -r ea256b8b5c75 go/expressions.h --- a/go/expressions.h Wed Jun 12 15:27:10 2013 -0700 +++ b/go/expressions.h Fri Jun 14 10:56:49 2013 -0700 @@ -1860,6 +1860,15 @@ field_index() const { return this->field_index_; } + // Return whether this node was implied by an anonymous field. + bool + implicit() const + { return this->implicit_; } + + void + set_implicit(bool implicit) + { this->implicit_ = implicit; } + // Set the struct expression. This is used when parsing. void set_struct_expression(Expression* expr) @@ -1914,6 +1923,9 @@ Expression* expr_; // The zero-based index of the field we are retrieving. unsigned int field_index_; + // Whether this node was emitted implicitly for an embedded field, + // that is, expr_ is not the expr_ of the original user node. + bool implicit_; // Whether we have already emitted a fieldtrack call. bool called_fieldtrack_; }; diff -r ea256b8b5c75 go/types.cc --- a/go/types.cc Wed Jun 12 15:27:10 2013 -0700 +++ b/go/types.cc Fri Jun 14 10:56:49 2013 -0700 @@ -4532,6 +4532,7 @@ go_assert(sub != NULL); } sub->set_struct_expression(here); + sub->set_implicit(true); } else if (subdepth > found_depth) delete sub;