Page MenuHomePhabricator

[clang][dataflow] Store DeclContext of block being analysed in Environment if available.
ClosedPublic

Authored by wyt on Aug 3 2022, 4:09 AM.

Details

Summary

Allows propagation of information from the DeclContext into child nodes.

The use case which motivated this patch is the verification of the compatibility between the declared return type and the actual return type in a pointer nullability analysis. For example, we should not be returning a nullable pointer in a function which has _Nonnull annotated return type.
To retrieve the declared return type, we need to keep track of the FuncDecl (which is a DeclCtx) of the function body being analysed.

Diff Detail

Event Timeline

wyt created this revision.Aug 3 2022, 4:09 AM
Herald added a project: Restricted Project. · View Herald Transcript
wyt requested review of this revision.Aug 3 2022, 4:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 4:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
wyt edited the summary of this revision. (Show Details)Aug 3 2022, 4:18 AM
wyt added reviewers: hlopko, gribozavr2, sgatev, ymandel.
wyt added a subscriber: samestep.
sgatev accepted this revision.Aug 3 2022, 4:37 AM
sgatev added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
175
387
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
171–175
This revision is now accepted and ready to land.Aug 3 2022, 4:37 AM
samestep added inline comments.Aug 3 2022, 5:07 AM
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
213

I think you need to set the DeclCtx field here (or at least, somewhere in this method).

wyt updated this revision to Diff 449664.Aug 3 2022, 7:40 AM

Update DeclCtx when pushing/popping calls.

wyt updated this revision to Diff 449666.Aug 3 2022, 7:49 AM
wyt marked 3 inline comments as done.

Formatting fixes.

wyt added a reviewer: samestep.Aug 3 2022, 7:50 AM
wyt removed a subscriber: samestep.
wyt added inline comments.
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
171–175

Unfortunately doesn't work, I get a warning about "An initializer for a delegating constructor must appear alone".

sgatev accepted this revision.Aug 5 2022, 4:58 AM
sgatev added inline comments.
clang/lib/Analysis/FlowSensitive/Transfer.cpp
537–539 ↗(On Diff #449666)
wyt updated this revision to Diff 450276.Aug 5 2022, 6:19 AM
wyt marked an inline comment as done.

Rebase to head.

gribozavr2 accepted this revision.Aug 5 2022, 7:35 AM
wyt updated this revision to Diff 451411.Aug 10 2022, 4:27 AM

Relocate function and fix comment for consistency.

This revision was landed with ongoing or failed builds.Aug 10 2022, 4:30 AM
This revision was automatically updated to reflect the committed changes.
wyt reopened this revision.Aug 11 2022, 12:30 AM
This revision is now accepted and ready to land.Aug 11 2022, 12:30 AM
wyt updated this revision to Diff 451754.Aug 11 2022, 12:31 AM

Initialise DeclCtx field with nullptr.

This revision was landed with ongoing or failed builds.Aug 11 2022, 12:42 AM
This revision was automatically updated to reflect the committed changes.