[clang] [mutation analyzer] support mutation analysis for pointee (PR #118593)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 21 06:25:58 PST 2025


================
@@ -654,6 +716,83 @@ ExprMutationAnalyzer::Analyzer::findFunctionArgMutation(const Expr *Exp) {
   return nullptr;
 }
 
+const Stmt *
+ExprMutationAnalyzer::Analyzer::findPointeeValueMutation(const Expr *Exp) {
+  const auto Matches = match(
+      stmt(forEachDescendant(
+          expr(anyOf(
+                   // deref by *
+                   unaryOperator(hasOperatorName("*"),
+                                 hasUnaryOperand(canResolveToExprPointee(Exp))),
+                   // deref by []
+                   arraySubscriptExpr(hasBase(canResolveToExprPointee(Exp)))))
+              .bind(NodeID<Expr>::value))),
+      Stm, Context);
+  return findExprMutation(Matches);
+}
+
+const Stmt *
+ExprMutationAnalyzer::Analyzer::findPointeeMemberMutation(const Expr *Exp) {
----------------
HerrCai0907 wrote:

`CXXOperatorCallExpr` need to dereference firstly. It will be changed by other path.

```c++
struct A { int v; int operator++() const; };
void f() { A* x = nullptr; x->operator++(); }
```
ast looks like
```
    `-CXXMemberCallExpr 0x14811b898 <col:28, col:42> 'int'
      `-MemberExpr 0x14811b818 <col:28, col:39> '<bound member function type>' ->operator++ 0x1480fd088
        `-ImplicitCastExpr 0x14811b880 <col:28> 'const A *' <NoOp>
          `-ImplicitCastExpr 0x14811b800 <col:28> 'A *' <LValueToRValue>
            `-DeclRefExpr 0x1480fd3e0 <col:28> 'A *' lvalue Var 0x1480fd338 'x' 'A *'
```


https://github.com/llvm/llvm-project/pull/118593


More information about the cfe-commits mailing list