Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ class DataflowAnalysisContext {
SyntheticFieldCallback = CB;
}

void setInitializerCallback(
std::function<void(QualType, StorageLocation&)> CB) {
assert(!RecordStorageLocationCreated);
InitializerCallback = CB;
}

/// Returns a new storage location appropriate for `Type`.
///
/// A null `Type` is interpreted as the pointee type of `std::nullptr_t`.
Expand Down Expand Up @@ -332,6 +338,7 @@ class DataflowAnalysisContext {
std::unique_ptr<Logger> LogOwner; // If created via flags.

std::function<llvm::StringMap<QualType>(QualType)> SyntheticFieldCallback;
std::optional<std::function<void(QualType, StorageLocation&)>> InitializerCallback;

/// Has any `RecordStorageLocation` been created yet?
bool RecordStorageLocationCreated = false;
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void DataflowAnalysisContext::addModeledFields(const FieldSet &Fields) {
}

StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
StorageLocation *S;
if (!Type.isNull() && Type->isRecordType()) {
llvm::DenseMap<const ValueDecl *, StorageLocation *> FieldLocs;
for (const FieldDecl *Field : getModeledFields(Type))
Expand All @@ -74,10 +75,14 @@ StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
{Entry.getKey(),
&createStorageLocation(Entry.getValue().getNonReferenceType())});

return createRecordStorageLocation(Type, std::move(FieldLocs),
S = &createRecordStorageLocation(Type, std::move(FieldLocs),
std::move(SyntheticFields));
} else {
S = &arena().create<ScalarStorageLocation>(Type);
}
return arena().create<ScalarStorageLocation>(Type);
if (InitializerCallback)
(*InitializerCallback)(Type, *S);
return *S;
}

// Returns the keys for a given `StringMap`.
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.