[clang] [clang][dataflow] Add `Environment::initializeFieldsWithValues()`. (PR #81239)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 09:20:59 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());
----------------
Xazax-hun wrote:
Minor nit: Maybe we can save a lookup here. The insert above should return an iterator, so we should be able to remove the element using that iterator.
https://github.com/llvm/llvm-project/pull/81239
More information about the cfe-commits
mailing list