public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] privacy: Handle calls to functions defined in previous ancestors
@ 2022-06-08 12:47 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7ebe376bd68eb0d9aae9cef6308f3ec15407862d
commit 7ebe376bd68eb0d9aae9cef6308f3ec15407862d
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Tue May 17 14:01:19 2022 +0200
privacy: Handle calls to functions defined in previous ancestors
Previously, we would only check if `current_module` was a direct
descendant of the item's module. However, we also need to visit each of this
item's module's children recursively.
Diff:
---
gcc/rust/privacy/rust-privacy-reporter.cc | 19 ++++++++++++-------
gcc/testsuite/rust/compile/privacy2.rs | 13 +++++++++++++
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/privacy/rust-privacy-reporter.cc b/gcc/rust/privacy/rust-privacy-reporter.cc
index 4c18adb8615..a974de039c7 100644
--- a/gcc/rust/privacy/rust-privacy-reporter.cc
+++ b/gcc/rust/privacy/rust-privacy-reporter.cc
@@ -20,15 +20,22 @@ PrivacyReporter::go (HIR::Crate &crate)
}
static bool
-is_child_module (NodeId current_module,
- Optional<std::vector<NodeId> &> children)
+is_child_module (Analysis::Mappings &mappings, NodeId parent,
+ NodeId possible_child)
{
+ auto children = mappings.lookup_module_children (parent);
+
if (!children)
return false;
- // FIXME: This checks for one step - we need to go deeper
+ // Visit all toplevel children
for (auto &child : *children)
- if (child == current_module)
+ if (child == possible_child)
+ return true;
+
+ // Now descend recursively in the child module tree
+ for (auto &child : *children)
+ if (is_child_module (mappings, child, possible_child))
return true;
return false;
@@ -72,11 +79,9 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
if (mod_node_id == current_module.get ())
break;
- auto children = mappings.lookup_module_children (mod_node_id);
-
// FIXME: This needs a LOT of TLC: hinting about the definition, a
// string to say if it's a module, function, type, etc...
- if (!is_child_module (current_module.get (), children))
+ if (!is_child_module (mappings, mod_node_id, current_module.get ()))
valid = false;
}
break;
diff --git a/gcc/testsuite/rust/compile/privacy2.rs b/gcc/testsuite/rust/compile/privacy2.rs
new file mode 100644
index 00000000000..3c0744928b1
--- /dev/null
+++ b/gcc/testsuite/rust/compile/privacy2.rs
@@ -0,0 +1,13 @@
+// { dg-additional-options "-w" }
+
+mod orange {
+ fn tangerine() {}
+
+ mod green {
+ mod blue {
+ fn berry() {
+ tangerine();
+ }
+ }
+ }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:47 [gcc/devel/rust/master] privacy: Handle calls to functions defined in previous ancestors Thomas Schwinge
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).