This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add a `ControlFlowContext::build()` overload taking a `FunctionDecl`.
ClosedPublic

Authored by mboehme on May 23 2023, 12:32 AM.

Details

Summary

This is the most common use case, so it makes sense to have a specific overload for it.

Diff Detail

Event Timeline

mboehme created this revision.May 23 2023, 12:32 AM
Herald added a project: Restricted Project. · View Herald Transcript
mboehme requested review of this revision.May 23 2023, 12:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 12:32 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mboehme edited the summary of this revision. (Show Details)May 23 2023, 12:32 AM
mboehme added a reviewer: gribozavr2.
xazax.hun accepted this revision.May 24 2023, 7:54 PM
xazax.hun added inline comments.
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
39

I was wondering if there is a plan to make the framework work for non-functions, like global initializers.

This revision is now accepted and ready to land.May 24 2023, 7:54 PM
mboehme marked an inline comment as done.May 25 2023, 12:02 AM
mboehme added inline comments.
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
39

I believe there may be? I remember talking to someone who mentioned this -- I don't know, it might have been you?

This is, really, the only reason I can see for having an overload that takes a separate Stmt. It doesn't really make sense (I think) to pass a FunctionDecl to this overload and then pass some Stmt that isn't the complete function body. (I can't think of any good scenarios where the control flow wouldn't escape that Stmt, and I don't see any good use cases anyway.) So I've been assuming that this overload is there for global initializers. Confusingly, the comment says that D should be a function, but notably, D is a Decl, not a FunctionDecl -- so I think the comment is wrong here.

Anyway, I'll try and get some more insights into this, but until then, I'll certainly keep this overload in place.

This revision was automatically updated to reflect the committed changes.
mboehme marked an inline comment as done.
chapuni added inline comments.
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
71

This was the only user of Body in -Asserts

mboehme marked an inline comment as done.May 25 2023, 5:10 AM
mboehme added inline comments.
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
71

Thanks for pointing this out. Fixed in https://reviews.llvm.org/D151430.