llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Florian Mayer (fmayer)

<details>
<summary>Changes</summary>

This is useful to make sure that a newly created StorageLocation always
has e.g. an uninitialized boolean.


---
Full diff: https://github.com/llvm/llvm-project/pull/164675.diff


2 Files Affected:

- (modified) 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h (+7) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
(+7-2) 


``````````diff
diff --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 11042e865c4e6..57dfabaa16212 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -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`.
@@ -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;
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 4196d6821c184..1b1b41f1f3160 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -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))
@@ -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`.

``````````

</details>


https://github.com/llvm/llvm-project/pull/164675
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to