[clang] [clang][dataflow] Correctly handle `InitListExpr` of union type. (PR #82348)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 09:10:26 PST 2024


================
@@ -731,6 +723,18 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
       FieldLocs.insert({Field, &Loc});
     }
 
+    // In the case of a union, we don't in general have initializers for all
+    // of the fields. Create storage locations for the remaining fields (but
+    // don't associate them with values).
+    if (Type->isUnionType()) {
+      for (const FieldDecl *Field :
+           Env.getDataflowAnalysisContext().getModeledFields(Type)) {
+        if (!FieldLocs.contains(Field))
+          FieldLocs.insert(
----------------
Xazax-hun wrote:

Probably we could save a lookup if we did something like
```
if (auto [it, inserted] = FieldLocs.insert({Field, nullptr}); inserted)
  it->second = &Env.createStorageLocation(Field->getType());
```

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


More information about the cfe-commits mailing list