Skip to content

Commit 9d2c082

Browse files
committed
transpile: keep cleanup-attribute targets alive through decl pruning
1 parent 3593ecd commit 9d2c082

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
@@ -1191,6 +1191,20 @@ impl TypedAstContext {
11911191
to_walk.push(parent_id);
11921192
}
11931193
}
1194+
1195+
// `__attribute__((cleanup(func)))` references its cleanup
1196+
// function through the attribute payload, not via a
1197+
// DeclRef the traversal would otherwise see, so mark it
1198+
// here.
1199+
if let CDeclKind::Variable { ref attrs, .. } = self.c_decls[&decl_id].kind {
1200+
for attr in attrs {
1201+
if let Attribute::Cleanup(fn_id) = attr {
1202+
if wanted.insert(*fn_id) {
1203+
to_walk.push(*fn_id);
1204+
}
1205+
}
1206+
}
1207+
}
11941208
}
11951209

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

0 commit comments

Comments
 (0)