From patchwork Thu Oct 17 20:08:40 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: 284362 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 E6CF62C00BC for ; Fri, 18 Oct 2013 07:08:59 +1100 (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=Aw4Wm8hwjMt7EAu/GZu1RtVta2LvOo4kUw/lk+0YQK7f75MyXMPvu YXimOOtPjuS9xsiNKPuQWFS3P1w5uQ32f1TKvFdGyDn1L2QAK3kOXoHIou6LWNTV jPVIW7Pur26NkaqxLl129CqyyXDCdrljWhEOi69xXiHArU8aYkkMsc= 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=/ICk4741e5o/K6Ts6FNeeAR6C6Y=; b=OtfxOrBA4GQfRlbLu2U8 dNS7J1CcKYZxYSHjTjd1sSINZ1fRLOX1GKoeXK7N8m/9Syco1nuGv8UA/u9/GoNw 5J879n9cgWbhDkrF4Mr4SrCluGQ9F6cO5jpCLIUMNeyCRAULJTeVE4aih4oGbUOs Rlh69YRHm9S0TyNb8tK2vAM= Received: (qmail 16814 invoked by alias); 17 Oct 2013 20:08:52 -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 16794 invoked by uid 89); 17 Oct 2013 20:08:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS, T_TVD_MIME_NO_HEADERS autolearn=ham version=3.3.2 X-HELO: mail-pb0-f45.google.com Received: from mail-pb0-f45.google.com (HELO mail-pb0-f45.google.com) (209.85.160.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 17 Oct 2013 20:08:49 +0000 Received: by mail-pb0-f45.google.com with SMTP id mc17so2780717pbc.18 for ; Thu, 17 Oct 2013 13:08:47 -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=aXfdytn+R3o87D8W7sCGYZtwMd8ZbFCN2QyayCmCFYs=; b=JoFET4yQ4jomQRHB62JNlZMQde/IGV2j2/rGbU+8gOP8QeojccCGa3iFIR8Uvhhbbc ZCvX4v7VgVwY2/jdZgkVqV/mz0oWoBm/it0b91gYXJb5/vFlzC0C6+D2QmoZZXlUFxgk n6G/8mDFurPyWGiBrWpASj/CzHcN8oFf6f4l1Z3njeMTBIVUB2wfW2wqFF8mKl9j+BjB w9MwSH4nKBTXuY2s1pADCVDiGpDyRqmlwBnk4jH9ufgMAP+kaWIBoxUr1eY6QcyymemF A7q4gZ4PlFC8ycFxRNdIvbLmjbMIUDAc3Pt1cVsa5anlk689VPvqveSdsDtF6a9jkbEA Py3A== X-Gm-Message-State: ALoCoQlga5HsRLxBohqG+iChjEmhBBufdD6HlDqdM01ltlG2t7yY/46EUhbzJHtsZy/pPyFH9+jYePsGU0gyuw33quFCnmfGPI0I41C7uq33zgflOIcI5mn+3wHIAfKSVOGWDRWAIORihBuzkaoxYLUZWU0+uJhTvSTDei8DSKcaIRV7TCnpnfClAjrNDZDInxQ+ui/RkdduYeOJ2mbn7YMttyEV+cHgjw== X-Received: by 10.66.188.203 with SMTP id gc11mr10670537pac.63.1382040527339; Thu, 17 Oct 2013 13:08:47 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com ([172.19.248.45]) by mx.google.com with ESMTPSA id ed3sm99730438pbc.6.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 17 Oct 2013 13:08:46 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Fix imported embedded builtin types again Date: Thu, 17 Oct 2013 13:08:40 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes I found another bug in my recent change to fix the handling of imported embedded builtin types. Two bugs means I need a different approach. This patch removes the code I added earlier and adopts a simpler approach, in which we mark a struct field for whether it is imported. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch. Ian diff -r 6ecdc3838869 go/types.cc --- a/go/types.cc Thu Oct 17 11:40:01 2013 -0700 +++ b/go/types.cc Thu Oct 17 13:03:06 2013 -0700 @@ -4208,13 +4208,44 @@ // This is a horrible hack caused by the fact that we don't pack // the names of builtin types. FIXME. + if (!this->is_imported_ + && nt != NULL + && nt->is_builtin() + && nt->name() == Gogo::unpack_hidden_name(name)) + return true; + + return false; + } +} + +// Return whether this field is an unexported field named NAME. + +bool +Struct_field::is_unexported_field_name(Gogo* gogo, + const std::string& name) const +{ + const std::string& field_name(this->field_name()); + if (Gogo::is_hidden_name(field_name) + && name == Gogo::unpack_hidden_name(field_name) + && gogo->pack_hidden_name(name, false) != field_name) + return true; + + // Check for the name of a builtin type. This is like the test in + // is_field_name, only there we return false if this->is_imported_, + // and here we return true. + if (this->is_imported_ && this->is_anonymous()) + { + Type* t = this->typed_identifier_.type(); + if (t->points_to() != NULL) + t = t->points_to(); + Named_type* nt = t->named_type(); if (nt != NULL && nt->is_builtin() && nt->name() == Gogo::unpack_hidden_name(name)) return true; - - return false; - } + } + + return false; } // Return whether this field is an embedded built-in type. @@ -4649,13 +4680,8 @@ for (Struct_field_list::const_iterator pf = fields->begin(); pf != fields->end(); ++pf) - { - const std::string& field_name(pf->field_name()); - if (Gogo::is_hidden_name(field_name) - && name == Gogo::unpack_hidden_name(field_name) - && gogo->pack_hidden_name(name, false) != field_name) - return true; - } + if (pf->is_unexported_field_name(gogo, name)) + return true; } return false; } @@ -5257,34 +5283,8 @@ } Type* ftype = imp->read_type(); - // We don't pack the names of builtin types. In - // Struct_field::is_field_name we cope with a hack. Now we - // need another hack so that we don't accidentally think - // that an embedded builtin type is accessible from another - // package (we know that all the builtin types are not - // exported). - // This is called during parsing, before anything is - // lowered, so we have to be careful to avoid dereferencing - // an unknown type name. - if (name.empty()) - { - Type *t = ftype; - if (t->classification() == Type::TYPE_POINTER) - { - // Very ugly. - Pointer_type* ptype = static_cast(t); - t = ptype->points_to(); - } - std::string tname; - if (t->forward_declaration_type() != NULL) - tname = t->forward_declaration_type()->name(); - else if (t->named_type() != NULL) - tname = t->named_type()->name(); - if (!tname.empty() && tname[0] >= 'a' && tname[0] <= 'z') - name = '.' + imp->package()->pkgpath() + '.' + tname; - } - Struct_field sf(Typed_identifier(name, ftype, imp->location())); + sf.set_is_imported(); if (imp->peek_char() == ' ') { @@ -9324,7 +9324,9 @@ else { bool is_unexported; - if (!Gogo::is_hidden_name(name)) + // The test for 'a' and 'z' is to handle builtin names, + // which are not hidden. + if (!Gogo::is_hidden_name(name) && (name[0] < 'a' || name[0] > 'z')) is_unexported = false; else { diff -r 6ecdc3838869 go/types.h --- a/go/types.h Thu Oct 17 11:40:01 2013 -0700 +++ b/go/types.h Thu Oct 17 13:03:06 2013 -0700 @@ -1924,7 +1924,7 @@ { public: explicit Struct_field(const Typed_identifier& typed_identifier) - : typed_identifier_(typed_identifier), tag_(NULL) + : typed_identifier_(typed_identifier), tag_(NULL), is_imported_(false) { } // The field name. @@ -1935,6 +1935,10 @@ bool is_field_name(const std::string& name) const; + // Return whether this struct field is an unexported field named NAME. + bool + is_unexported_field_name(Gogo*, const std::string& name) const; + // Return whether this struct field is an embedded built-in type. bool is_embedded_builtin(Gogo*) const; @@ -1972,6 +1976,11 @@ set_tag(const std::string& tag) { this->tag_ = new std::string(tag); } + // Record that this field is defined in an imported struct. + void + set_is_imported() + { this->is_imported_ = true; } + // Set the type. This is only used in error cases. void set_type(Type* type) @@ -1982,6 +1991,8 @@ Typed_identifier typed_identifier_; // The field tag. This is NULL if the field has no tag. std::string* tag_; + // Whether this field is defined in an imported struct. + bool is_imported_; }; // A list of struct fields.