diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h index cd4a48243785bc..72ddfbb780f178 100644 --- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h +++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h @@ -269,8 +269,6 @@ class DataflowAnalysisContext { /// returns null. const ControlFlowContext *getControlFlowContext(const FunctionDecl *F); - void addFieldsReferencedInScope(llvm::DenseSet Fields); - const Options &getOptions() { return Opts; } private: @@ -287,8 +285,11 @@ class DataflowAnalysisContext { 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 &Fields); + + /// Returns the fields of `Type`, limited to the set of fields modeled by this + /// context. llvm::DenseSet getReferencedFields(QualType Type); /// Adds all constraints of the flow condition identified by `Token` and all @@ -388,8 +389,8 @@ class DataflowAnalysisContext { llvm::DenseMap FunctionContexts; - // All fields referenced (statically) in the scope of the analysis. - llvm::DenseSet FieldsReferencedInScope; + // Fields modeled by environments covered by this context. + llvm::DenseSet ModeledFields; }; } // namespace dataflow diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp index 463230516185f0..480606bdac8d85 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp @@ -25,15 +25,15 @@ namespace clang { namespace dataflow { -void DataflowAnalysisContext::addFieldsReferencedInScope( - llvm::DenseSet Fields) { - llvm::set_union(FieldsReferencedInScope, Fields); +void DataflowAnalysisContext::addModeledFields( + const llvm::DenseSet &Fields) { + llvm::set_union(ModeledFields, Fields); } llvm::DenseSet DataflowAnalysisContext::getReferencedFields(QualType Type) { llvm::DenseSet 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); diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index c4c3d0be229cd3..7d10a75b36e3e4 100644 --- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp +++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp @@ -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();