aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
diff options
context:
space:
mode:
authorSamira Bazuzi <bazuzi@google.com>2024-04-16 14:46:05 -0400
committerGitHub <noreply@github.com>2024-04-16 14:46:05 -0400
commit9ec8c961664de3b3fcc1cbd5238e40ec8c9bdddb (patch)
tree129feadbf7806140c1a698fa8bbd98b1cbe6c9d8 /clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
parentb01879ec1ffbd249f9bf3c4f32308443be6ac36b (diff)
downloadllvm-9ec8c961664de3b3fcc1cbd5238e40ec8c9bdddb.zip
llvm-9ec8c961664de3b3fcc1cbd5238e40ec8c9bdddb.tar.gz
llvm-9ec8c961664de3b3fcc1cbd5238e40ec8c9bdddb.tar.bz2
[clang][dataflow] Expose getReferencedDecls and relocate free functions. (#88754)
Moves free functions from DataflowEnvironment.h/cc and DataflowAnalysisContext.h/cc to RecordOps and a new ASTOps and exposes them as needed for current use and to expose getReferencedDecls for out-of-tree use. Minimal change in functionality, only to modify the return type of getReferenceDecls to return the collected decls instead of using output params. Tested with `ninja check-clang-tooling`.
Diffstat (limited to 'clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp')
-rw-r--r--clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp53
1 files changed, 1 insertions, 52 deletions
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index d520539..e94fd39 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -14,6 +14,7 @@
#include "clang/Analysis/FlowSensitive/DataflowAnalysisContext.h"
#include "clang/AST/ExprCXX.h"
+#include "clang/Analysis/FlowSensitive/ASTOps.h"
#include "clang/Analysis/FlowSensitive/DebugSupport.h"
#include "clang/Analysis/FlowSensitive/Formula.h"
#include "clang/Analysis/FlowSensitive/Logger.h"
@@ -359,55 +360,3 @@ DataflowAnalysisContext::~DataflowAnalysisContext() = default;
} // namespace dataflow
} // namespace clang
-
-using namespace clang;
-
-const Expr &clang::dataflow::ignoreCFGOmittedNodes(const Expr &E) {
- const Expr *Current = &E;
- if (auto *EWC = dyn_cast<ExprWithCleanups>(Current)) {
- Current = EWC->getSubExpr();
- assert(Current != nullptr);
- }
- Current = Current->IgnoreParens();
- assert(Current != nullptr);
- return *Current;
-}
-
-const Stmt &clang::dataflow::ignoreCFGOmittedNodes(const Stmt &S) {
- if (auto *E = dyn_cast<Expr>(&S))
- return ignoreCFGOmittedNodes(*E);
- return S;
-}
-
-// FIXME: Does not precisely handle non-virtual diamond inheritance. A single
-// field decl will be modeled for all instances of the inherited field.
-static void getFieldsFromClassHierarchy(QualType Type,
- clang::dataflow::FieldSet &Fields) {
- if (Type->isIncompleteType() || Type->isDependentType() ||
- !Type->isRecordType())
- return;
-
- for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
- Fields.insert(Field);
- if (auto *CXXRecord = Type->getAsCXXRecordDecl())
- for (const CXXBaseSpecifier &Base : CXXRecord->bases())
- getFieldsFromClassHierarchy(Base.getType(), Fields);
-}
-
-/// Gets the set of all fields in the type.
-clang::dataflow::FieldSet clang::dataflow::getObjectFields(QualType Type) {
- FieldSet Fields;
- getFieldsFromClassHierarchy(Type, Fields);
- return Fields;
-}
-
-bool clang::dataflow::containsSameFields(
- const clang::dataflow::FieldSet &Fields,
- const clang::dataflow::RecordStorageLocation::FieldToLoc &FieldLocs) {
- if (Fields.size() != FieldLocs.size())
- return false;
- for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
- if (!Fields.contains(cast_or_null<FieldDecl>(Field)))
- return false;
- return true;
-}