Skip to content

[clang][dataflow] Tighten checking for existence of a function body. #78163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace dataflow {
class ControlFlowContext {
public:
/// Builds a ControlFlowContext from a `FunctionDecl`.
/// `Func.hasBody()` must be true, and `Func.isTemplated()` must be false.
/// `Func.doesThisDeclarationHaveABody()` must be true, and
/// `Func.isTemplated()` must be false.
static llvm::Expected<ControlFlowContext> build(const FunctionDecl &Func);

/// Builds a ControlFlowContext from an AST node. `D` is the function in which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class Environment {
///
/// Requirements:
///
/// The function must have a body.
/// The function must have a body, i.e.
/// `FunctionDecl::doesThisDecalarationHaveABody()` must be true.
void initialize();

/// Returns a new environment that is a copy of this one.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static llvm::BitVector findReachableBlocks(const CFG &Cfg) {

llvm::Expected<ControlFlowContext>
ControlFlowContext::build(const FunctionDecl &Func) {
if (!Func.hasBody())
if (!Func.doesThisDeclarationHaveABody())
return llvm::createStringError(
std::make_error_code(std::errc::invalid_argument),
"Cannot analyze function without a body");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ DataflowAnalysisContext::getControlFlowContext(const FunctionDecl *F) {
if (It != FunctionContexts.end())
return &It->second;

if (F->hasBody()) {
if (F->doesThisDeclarationHaveABody()) {
auto CFCtx = ControlFlowContext::build(*F);
// FIXME: Handle errors.
assert(CFCtx);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void Environment::initialize() {
return;

if (const auto *FuncDecl = dyn_cast<FunctionDecl>(DeclCtx)) {
assert(FuncDecl->getBody() != nullptr);
assert(FuncDecl->doesThisDeclarationHaveABody());

initFieldsGlobalsAndFuncs(FuncDecl);

Expand Down Expand Up @@ -426,7 +426,7 @@ void Environment::initialize() {
// FIXME: Add support for resetting globals after function calls to enable
// the implementation of sound analyses.
void Environment::initFieldsGlobalsAndFuncs(const FunctionDecl *FuncDecl) {
assert(FuncDecl->getBody() != nullptr);
assert(FuncDecl->doesThisDeclarationHaveABody());

FieldSet Fields;
llvm::DenseSet<const VarDecl *> Vars;
Expand Down