TsXor wrote:

I still think we can still do something to stop #101548 from happening again. 
Here is a script that can locate all `conf.lib.*` calls and find if any of them 
use an undeclared symbol in `functionList`. Maybe we can add it to test.
```python
import ast
from typing import Optional, Set
from clang import cindex


class CCallVisitor(ast.NodeVisitor):
    lib_node: str
    attr_set: Set[str]
    missing_attr: list[str]

    def __init__(self, lib_node: str, attr_set: Set[str]):
        self.lib_node = lib_node
        self.attr_set = attr_set
        self.missing_attr = []

    def check_target_call(self, node: ast.expr) -> Optional[str]:
        if not isinstance(node, ast.Attribute):
            return None
        if ast.unparse(node.value) != self.lib_node:
            return None
        return node.attr

    def visit_Call(self, node: ast.Call) -> None:
        attr = self.check_target_call(node.func)
        if attr is not None and attr not in self.attr_set:
            self.missing_attr.append(attr)


with open(cindex.__file__, 'rt') as modfp:
    modtxt = modfp.read()
modast = ast.parse(modtxt, mode='exec')

func_checker = CCallVisitor(
    'conf.lib',
    {fn[0] for fn in cindex.functionList},
)
func_checker.visit(modast)
print(func_checker.missing_attr)
```

https://github.com/llvm/llvm-project/pull/101941
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to