diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-14 10:36:09 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-14 11:21:20 +0100 |
commit | 02887c88f57834e3c5b20e98e15710fc7e43562d (patch) | |
tree | 7a0a4ed8a76d10db85fd6b6d3ee34d752095d1b4 /gcc/rust/expand/rust-macro-expand.h | |
parent | 41f402f0b19c7e4f19f8d4d65d15223d2752f302 (diff) | |
download | gcc-02887c88f57834e3c5b20e98e15710fc7e43562d.zip gcc-02887c88f57834e3c5b20e98e15710fc7e43562d.tar.gz gcc-02887c88f57834e3c5b20e98e15710fc7e43562d.tar.bz2 |
macros: Do not try and re-expand if depth has exceeded recursion limit
We need to limit the amount of times that macro get expanded recursively
during macro-expansion. This limits the amount of times an ASTFragment
can be visited by simply incrementing the depth when setting a fragment,
and decreasing it when taking one. This way, recursive expansion which
happens at the expansion level (instead of the matching level) will
still get caught
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index 4efcd7b..0d0282e 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -287,11 +287,18 @@ struct MacroExpander expanded_fragment = std::move (fragment); } - AST::ASTFragment take_expanded_fragment () + AST::ASTFragment take_expanded_fragment (AST::ASTVisitor &vis) { AST::ASTFragment old_fragment = std::move (expanded_fragment); expanded_fragment = AST::ASTFragment::create_empty (); + for (auto &node : old_fragment.get_nodes ()) + { + expansion_depth++; + node.accept_vis (vis); + expansion_depth--; + } + return old_fragment; } |