[clang][dataflow][NFC] Refine names and comments for field filtering.
authorYitzhak Mandelbaum <yitzhakm@google.com>
Mon, 9 Jan 2023 20:13:16 +0000 (20:13 +0000)
committerYitzhak Mandelbaum <yitzhakm@google.com>
Tue, 10 Jan 2023 14:28:45 +0000 (14:28 +0000)
Tweaks elements of the new API for filtering the set of modeled fields.

Differential Revision: https://reviews.llvm.org/D141319

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

index cd4a482..72ddfbb 100644 (file)
@@ -269,8 +269,6 @@ public:
   /// returns null.
   const ControlFlowContext *getControlFlowContext(const FunctionDecl *F);
 
-  void addFieldsReferencedInScope(llvm::DenseSet<const FieldDecl *> Fields);
-
   const Options &getOptions() { return Opts; }
 
 private:
@@ -287,8 +285,11 @@ private:
     using DenseMapInfo::isEqual;
   };
 
-  /// Returns the subset of fields of `Type` that are referenced in the scope of
-  /// the analysis.
+  // Extends the set of modeled field declarations.
+  void addModeledFields(const llvm::DenseSet<const FieldDecl *> &Fields);
+
+  /// Returns the fields of `Type`, limited to the set of fields modeled by this
+  /// context.
   llvm::DenseSet<const FieldDecl *> getReferencedFields(QualType Type);
 
   /// Adds all constraints of the flow condition identified by `Token` and all
@@ -388,8 +389,8 @@ private:
 
   llvm::DenseMap<const FunctionDecl *, ControlFlowContext> FunctionContexts;
 
-  // All fields referenced (statically) in the scope of the analysis.
-  llvm::DenseSet<const FieldDecl *> FieldsReferencedInScope;
+  // Fields modeled by environments covered by this context.
+  llvm::DenseSet<const FieldDecl *> ModeledFields;
 };
 
 } // namespace dataflow
index 4632305..480606b 100644 (file)
 namespace clang {
 namespace dataflow {
 
-void DataflowAnalysisContext::addFieldsReferencedInScope(
-    llvm::DenseSet<const FieldDecl *> Fields) {
-  llvm::set_union(FieldsReferencedInScope, Fields);
+void DataflowAnalysisContext::addModeledFields(
+    const llvm::DenseSet<const FieldDecl *> &Fields) {
+  llvm::set_union(ModeledFields, Fields);
 }
 
 llvm::DenseSet<const FieldDecl *>
 DataflowAnalysisContext::getReferencedFields(QualType Type) {
   llvm::DenseSet<const FieldDecl *> Fields = getObjectFields(Type);
-  llvm::set_intersect(Fields, FieldsReferencedInScope);
+  llvm::set_intersect(Fields, ModeledFields);
   return Fields;
 }
 
@@ -46,7 +46,7 @@ StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
     // the allocation. Since we only collect fields used in the function where
     // the allocation occurs, we can't apply that filter when performing
     // context-sensitive analysis. But, this only applies to storage locations,
-    // since fields access it not allowed to fail. In contrast, field *values*
+    // since field access it not allowed to fail. In contrast, field *values*
     // don't need this allowance, since the API allows for uninitialized fields.
     auto Fields = Opts.ContextSensitiveOpts ? getObjectFields(Type)
                                             : getReferencedFields(Type);
index c4c3d0b..7d10a75 100644 (file)
@@ -253,7 +253,7 @@ Environment::Environment(DataflowAnalysisContext &DACtx,
     initVars(Vars);
     // These have to be set before the lines that follow to ensure that create*
     // work correctly for structs.
-    DACtx.addFieldsReferencedInScope(std::move(Fields));
+    DACtx.addModeledFields(Fields);
 
     for (const auto *ParamDecl : FuncDecl->parameters()) {
       assert(ParamDecl != nullptr);
@@ -342,7 +342,7 @@ void Environment::pushCallInternal(const FunctionDecl *FuncDecl,
   }
   getFieldsAndGlobalVars(*FuncDecl->getBody(), Fields, Vars);
   initVars(Vars);
-  DACtx->addFieldsReferencedInScope(std::move(Fields));
+  DACtx->addModeledFields(Fields);
 
   const auto *ParamIt = FuncDecl->param_begin();