================
@@ -705,6 +713,30 @@ void MoveChecker::checkPreCall(const CallEvent &Call, 
CheckerContext &C) const {
     }
   }
 
+  // Calls to explicit-object member functions are represented as ordinary
+  // function calls because they have no implicit 'this' argument.  Model an
+  // explicit-object assignment here before handling instance calls below.
+  const auto *ExplicitObjectMethod =
+      dyn_cast_or_null<CXXMethodDecl>(Call.getDecl());
+  if (ExplicitObjectMethod &&
+      ExplicitObjectMethod->isExplicitObjectMemberFunction() &&
+      ExplicitObjectMethod->getOverloadedOperator() == OO_Equal) {
+    const MemRegion *ThisRegion = Call.getArgSVal(0).getAsRegion();
+    State = removeFromState(State, ThisRegion);
+
+    if (ExplicitObjectMethod->isCopyAssignmentOperator() ||
+        ExplicitObjectMethod->isMoveAssignmentOperator()) {
+      const MemRegion *ArgRegion = Call.getArgSVal(1).getAsRegion();
+      const CXXRecordDecl *RD = ExplicitObjectMethod->getParent();
+      MisuseKind MK =
+          ExplicitObjectMethod->isMoveAssignmentOperator() ? MK_Move : MK_Copy;
+      modelUse(State, ArgRegion, RD, MK, C);
+      return;
+    }
+    C.addTransition(State);
+    return;
+  }
----------------
SekaiArendelle wrote:

Good point — I moved the block after the MethodDecl lookup and reused the same 
variable.

I don’t think modeling explicit-object calls as CXXInstanceCall would simplify 
this patch. CXXInstanceCall assumes an implicit object argument, whereas an 
explicit object parameter is an ordinary argument; notably, `this T self` gets 
a distinct temporary region. The current handling supports both reference and 
by-value object parameters, and I’ve added a regression
test for the latter.

https://github.com/llvm/llvm-project/pull/218303
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to