From patchwork Fri Sep 28 13:50:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 976308 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-486622-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=golang.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="r3pO+rJK"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=golang-org.20150623.gappssmtp.com header.i=@golang-org.20150623.gappssmtp.com header.b="KOTbzLtD"; dkim-atps=neutral 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 42MCkf35VMz9s1x for ; Fri, 28 Sep 2018 23:51:03 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=Tv8QANQzyfx+aEjUrnJlGoCmYELGCSOQ6DqGQ2Bahb9pxf 7HBbT22HcvP875haxlTaYdqzkJ8M+I9DU69qspZQ8OuPKHey9UKLe264YvrmN9so 2G/RM/q9kW2zj2nTxNUzVtKBn7piJJ3HzYRdZdzhj1TPl7617NXjCVpNmbeAE= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=j40qiFCJ2IE4JWWNtd3SvCqq+MM=; b=r3pO+rJKNkqyQXqfrmi7 ow9HDumLKlJszxc6GheoGYrv4wzPs/DdQJpKC5Kwb0h14CirfTzuRo1eXeL5kacv JX4NIuSu9r29DkBpCf52AmdFyWWgGWSnFaFDInJZEVK3zTponVdMOUrT8/zQGoli IWVY+O95OgP6lvZT59DuIXQ= Received: (qmail 26910 invoked by alias); 28 Sep 2018 13:50:55 -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 26895 invoked by uid 89); 28 Sep 2018 13:50:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Lex, HTo:D*googlegroups.com, Than X-HELO: mail-lf1-f53.google.com Received: from mail-lf1-f53.google.com (HELO mail-lf1-f53.google.com) (209.85.167.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Sep 2018 13:50:53 +0000 Received: by mail-lf1-f53.google.com with SMTP id g89-v6so5053390lfl.5 for ; Fri, 28 Sep 2018 06:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=ZHYyAwfOYRRrrofXTRiJeu0W4kYRpZoP1ixVwKXdZBA=; b=KOTbzLtD8N6Fy04laRCECov68EL0a74GX5p57kb7qR3D5ErxvlN3v9BXdoxJX2a+DA 5p6cCXRDoArPoC2EULixO+ZFl3i+mxA2Tznj2FAC1Wl6bTx2WxmdAFjJaGUMdPSZghGs 2l4B7DM+rDwv7w4rh7653HH9qTnsCXHhjtVRrEU7qpPIU7Ja9QHyIH6p1GLEjnfLC9mT WxQtRblpjx/WtCJDcgzt74xJiM4BL8nVYebkJ/6JVpsaV38WvDFOzVEDuAwhx4TzOqj4 4t4OaI6pAgzK44vqNo5ZwsA/4V7pskBA19U1Z9qP/AY9tbv3WzQJcKxzu7DqhJ9a+bMn 1o3Q== MIME-Version: 1.0 Received: by 2002:ab3:5609:0:0:0:0:0 with HTTP; Fri, 28 Sep 2018 06:50:49 -0700 (PDT) From: Ian Lance Taylor Date: Fri, 28 Sep 2018 06:50:49 -0700 Message-ID: Subject: Go patch committed: Fix parsing problem when package name starts with non-ASCII To: gcc-patches , gofrontend-dev@googlegroups.com This patch to the Go frontend by Than McIntosh fixes a problem when the name of a package starts with a non-ASCII character. The function Lex::is_exported_name (which assumes that its input is a mangled name) was being called on non-mangled (raw utf-8) names in various places. In https://golang.org/issue/27836 this caused an imported package to be registered under the wrong name. To fix the issue, rename 'Lex::is_exported_name' to 'Lex::is_exported_mangled_name', and add a new 'Lex::is_exported_name' that works on utf-8 strings. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 264648) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -944784a93cf89d3a238e5607c993ea5f18f99c12 +f4a224ec481957ca4f14d0e8cc4fe59cc95b3a49 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/import.cc =================================================================== --- gcc/go/gofrontend/import.cc (revision 264648) +++ gcc/go/gofrontend/import.cc (working copy) @@ -983,8 +983,6 @@ Import::read_name() std::string ret = this->read_identifier(); if (ret == "?") ret.clear(); - else if (!Lex::is_exported_name(ret)) - ret = '.' + this->package_->pkgpath() + '.' + ret; return ret; } Index: gcc/go/gofrontend/lex.cc =================================================================== --- gcc/go/gofrontend/lex.cc (revision 264648) +++ gcc/go/gofrontend/lex.cc (working copy) @@ -2764,7 +2764,7 @@ Lex::is_unicode_uppercase(unsigned int c // mangled name which includes only ASCII characters. bool -Lex::is_exported_name(const std::string& name) +Lex::is_exported_mangled_name(const std::string& name) { unsigned char c = name[0]; if (c != '.') @@ -2791,6 +2791,18 @@ Lex::is_exported_name(const std::string& } } +// Return whether the identifier NAME should be exported. NAME is a +// an unmangled utf-8 string and may contain non-ASCII characters. + +bool +Lex::is_exported_name(const std::string& name) +{ + unsigned int uchar; + if (Lex::fetch_char(name.c_str(), &uchar) != 0) + return Lex::is_unicode_letter(uchar) && Lex::is_unicode_uppercase(uchar); + return false; +} + // Return whether the identifier NAME contains an invalid character. // This is based on how we handle invalid characters in // gather_identifier. Index: gcc/go/gofrontend/lex.h =================================================================== --- gcc/go/gofrontend/lex.h (revision 264648) +++ gcc/go/gofrontend/lex.h (working copy) @@ -408,6 +408,11 @@ class Lex // Return whether the identifier NAME should be exported. NAME is a // mangled name which includes only ASCII characters. static bool + is_exported_mangled_name(const std::string& name); + + // Return whether the identifier NAME should be exported. NAME is + // an unmangled utf-8 string and may contain non-ASCII characters. + static bool is_exported_name(const std::string& name); // Return whether the identifier NAME is invalid. When we see an