From patchwork Thu May 19 02:34:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1633045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Ay+NA7b0; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3Yqx6Jmwz9vFL for ; Thu, 19 May 2022 12:35:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53CCD385624E for ; Thu, 19 May 2022 02:35:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53CCD385624E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652927733; bh=mAjhim1L0jT3br4gYej3m4oQVJQcwQb2Fjzvtbd0Y5M=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Ay+NA7b0us9outBT01eZj3vlUBuOGxRVST92vDPXocLKXbRhQKl1F+6djzJQ3zJbQ lFIOes1SSuE6Sp66l9+5fs6aQ9yHa6Yx6ZkKj0tok+7u4nHjdoQiIVkew/Y5Pzro86 XQY5B2JRvMs+u0KzQJDvFKAApD8EqLfgAvuDOprk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id C9626385B801 for ; Thu, 19 May 2022 02:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9626385B801 Received: by mail-ed1-x52f.google.com with SMTP id fd25so5302596edb.3 for ; Wed, 18 May 2022 19:35:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=mAjhim1L0jT3br4gYej3m4oQVJQcwQb2Fjzvtbd0Y5M=; b=YEtwCleGt+2u5Glg814g6D9v05LOp8Bm48x4OPJX5zL7tcFmoM/LnQG0lbIkgzNPyk IOR85orPozUyaW2kq14vbl8fuESQSsO40Gs6FkU4PpsN6G64vwgfP74diuyANp1x/jeq BZuSPbwLjZZ0Y5+2VfqcaMslmoZS17jf83UY9VWrxPg0+2G4N/dWDWmhQgnVo2zItkn6 0T052rU/UsC/CsOdhuM9A/tACeS8dgNKSqzwEABm+K3AeiMubgBB6TP1QtFQzFUPiFcK tB84okXbBnhUljuLcNY1xeoEJ9unE/3iDhmlRrlMVIYCuHV1cgA+G3ublQ9v0l8OMLZ4 N1GQ== X-Gm-Message-State: AOAM532IoFOn54u21B5j+JUxHjE5/zETeKFsS1V+/tK7oc2i1TWfW4wn MWzu1XB6401q5TsouRd/ZsHrpm6UScMKSAQwi6GlKfczFP5Rrw== X-Google-Smtp-Source: ABdhPJzDBO253fAEjeWFPNWTWHNc7QLGtMzcqQ422YqtjBfyJyBR5KpYs5I8jmnjaexw9IkH3VmvMrFrUbw5q1sxbCQ= X-Received: by 2002:a05:6402:1341:b0:42a:f7cb:44dc with SMTP id y1-20020a056402134100b0042af7cb44dcmr1592191edw.165.1652927709983; Wed, 18 May 2022 19:35:09 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 18 May 2022 19:34:58 -0700 Message-ID: Subject: Go patch committed: Traverse expressions with exporting consts To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch to the Go frontend by Julia Lapenko traverses expressions when exporting constants. When exporting a constant A that is expressed through a constant B from another package, it is necessary to traverse an expression representing the constant A to generate a sequence of type casts from the constant B. Before this patch the frontend didn't collect types of constants contained in such expressions. This change fetches these types. This fixes https://go.dev/issue/51291. The test case is https://go.dev/cl/406916. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 4105b492d64412b03c3776b49f7663aa094a3f07 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 5fa8becde3e..2cf7141c4fa 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -9d07072e58ca4f9f05343dfd3475b9f49dae5ec5 +0058658a9efb6e5c5faa6f0f65949beea5ddbc98 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc index 70d3f708d32..a30b11af31e 100644 --- a/gcc/go/gofrontend/export.cc +++ b/gcc/go/gofrontend/export.cc @@ -124,6 +124,11 @@ class Collect_export_references : public Traverse void prepare_types(const std::vector& sorted_exports); + // Third entry point (called after the method above), to find + // all types in expressions referenced by exports. + void + prepare_expressions(const std::vector& sorted_exports); + protected: // Override of parent class method. int @@ -281,6 +286,28 @@ Collect_export_references::expression(Expression** pexpr) return TRAVERSE_CONTINUE; } +// Collect up the set of types mentioned in expressions of things we're exporting, +// and collect all the packages encountered during type traversal, to make sure +// we can declare things referered to indirectly (for example, in the body of an +// exported inline function from another package). + +void +Collect_export_references::prepare_expressions(const std::vector& sorted_exports) +{ + for (std::vector::const_iterator p = sorted_exports.begin(); + p != sorted_exports.end(); + ++p) + { + Named_object* no = *p; + if (no->classification() == Named_object::NAMED_OBJECT_CONST) + { + Expression* e = no->const_value()->expr(); + if (e != NULL) + Expression::traverse(&e, this); + } + } +} + // Collect up the set of types mentioned in things we're exporting, and collect // all the packages encountered during type traversal, to make sure we can // declare things referered to indirectly (for example, in the body of an @@ -891,6 +918,7 @@ Export::export_globals(const std::string& package_name, // Collect up the set of types mentioned in things we're exporting, // and any packages that may be referred to indirectly. collect.prepare_types(sorted_exports); + collect.prepare_expressions(sorted_exports); // Assign indexes to all exported types and types referenced by // things we're exporting. Return value is index of first non-exported