public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@golang.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	 gofrontend-dev <gofrontend-dev@googlegroups.com>
Subject: Go patch committed: Traverse expressions with exporting consts
Date: Wed, 18 May 2022 19:34:58 -0700	[thread overview]
Message-ID: <CAOyqgcU+X=rxXq0chBgMkfgj5gVA2vE+snST7da25zWLOnP1Pg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 615 bytes --]

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

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2592 bytes --]

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<Named_object*>& 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<Named_object*>& 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<Named_object*>& sorted_exports)
+{
+  for (std::vector<Named_object*>::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

                 reply	other threads:[~2022-05-19  2:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOyqgcU+X=rxXq0chBgMkfgj5gVA2vE+snST7da25zWLOnP1Pg@mail.gmail.com' \
    --to=iant@golang.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).