Page MenuHomePhabricator

[analyzer] Test case for lambda capture by value modelling
AcceptedPublic

Authored by gamesh411 on Oct 29 2019, 8:01 PM.

Details

Summary

This test provides test coverage for the following feature:
Variables which are captured by value into a lambda require a call to a
copy constructor.

Event Timeline

gamesh411 created this revision.Oct 29 2019, 8:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2019, 8:01 PM
gamesh411 updated this revision to Diff 227090.EditedOct 30 2019, 7:10 AM
  • Add capture by reference test
  • Add another class to ensure reachability inside function call is independent of each other in the first 2 test cases
Szelethus accepted this revision.Oct 30 2019, 7:49 AM

LGTM, can we remove the open projects entry under the same breath?

This revision is now accepted and ready to land.Oct 30 2019, 7:49 AM
gamesh411 updated this revision to Diff 227096.Oct 30 2019, 7:55 AM
  • Remove link reference from commit message
  • Remove superfluous semicolons left in the code
gamesh411 edited the summary of this revision. (Show Details)Oct 30 2019, 7:55 AM
NoQ added a comment.Oct 30 2019, 11:28 AM

I recommend starting with CFG tests for this feature. I.e., do -analyzer-checker debug.DumpCFG and make sure that every CFGStmt that corresponds to a constructor is a CFGConstructor (i.e., has a ConstructionContext explained in the dump). Cf. test/Analysis/cfg-rich-constructors.cpp.

clang/test/Analysis/clangsa_unsupported_features/handle_constructors_for_lambda_captures.cpp
11

This test doesn't test whether the function is inlined. If the function is not inlined, the code will still be reachable when analyzed as top frame. See also clang_analyzer_checkInlined().

29

That's the reason why your tests seem to work. If you change it to ~incr_on_copy_for_simple_usage() {}, we will no longer evaluate the capture correctly.

The difference here is that we allow ourselves inline the constructor without a construction context when the destructor is trivial. But when the destructor is non-trivial, our inability to keep track of the object under construction until destruction will have terrible consequences.

NoQ added inline comments.Oct 30 2019, 11:29 AM
clang/test/Analysis/clangsa_unsupported_features/handle_constructors_for_lambda_captures.cpp
29

*allow ourselves to inline