This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] do not crash on libcxx03 call_once implementation
ClosedPublic

Authored by george.karpenkov on Nov 1 2017, 4:06 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

xazax.hun added inline comments.Nov 2 2017, 4:10 AM
lib/Analysis/BodyFarm.cpp
415 ↗(On Diff #121206)

Wouldn't it be equivalent for checking only callback->getType()->isReferenceType()?

Updated the diff, addressed review concerns.
Made it more explicit in comments in tests that we do not crash on libcxx03 implementation, but that we don't model it either.

@dcoughlin sorry I disagree on previous testing notes (requiring to explicitly test that the std::call_once on libcxx03 is ignored).
Current tests test exactly the specification we want them to test: libcxx11 is modeled, libcxx03 does not crash.
Testing actual behavior on libcxx03 would entail many problems, with very little benefit:

a) The fact that libcxx03 std::call_once is ignored is not part of the specification, it's just not specified
b) Splitting libcxx03 into a separate file would case many issues:

  • Higher cognitive overhead when looking for a particular file
  • Harder to run tests with a single command, harder to see all tests for this functionality
  • Tests would have to be copied, causing the copying of almost the entire file. Furthermore, all future tests would have to be duplicated as well.
  • If we were to eventually model libcxx03 std::call_once, we would have to merge two files back together (or maintain the duplication) to say that we get the same behavior
  • This would encourage further stacking up of technical debt: if we would model another libcxx version, and get a separate file for that, we would have to now duplicate every test across three files.

c) Having separate behaviors with ifndef would make the file larger, increase the cognitive overhead, and also make writing future tests more difficult. This is also something easy to forget while writing future tests. Also it's not clear how ifndef would even help, since LIT directives are not controlled by the preprocessor.

dcoughlin edited edge metadata.Nov 2 2017, 3:52 PM

Updated the diff, addressed review concerns.
Made it more explicit in comments in tests that we do not crash on libcxx03 implementation, but that we don't model it either.

@dcoughlin sorry I disagree on previous testing notes (requiring to explicitly test that the std::call_once on libcxx03 is ignored).
Current tests test exactly the specification we want them to test: libcxx11 is modeled, libcxx03 does not crash.

At a minimum we need to test that calling call_once() doesn't emit a diagnostic. If the analyzer were to emit a diagnostic on every call, that would be very bad.

It would probably also be good to also test that the arguments are escaped as well.

Testing actual behavior on libcxx03 would entail many problems, with very little benefit:

a) The fact that libcxx03 std::call_once is ignored is not part of the specification, it's just not specified
b) Splitting libcxx03 into a separate file would case many issues:

You don't have to copy the whole file. Please, just add a test (somewhere, anywhere) making sure that that the analyzer does what we expect on a call to call_once() under libcxx03. This should not be difficult and it tests a supported analyzer configuration.

c) Having separate behaviors with ifndef would make the file larger, increase the cognitive overhead, and also make writing future tests more difficult. This is also something easy to forget while writing future tests. Also it's not clear how ifndef would even help, since LIT directives are not controlled by the preprocessor.

You are testing with -verify and // expected-warning. Note that -verify does respect the preprocessor; this is a pattern used throughout the clang tests.

dcoughlin accepted this revision.Nov 2 2017, 5:30 PM

Looks great. Thank you!

This revision is now accepted and ready to land.Nov 2 2017, 5:30 PM
This revision was automatically updated to reflect the committed changes.