Rust: adapt BadCtorInitialization.ql to attribute macro expansion

This commit is contained in:
Paolo Tranquilli
2025-05-16 16:14:51 +02:00
parent c046a306ba
commit 32cece3a43

View File

@@ -44,9 +44,18 @@ class PathElement = AstNode;
* reachable from a source.
*/
predicate edgesFwd(PathElement pred, PathElement succ) {
// attribute (source) -> callable
pred.(CtorAttr) = succ.(Callable).getAnAttr()
// attribute (source) -> function in macro expansion
exists(Function f |
pred.(CtorAttr) = f.getAnAttr() and
(
f.getAttributeMacroExpansion().getAnItem() = succ.(Callable)
or
// if for some reason the ctor/dtor macro expansion failed, fall back to looking into the unexpanded item
not f.hasAttributeMacroExpansion() and f = succ.(Callable)
)
)
or
// callable -> callable attribute macro expansion
// [forwards reachable] callable -> enclosed call
edgesFwd(_, pred) and
pred = succ.(CallExprBase).getEnclosingCallable()