aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-05-17 14:01:19 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-05-17 14:04:34 +0200
commit7ebe376bd68eb0d9aae9cef6308f3ec15407862d (patch)
treebd548a4c5f4b4a1e250e4157fc65fc85325d9563 /gcc
parent8cad07cfd2244ad9a40027a4306b81b4553a4797 (diff)
downloadgcc-7ebe376bd68eb0d9aae9cef6308f3ec15407862d.zip
gcc-7ebe376bd68eb0d9aae9cef6308f3ec15407862d.tar.gz
gcc-7ebe376bd68eb0d9aae9cef6308f3ec15407862d.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/privacy/rust-privacy-reporter.cc19
-rw-r--r--gcc/testsuite/rust/compile/privacy2.rs13
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 4c18adb..a974de0 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 0000000..3c07449
--- /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();
+ }
+ }
+ }
+}