From patchwork Fri Oct 4 18:14:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1171988 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-510295-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="JYV1Untr"; 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="ecVERkuD"; 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 46lJ244pSwz9sPl for ; Sat, 5 Oct 2019 04:15:07 +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=mBtbaSBUx1W/WFFo89kCfwQLno1giwLt0qPM3QS4LxTEwi szOW5AkdeRBDd2L1mUffWZBTbUH5KW4vFJJdflAMCD5dnGa/sSatAc13ZINaB09e ZXdweZX5oMx/ygUXGPZGW4Q6VHcxHN1eiYhCXZwCOBYHEYQnuuJfVyDfcwbQ0= 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=cZ3tKYaJztZSX4OIkihqSgqJ5ho=; b=JYV1UntrZr7gDouoKH93 Pw/wU9PHXMCjJ0l3Q5dtEGD/3jg56CzAXWOF4FwiWiVZo6D1MmsuUV29LTjythVw hEnsp4Z19Kv2aVUm34DSJUTn9NgxqBc/05OVhfu2yCUTd7TqRLGmRZhjCeocd6nE IwrX2rBCgkBiMWGfeYfa7Fg= Received: (qmail 59963 invoked by alias); 4 Oct 2019 18:15:00 -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 59955 invoked by uid 89); 4 Oct 2019 18:15:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.6 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.1 spammy=H*Ad:D*googlegroups.com, classification, HX-Received:dd8e, HX-Received:sk:g14mr16 X-HELO: mail-ed1-f54.google.com Received: from mail-ed1-f54.google.com (HELO mail-ed1-f54.google.com) (209.85.208.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 04 Oct 2019 18:14:57 +0000 Received: by mail-ed1-f54.google.com with SMTP id a15so6803373edt.6 for ; Fri, 04 Oct 2019 11:14:57 -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=Aqb6I+48ScQPJtMfgt403OA22phU1dev0cw/EjqcF4M=; b=ecVERkuDWCapWiDi7DAFGNKLyDgdKKbFNbBqODfCm/gPMp2ED73Iyf/ptO5gJrrMu+ Mhd+zrtLZMWOIVpIf0j3xw5JO2I1r6Eoj6dfIRqPCuDRzedeV6xcUOYprfzoQicp10vk OoU0URcR+bZ1R7tkk8gaxymfcSJ/j/kj/fr6NKG2AZvdaQQz6RSzM/VfLEDcfx696hAV P+mb1G2+hdprezgvGpqi4A+lm5bekdI3gwuG6eW2LT8oGKIJfM82GgaljgsPi3emCL+u 4TGx7F5/90JnL+qUu9EodXmhj9TFQzs7yul2aRilmT8Vx6RRRBX713ESWHNNMMRI99s6 8Whg== MIME-Version: 1.0 From: Ian Lance Taylor Date: Fri, 4 Oct 2019 11:14:43 -0700 Message-ID: Subject: Go patch committed: Include constant types during export processing To: gcc-patches , gofrontend-dev This patch to the Go frontend by Than McIntosh includes selected constant types during export processing. The machinery that collects types referenced by expressions that are part of inlinable function bodies was missing the types of local named constants in certain cases. This patch updates the Collect_export_references::expression() hook to look for references to local named constants and include their types in the exported set. This fixes https://golang.org/issue/34577. 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 276579) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -441f3f1f350b532707c48273d7f454cf1c4e959f +ddfb845fad1f2e8b84383f262ed5ea5be7b3e35a The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/export.cc =================================================================== --- gcc/go/gofrontend/export.cc (revision 276382) +++ gcc/go/gofrontend/export.cc (working copy) @@ -249,6 +249,14 @@ Collect_export_references::expression(Ex return TRAVERSE_CONTINUE; } + const Named_object* nco = expr->named_constant(); + if (nco != 0 && nco->package() == NULL) + { + const Named_constant *nc = nco->const_value(); + Type::traverse(nc->type(), this); + return TRAVERSE_CONTINUE; + } + return TRAVERSE_CONTINUE; } @@ -322,6 +330,10 @@ Collect_export_references::type(Type* ty if (type->is_void_type()) return TRAVERSE_SKIP_COMPONENTS; + // Skip the nil type, turns up in function bodies. + if (type->is_nil_type()) + return TRAVERSE_SKIP_COMPONENTS; + // Skip abstract types. We should never see these in real code, // only in things like const declarations. if (type->is_abstract()) Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 276579) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -3234,6 +3234,10 @@ class Const_expression : public Expressi named_object() { return this->constant_; } + const Named_object* + named_object() const + { return this->constant_; } + // Check that the initializer does not refer to the constant itself. void check_for_init_loop(); @@ -16782,6 +16786,15 @@ Expression::is_local_variable() const || (no->is_variable() && !no->var_value()->is_global())); } +const Named_object* +Expression::named_constant() const +{ + if (this->classification() != EXPRESSION_CONST_REFERENCE) + return NULL; + const Const_expression* ce = static_cast(this); + return ce->named_object(); +} + // Class Type_guard_expression. // Traversal. Index: gcc/go/gofrontend/expressions.h =================================================================== --- gcc/go/gofrontend/expressions.h (revision 276382) +++ gcc/go/gofrontend/expressions.h (working copy) @@ -587,6 +587,11 @@ class Expression boolean_constant_value(bool* val) const { return this->do_boolean_constant_value(val); } + // If this is a const reference expression, return the named + // object to which the expression refers, otherwise return NULL. + const Named_object* + named_constant() const; + // This is called if the value of this expression is being // discarded. This issues warnings about computed values being // unused. This returns true if all is well, false if it issued an