This is an archive of the discontinued LLVM Phabricator instance.

[CFG] [analyzer] Add construction contexts for function arguments.
ClosedPublic

Authored by NoQ on Jun 27 2018, 4:27 PM.

Details

Summary

Replace stubs we had to discriminate between temporaries and function arguments with actual construction contexts for arguments. Make them visible in the CFG. Which means that when there's an argument constructor in the CFG, it'll now be a CFGConstructor element (or a CFGCXXRecordTypedCall element if it's a temporary produced by a function call in C++17 where copy elision is mandatory) that will augment the construct-expression with the information about the constructed object - that it's argument #N of a certain function call.

On the analyzer side, the patch interacts with the recently implemented pre-C++17 copy elision support (D47616, D47671) in an interesting manner. If on the CFG side we didn't find a construction context for the elidable constructor, we build the CFG as if the elidable constructor is not elided, and the non-elided constructor within it is a simple temporary. But the same problem may occur in the analyzer: if the elidable constructor has a construction context but the analyzer doesn't implement such context yet, the analyzer should also try to skip copy elision and still inline the non-elided temporary constructor. This was implemented by adding a "roll back" mechanism: when elision fails, roll back the changes and proceed as if it's a simple temporary. The approach is wonky, but i'm fine with that as long as it's merely a defensive mechanism that should eventually go away once all construction contexts become supported.

Diff Detail

Event Timeline

NoQ created this revision.Jun 27 2018, 4:27 PM
NoQ added inline comments.Jun 27 2018, 4:29 PM
lib/Analysis/CFG.cpp
5011

For consistency.

5074–5078

I'm starting to regret this code reuse mechanism. I guess i should have made a simple lambda instead to wrap all handledStmt calls.

NoQ added inline comments.Jul 2 2018, 2:16 PM
include/clang/Analysis/ConstructionContext.h
90

Uhm. Will fix.

george.karpenkov accepted this revision.Jul 3 2018, 11:23 AM
This revision is now accepted and ready to land.Jul 3 2018, 11:23 AM
NoQ added inline comments.Jul 10 2018, 5:34 PM
lib/Analysis/ConstructionContext.cpp
186

Should assert that we only have one layer.

NoQ updated this revision to Diff 155091.Jul 11 2018, 5:26 PM

Address my own comments.

NoQ closed this revision.Jul 31 2018, 2:47 PM

Committed as rC338436 but Phabricator didn't pick it up because i put a . after the phabricator link.