[clang] [clang][dataflow] Add basic modeling for compound assignments. (PR #179058)
Yitzhak Mandelbaum via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 10 06:34:04 PDT 2026
================
@@ -155,38 +155,40 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
const Expr *RHS = S->getRHS();
assert(RHS != nullptr);
- // Do compound assignments up-front, as there are so many of them and we
- // don't want to list all of them in the switch statement below.
- // To avoid generating unnecessary values, we don't create a new value but
- // instead leave it to the specific analysis to do this if desired.
- if (S->isCompoundAssignmentOp())
- propagateStorageLocation(*S->getLHS(), *S, Env);
-
- switch (S->getOpcode()) {
- case BO_Assign: {
+ // Do assignments and compound assignments up-front, as there are
+ // so many of them and we don't want to list all of them in
+ // the switch statement below.
+ if (S->isAssignmentOp()) {
auto *LHSLoc = Env.getStorageLocation(*LHS);
if (LHSLoc == nullptr)
- break;
+ return;
- auto *RHSVal = Env.getValue(*RHS);
+ // Assign a storage location for the whole expression.
+ Env.setStorageLocation(*S, *LHSLoc);
+
+ // Compound assignments involve arithmetic we don't model yet.
+ // Regular assignments preserve the value so they're easy.
+ Value *RHSVal =
+ S->isCompoundAssignmentOp() ? nullptr : Env.getValue(*RHS);
if (RHSVal == nullptr) {
+ // Either way, we need to conjure a value if we don't have any so that
+ // future lookups into that locations produced consistent results.
----------------
ymand wrote:
```suggestion
// future lookups into that location produce consistent results.
```
https://github.com/llvm/llvm-project/pull/179058
More information about the cfe-commits
mailing list