Author: Yitzhak Mandelbaum Date: 2023-01-10T14:28:45Z New Revision: 089a54469f63c2f3c4b9d79fb9694f21bef0d071
URL: https://github.com/llvm/llvm-project/commit/089a54469f63c2f3c4b9d79fb9694f21bef0d071 DIFF: https://github.com/llvm/llvm-project/commit/089a54469f63c2f3c4b9d79fb9694f21bef0d071.diff LOG: [clang][dataflow][NFC] Refine names and comments for field filtering. Tweaks elements of the new API for filtering the set of modeled fields. Differential Revision: https://reviews.llvm.org/D141319 Added: Modified: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h index cd4a48243785b..72ddfbb780f17 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<const FieldDecl *> 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<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 @@ class DataflowAnalysisContext { 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 diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp index 463230516185f..480606bdac8d8 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<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); diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp index c4c3d0be229cd..7d10a75b36e3e 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(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits