From patchwork Sun Jul 20 15:13:55 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: 371932 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 87C7814013B for ; Mon, 21 Jul 2014 01:14:14 +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=X49rthKFHswpXvmo/+WTD9wrS0QBLpBwmluwWMu6vJptSP9ANYRnz iLG5lDmCQAN0brPAnPdbTtJv5BuiqZvJHpcO7x35+3gy99WbiN2zX3Hz5N3EQf/K zePjxTywu/VEaL6j3+DclL+jhfVcR0C1zw9IUQIDakkQUkbTRXx3zU= 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=reTXRa/PGZ2PsyBkdOZJ2j/+rAk=; b=U0PirAlEUfM7bX2ww37v RIx3gXLKTVc0Zfot46N7bsYqAFU5DMDhyvVx5zvArYIQHcpkpDWhDmokzDkviHgc V6mAGOmnJ5hmsycZoAsAWOEoa9a4xRNrsdxHEwI7f/l52x6Mr6wnXnMIQqO/McUd L1Lr09mahlYN/x8U4gyb/yM= Received: (qmail 10748 invoked by alias); 20 Jul 2014 15:14:06 -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 10693 invoked by uid 89); 20 Jul 2014 15:14:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 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-wi0-f182.google.com Received: from mail-wi0-f182.google.com (HELO mail-wi0-f182.google.com) (209.85.212.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 20 Jul 2014 15:14:00 +0000 Received: by mail-wi0-f182.google.com with SMTP id d1so2871080wiv.15 for ; Sun, 20 Jul 2014 08:13:57 -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=g9R3e4X4TDB1bb7Cn/NSUJG7MtZkfj2uCrvkU6bWWhI=; b=FdoUplhwECnM14xYIUDas36z3okkTO6ZtGIMKQte01eeT6qoGl0XN8pmQahBTdqcFe Y1a2V//YGwz4AC+Wa8U4j6orVSjIhHb5SrQI3EDHOPsq988/8BqDKFZTDs6lQEmkPCFh R34sm7lkRKOFlM4/jvg5PCvda8NQK+OrkacT8AyMEgsa+tUUoSquJzuGhV/Xi7BxhaSs 1lLhWHe/i1lIO6bTh5g6Wmkc0a4q+QTlJP4LsQI9tYMC2YOv7SgoaNkWOWnVEfjFX96Q c8uub3OvGhhArs89HRU2UImFSJUzAjQyoOWZDH2ifUT7qN/7WJl/edREcmzmUc8CSgh5 KVoQ== X-Gm-Message-State: ALoCoQm7cWZOnbmgIY1EL3Gvy7167eZwKJq/b9Sd4tMWELwtNlVA4BoHzdSuK0SrfnSqid1/r87i X-Received: by 10.194.89.168 with SMTP id bp8mr14291062wjb.73.1405869237463; Sun, 20 Jul 2014 08:13:57 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com (global-1-18.nat.csx.cam.ac.uk. [131.111.184.18]) by mx.google.com with ESMTPSA id eh10sm31066392wic.0.2014.07.20.08.13.56 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 20 Jul 2014 08:13:56 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't merge dot-import names Date: Sun, 20 Jul 2014 08:13:55 -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 to the Go frontend fixes it so that a name included because of a dot import (import . "package") is not merged with the same name defined in an earlier file. Without this patch, the Go compiler would incorrectly accept code that used a name defined by a dot import in a later file. I've sent out a change to add a test to the master testsuite: http://codereview.appspot.com/118000043 . For this patch, bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 0e313c250b05 go/gogo.cc --- a/go/gogo.cc Sun Jul 20 08:08:44 2014 -0700 +++ b/go/gogo.cc Sun Jul 20 08:11:43 2014 -0700 @@ -473,7 +473,7 @@ bindings->begin_declarations(); p != bindings->end_declarations(); ++p) - this->add_named_object(p->second); + this->add_dot_import_object(p->second); } else if (ln == "_") package->set_uses_sink_alias(); @@ -1968,11 +1968,32 @@ return Named_object::make_sink(); } -// Add a named object. +// Add a named object for a dot import. void -Gogo::add_named_object(Named_object* no) -{ +Gogo::add_dot_import_object(Named_object* no) +{ + // If the name already exists, then it was defined in some file seen + // earlier. If the earlier name is just a declaration, don't add + // this name, because that will cause the previous declaration to + // merge to this imported name, which should not happen. Just add + // this name to the list of file block names to get appropriate + // errors if we see a later definition. + Named_object* e = this->package_->bindings()->lookup(no->name()); + if (e != NULL && e->package() == NULL) + { + if (e->is_unknown()) + e = e->resolve(); + if (e->package() == NULL + && (e->is_type_declaration() + || e->is_function_declaration() + || e->is_unknown())) + { + this->add_file_block_name(no->name(), no->location()); + return; + } + } + this->current_bindings()->add_named_object(no); } diff -r 0e313c250b05 go/gogo.h --- a/go/gogo.h Sun Jul 20 08:08:44 2014 -0700 +++ b/go/gogo.h Sun Jul 20 08:11:43 2014 -0700 @@ -397,7 +397,7 @@ // Add a named object to the current namespace. This is used for // import . "package". void - add_named_object(Named_object*); + add_dot_import_object(Named_object*); // Add an identifier to the list of names seen in the file block. void diff -r 0e313c250b05 go/import.cc --- a/go/import.cc Sun Jul 20 08:08:44 2014 -0700 +++ b/go/import.cc Sun Jul 20 08:11:43 2014 -0700 @@ -431,7 +431,7 @@ Typed_identifier tid(name, type, this->location_); Named_object* no = this->package_->add_constant(tid, expr); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } // Import a type. @@ -464,7 +464,7 @@ Named_object* no; no = this->package_->add_variable(name, var); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } // Import a function into PACKAGE. PACKAGE is normally @@ -518,7 +518,7 @@ { no = package->add_function_declaration(name, fntype, loc); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } return no; } diff -r 0e313c250b05 go/unsafe.cc --- a/go/unsafe.cc Sun Jul 20 08:08:44 2014 -0700 +++ b/go/unsafe.cc Sun Jul 20 08:11:43 2014 -0700 @@ -66,7 +66,7 @@ fntype->set_is_builtin(); no = bindings->add_function_declaration("Sizeof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); // Offsetof. results = new Typed_identifier_list; @@ -76,7 +76,7 @@ fntype->set_is_builtin(); no = bindings->add_function_declaration("Offsetof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); // Alignof. results = new Typed_identifier_list; @@ -86,7 +86,7 @@ fntype->set_is_builtin(); no = bindings->add_function_declaration("Alignof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); if (!this->imported_unsafe_) {