[PATCH] D151183: [clang][dataflow] Add a `ControlFlowContext::build()` overload taking a `FunctionDecl`.
Martin Böhme via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 25 00:19:33 PDT 2023
This revision was automatically updated to reflect the committed changes.
mboehme marked an inline comment as done.
Closed by commit rG246626a8cfd3: [clang][dataflow] Add a `ControlFlowContext::build()` overload taking a… (authored by mboehme).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151183/new/
https://reviews.llvm.org/D151183
Files:
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -67,8 +67,8 @@
Stmt *Body = Func->getBody();
assert(Body != nullptr);
- auto CFCtx = llvm::cantFail(
- ControlFlowContext::build(*Func, *Body, AST->getASTContext()));
+ auto CFCtx =
+ llvm::cantFail(ControlFlowContext::build(*Func, AST->getASTContext()));
AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
DataflowAnalysisContext DACtx(std::make_unique<WatchedLiteralsSolver>());
Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===================================================================
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -241,8 +241,7 @@
llvm::errc::invalid_argument, "Could not find the target function.");
// Build the control flow graph for the target function.
- auto MaybeCFCtx =
- ControlFlowContext::build(*Target, *Target->getBody(), Context);
+ auto MaybeCFCtx = ControlFlowContext::build(*Target, Context);
if (!MaybeCFCtx) return MaybeCFCtx.takeError();
auto &CFCtx = *MaybeCFCtx;
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -210,8 +210,8 @@
if (It != FunctionContexts.end())
return &It->second;
- if (Stmt *Body = F->getBody()) {
- auto CFCtx = ControlFlowContext::build(*F, *Body, F->getASTContext());
+ if (F->hasBody()) {
+ auto CFCtx = ControlFlowContext::build(*F, F->getASTContext());
// FIXME: Handle errors.
assert(CFCtx);
auto Result = FunctionContexts.insert({F, std::move(*CFCtx)});
Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===================================================================
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,6 +67,16 @@
return BlockReachable;
}
+llvm::Expected<ControlFlowContext>
+ControlFlowContext::build(const FunctionDecl &Func, ASTContext &C) {
+ if (!Func.hasBody())
+ return llvm::createStringError(
+ std::make_error_code(std::errc::invalid_argument),
+ "Cannot analyze function without a body");
+
+ return build(Func, *Func.getBody(), C);
+}
+
llvm::Expected<ControlFlowContext>
ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext &C) {
if (D.isTemplated())
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -31,6 +31,11 @@
/// analysis.
class ControlFlowContext {
public:
+ /// Builds a ControlFlowContext from a `FunctionDecl`.
+ /// `Func.hasBody()` must be true, and `Func.isTemplated()` must be false.
+ static llvm::Expected<ControlFlowContext> build(const FunctionDecl &Func,
+ ASTContext &C);
+
/// Builds a ControlFlowContext from an AST node. `D` is the function in which
/// `S` resides. `D.isTemplated()` must be false.
static llvm::Expected<ControlFlowContext> build(const Decl &D, Stmt &S,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151183.525464.patch
Type: text/x-patch
Size: 3659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230525/440995dd/attachment.bin>
More information about the cfe-commits
mailing list