aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulia Lapenko <julia.lapenko@gmail.com>2022-05-16 10:37:49 +0300
committerIan Lance Taylor <iant@golang.org>2022-05-18 19:34:49 -0700
commitb8944f0438a183a0245ffe17aeaeaf3a1a00069c (patch)
tree479a7909cff1ed8753c874357248b16696809172
parent1cda629f96b4e982bb87343a35a6db39445d3962 (diff)
downloadgcc-b8944f0438a183a0245ffe17aeaeaf3a1a00069c.zip
gcc-b8944f0438a183a0245ffe17aeaeaf3a1a00069c.tar.gz
gcc-b8944f0438a183a0245ffe17aeaeaf3a1a00069c.tar.bz2
compiler: traverse 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. Current implementation doesn't collect types of constants contained in such expressions. This change fetches these types. Fixes golang/go#51291 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/405976
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/export.cc28
2 files changed, 29 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5fa8bec..2cf7141 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 70d3f70..a30b11a 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