[clang] [dataflow] Fix crash when InitListExpr is not a prvalue (PR #80970)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 8 04:20:30 PST 2024


================
@@ -648,6 +648,12 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
     QualType Type = S->getType();
 
     if (!Type->isStructureOrClassType()) {
+      // It is possible that InitListExpr is not a prvalue, in which case
+      // `setValue` will fail. In this case, we can just let the next
+      // transfer function handle the value creation.
+      if (!S->isPRValue())
+        return;
+
       if (auto *Val = Env.createValue(Type))
         Env.setValue(*S, *Val);
 
----------------
martinboehme wrote:

Looking at this, I'm surprised that (in the existing prvalue case) we don't handle this better -- we should be able to propagate the actual value instead of creating a value from scratch.

I think you can handle both the prvalue and the glvalue case by simply doing this:

```suggestion
      assert(S->getNumInits() == 1);
      propagateValueOrStorageLocation(*S->getInit(0), *S, Env);
```

If this works, can you extend the test to verify that the value of `test` is `false`?

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


More information about the cfe-commits mailing list