Skip to content

Commit 8d294d2

Browse files
committed
transpile: add guards to stop cycles when build w/ clang-22
1 parent 8fb4cf5 commit 8d294d2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

c2rust-transpile/src/c_ast/iterators.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,15 @@ impl<'context> Iterator for DFExpr<'context> {
377377
pub struct DFNodes<'context> {
378378
context: &'context TypedAstContext,
379379
stack: Vec<SomeId>,
380+
visited: HashSet<SomeId>,
380381
}
381382

382383
impl<'context> DFNodes<'context> {
383384
pub fn new(context: &'context TypedAstContext, start: SomeId) -> Self {
384385
DFNodes {
385386
context,
386387
stack: vec![start],
388+
visited: <_>::from([start]),
387389
}
388390
}
389391
pub fn prune(&mut self, n: usize) {
@@ -401,7 +403,12 @@ impl<'context> Iterator for DFNodes<'context> {
401403
// Compute list of immediate children
402404
let children = immediate_children_all_types(self.context, i);
403405
// Add children in reverse order since we visit the end of the stack first
404-
self.stack.extend(children.into_iter().rev())
406+
self.stack.extend(
407+
children
408+
.into_iter()
409+
.rev()
410+
.filter(|child| self.visited.insert(*child)),
411+
)
405412
}
406413

407414
result
@@ -437,8 +444,9 @@ pub trait NodeVisitor {
437444
/// method afterward.
438445
fn visit_tree(&mut self, root: SomeId) {
439446
let mut stack = vec![VisitNode::new(root)];
447+
let mut visited = HashSet::new();
440448
while let Some(mut node) = stack.pop() {
441-
if !node.seen {
449+
if !node.seen && visited.insert(node.id) {
442450
let id = node.id;
443451
node.seen = true;
444452
stack.push(node);

0 commit comments

Comments
 (0)