[clang] [dataflow] CXXOperatorCallExpr equal operator might not be a glvalue (PR #80991)

Paul Semel via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 07:33:25 PST 2024


================
@@ -535,7 +535,19 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
         return;
 
       copyRecord(*LocSrc, *LocDst, Env);
-      Env.setStorageLocation(*S, *LocDst);
+
+      // If the expr is a glvalue, we can reasonably assume the operator is
+      // returning T& and thus we can assign it `LocDst`.
+      if (S->isGLValue()) {
+        Env.setStorageLocation(*S, *LocDst);
+      } else if (S->getType()->isRecordType() && S->isPRValue()) {
+        // If the expr is a prvalue, we cannot really assume anything regarding
+        // the new value being created. We should just propagate it to ensure a
+        // `RecordValue` exist for it.
+        if (Env.getValue(*S) == nullptr)
+          refreshRecordValue(*S, Env);
----------------
paulsemel wrote:

Yes, similarly to `TransferCallExpr`, it ensures a `RecordValue` exists. This is just a short path for not having to call `TransferCallExpr`, since it is pretty much the only thing that will trigger if being called.

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


More information about the cfe-commits mailing list