This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add support for global storage values
ClosedPublic

Authored by sgatev on Feb 18 2022, 10:54 AM.

Details

Summary

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Diff Detail

Event Timeline

sgatev created this revision.Feb 18 2022, 10:54 AM
sgatev requested review of this revision.Feb 18 2022, 10:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 18 2022, 10:54 AM
ymandel accepted this revision.Feb 18 2022, 11:50 AM
ymandel added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
74–77
80

maybe clarify that it intializes both declarations that are present *in* the substatements and those referenced *from* the sub statements?

clang/lib/Analysis/FlowSensitive/Transfer.cpp
140
305

should this be in the else branch? As is, Loc looks unused if the condition is true.

This revision is now accepted and ready to land.Feb 18 2022, 11:50 AM
sgatev updated this revision to Diff 410014.Feb 18 2022, 1:42 PM
sgatev marked 3 inline comments as done.

Address reviewers' comments.

sgatev marked an inline comment as done.Feb 18 2022, 1:42 PM
sgatev added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
80

Updated.

clang/lib/Analysis/FlowSensitive/Transfer.cpp
305

Yeap, moved it.

Shouldn't there be a functionality to invalidate all the globals at every function call by default?

clang/lib/Analysis/FlowSensitive/Transfer.cpp
141

Do we expect to ever see a global declaration in a transfer function? Or is this for static locals? If it is for the latter, I'd adjust the comment.

sgatev marked 2 inline comments as done.Feb 18 2022, 4:11 PM

I think we should provide such functionality and it probably should also apply to some of the pointer and reference values. Not sure what the default should be, but having the ability to choose the level of soundness for certain analyses is valuable so I think both options should be possible. We don't have that implemented yet and I think it might be better to consider this together with other improvements that we want to make such as lazy value initialization. Would you be ok with deferring this for now? I noted it with a FIXME in the code.

clang/lib/Analysis/FlowSensitive/Transfer.cpp
141

It's for static locals. Updated the comment.

sgatev updated this revision to Diff 410041.Feb 18 2022, 4:12 PM
sgatev marked an inline comment as done.

Address reviewers' comments.

I think we should provide such functionality and it probably should also apply to some of the pointer and reference values. Not sure what the default should be, but having the ability to choose the level of soundness for certain analyses is valuable so I think both options should be possible. We don't have that implemented yet and I think it might be better to consider this together with other improvements that we want to make such as lazy value initialization. Would you be ok with deferring this for now? I noted it with a FIXME in the code.

I think the default should be as sound as reasonably possible. If we don't do any invalidations, I'd like to see some sort of warning somewhere so early users are aware of the behavior. I'm not sure what is the best place to put the warning, maybe to the documentation of a class? With that warning in place, I think it is ok to commit this.

xazax.hun accepted this revision.Feb 22 2022, 10:03 AM
sgatev updated this revision to Diff 410580.Feb 22 2022, 10:20 AM

Address reviewers' comments.

This revision was automatically updated to reflect the committed changes.