This is an archive of the discontinued LLVM Phabricator instance.

[clang][dataflow] Add support for return values of reference type.
ClosedPublic

Authored by mboehme on May 23 2023, 2:37 AM.

Details

Summary

This patch changes the way Environment::ReturnLoc is set: Whereas previously it was set by the caller, it is now set by the callee (obviously, as we otherwise would not be able to return references).

The patch also introduces Environment::ReturnVal, which is used for non-reference-type return values. This allows these to be handled with the correct value category semantics; see also https://discourse.llvm.org/t/70086, which describes the ongoing migration to strict value category semantics.

Depends On D150776

Diff Detail

Event Timeline

mboehme created this revision.May 23 2023, 2:37 AM
Herald added a project: Restricted Project. · View Herald Transcript
mboehme requested review of this revision.May 23 2023, 2:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 23 2023, 2:37 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mboehme edited the summary of this revision. (Show Details)May 23 2023, 2:38 AM
mboehme added reviewers: ymandel, xazax.hun.
ymandel accepted this revision.May 23 2023, 5:40 AM

Nice!

This revision is now accepted and ready to land.May 23 2023, 5:40 AM
xazax.hun accepted this revision.May 24 2023, 8:07 PM
xazax.hun added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
196

I know that Obj-C is a non-goal, but it might worth a comment to support ObjCMessageExpr just in case someone wants to work on this.

Btw, this is one of my biggest pet peeves about the Clang AST. We should have a common abstraction for all the callables, instead of having to bifurcate many of the APIs.

mboehme marked an inline comment as done.May 25 2023, 12:12 AM
mboehme added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
196

Agreed!

I'm a bit hesitant to add a FIXME here though, as that might make it sound as if there's a plan to add Objective-C support or at least imply that that's a goal. Also, I think Objective-C support would entail quite a bit more than adding the right overloads here -- so I'm not sure how helpful the comment here would be. I think once someone goes down the road of seriously working on Objective-C support, they'll quickly discover that they need a new overload here.

I hope this makes sense? Happy to add something in a followup patch if you feel we should add some Objective-C "breadcrumbs" here.

This revision was automatically updated to reflect the committed changes.
mboehme marked an inline comment as done.
xazax.hun added inline comments.May 25 2023, 7:05 AM
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
196

Yup, makes sense!