[clang] [clang][dataflow] Fix assignment of unknown values. (PR #178943)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 30 11:57:53 PST 2026


================
@@ -170,7 +170,7 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
 
       auto *RHSVal = Env.getValue(*RHS);
       if (RHSVal == nullptr)
-        break;
+        RHSVal = Env.createValue(LHS->getType());
----------------
ymand wrote:

> I haven't quite figured out what exactly does a null value represents. Is it, like, "unimplemented"? If yes, creating a new value is probably better.

Sorry -- we really should have a dev guide for Clang Dataflow. Yes, it represents "unmodeled". It's an incomplete part of the system, which can have assorted causes. Our general approach is to on-demand create values in these cases (that is, wait until a point where have a fresh/blank value will be useful), but I don't believe we have a hard and fast rule. But, as your test demonstrates, the current behavior is definitely wrong. 

I'm somewhat inclined towards your choice, because it means that we'll have consistent reasoning is this simple case:

```
      Foo = unknown();
      int FooAtB = Foo;

      if (cond()) {
         // something involving FooAtB 
      } else {
         // something else involving FooAtB 
      }
```
With your current approach, a fresh value is populated and the branches will consider the same fresh value. otherwise, anything that on-demand introduces the value used by FooAtB, will result in separate copies for the two branches.

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


More information about the cfe-commits mailing list