[clang] [clang][dataflow] Add `Environment::initializeFieldsWithValues()`. (PR #81239)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 13 00:17:30 PST 2024


================
@@ -943,6 +919,50 @@ Environment::createLocAndMaybeValue(QualType Ty,
   return Loc;
 }
 
+void Environment::initializeFieldsWithValues(RecordStorageLocation &Loc,
+                                             llvm::DenseSet<QualType> &Visited,
+                                             int Depth,
+                                             int &CreatedValuesCount) {
+  auto initField = [&](QualType FieldType, StorageLocation &FieldLoc) {
+    if (FieldType->isRecordType()) {
+      auto &FieldRecordLoc = cast<RecordStorageLocation>(FieldLoc);
+      setValue(FieldRecordLoc, create<RecordValue>(FieldRecordLoc));
+      initializeFieldsWithValues(FieldRecordLoc, Visited, Depth + 1,
+                                 CreatedValuesCount);
+    } else {
+      if (!Visited.insert(FieldType.getCanonicalType()).second)
+        return;
+      if (Value *Val = createValueUnlessSelfReferential(
+              FieldType, Visited, Depth + 1, CreatedValuesCount))
+        setValue(FieldLoc, *Val);
+      Visited.erase(FieldType.getCanonicalType());
----------------
martinboehme wrote:

This doesn't, unfortunately, work, as `createValueUnlessSelfReferential()` may insert more entries into `Visited`, which would invalidate the iterator returned by `insert()`.

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


More information about the cfe-commits mailing list