Skip to content

Commit 2b2d229

Browse files
committed
transpile: keep cleanup-attribute targets alive through decl pruning
1 parent 56fa410 commit 2b2d229

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • c2rust-transpile/src/c_ast

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,20 @@ impl TypedAstContext {
12021202
to_walk.push(parent_id);
12031203
}
12041204
}
1205+
1206+
// `__attribute__((cleanup(func)))` references its cleanup
1207+
// function through the attribute payload, not via a
1208+
// DeclRef the traversal would otherwise see, so mark it
1209+
// here.
1210+
if let CDeclKind::Variable { ref attrs, .. } = self.c_decls[&decl_id].kind {
1211+
for attr in attrs {
1212+
if let Attribute::Cleanup(fn_id) = attr {
1213+
if wanted.insert(*fn_id) {
1214+
to_walk.push(*fn_id);
1215+
}
1216+
}
1217+
}
1218+
}
12051219
}
12061220

12071221
// Stmts can include decls, but we'll see the DeclId itself in a later

0 commit comments

Comments
 (0)