[clang] [clang][dataflow] Handle more glvalue cases of the ConditionalOperator transfer (PR #168994)

Jan Voung via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 24 19:15:29 PST 2025


================
@@ -769,8 +769,29 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
       StorageLocation *TrueLoc = TrueEnv->getStorageLocation(*S->getTrueExpr());
       StorageLocation *FalseLoc =
           FalseEnv->getStorageLocation(*S->getFalseExpr());
-      if (TrueLoc == FalseLoc && TrueLoc != nullptr)
+      if (TrueLoc == FalseLoc && TrueLoc != nullptr) {
         Env.setStorageLocation(*S, *TrueLoc);
+      } else if (!S->getType()->isRecordType()) {
+        // Ideally, we would have something like an "alias set" to say that the
+        // result StorageLocation can be either of the locations from the
+        // TrueEnv or FalseEnv. Then, when this ConditionalOperator is
+        // (a) used in an LValueToRValue cast, the value is the join of all of
+        //     the values in the alias set.
+        // (b) or, used in an assignment to the resulting LValue, the assignment
+        //     *may* update all of the locations in the alias set.
+        // For now, we do the simpler thing of creating a new StorageLocation
+        // and joining the values right away, handling only case (a).
+        // Otherwise, the dataflow framework needs to be updated be able to
+        // represent alias sets and weak updates (for the "may").
+        StorageLocation &Loc = Env.createStorageLocation(*S);
+        Env.setStorageLocation(*S, Loc);
+        if (Value *Val = Environment::joinValues(
----------------
jvoung wrote:

Good point! Moved the create Loc and association into the branch.

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


More information about the cfe-commits mailing list