This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check.
ClosedPublic

Authored by hokein on Feb 11 2016, 2:54 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein updated this revision to Diff 47617.Feb 11 2016, 2:54 AM
hokein retitled this revision from to [clang-tidy] Fix an ssert failure of ForStmt in `readability-braces-around-statments` check..
hokein updated this object.
hokein retitled this revision from [clang-tidy] Fix an ssert failure of ForStmt in `readability-braces-around-statments` check. to [clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check..Feb 11 2016, 2:55 AM
hokein added a reviewer: alexfh.
hokein set the repository for this revision to rL LLVM.
hokein added a subscriber: cfe-commits.
alexfh added inline comments.Feb 11 2016, 4:16 AM
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
13 ↗(On Diff #47617)

Can you further reduce the test case so it still causes a crash, but doesn't generate so many compilation errors?

The problem with matching compilation errors in clang-tidy tests is that a change in Clang parser can break clang-tidy tests. The more errors you verify, the higher the chance of this kind of a breakage. If we need to verify clang errors, we should keep their number minimal.

hokein added inline comments.Feb 11 2016, 8:57 AM
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
13 ↗(On Diff #47617)

Indeed, this is the minimal test case.

Is there a way to modify the test script to ignore message of compilation errors?

alexfh added inline comments.Feb 11 2016, 10:28 AM
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
13 ↗(On Diff #47617)

Interesting. Does creduce fail to further reduce the test?

As for ignoring errors, it's rather rarely needed in tests. Usually, we need the reverse: to ensure tests compile without errors. If we want to ignore errors here, we can either run clang-tidy and FileCheck directly from the test or add a parameter to the script to modify the -implicit-check-not parameter of the FileCheck.

hokein updated this revision to Diff 47795.Feb 12 2016, 5:24 AM

Make test ignore all compliation errors.

hokein marked an inline comment as done.Feb 12 2016, 5:27 AM
hokein added inline comments.
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
16 ↗(On Diff #47795)

Interesting. Does creduce fail to further reduce the test?

I reduce the test case manually.

Now I use FileCheck with -implicit-check-not parameter to ignore all compilation errors.

alexfh added inline comments.Feb 12 2016, 5:46 AM
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
8 ↗(On Diff #47795)

Tests shouldn't include any library headers. This is problematic in many different ways:

  • standard library can be different in different setups, which may cause test breakages;
  • including system headers may not work in some test setups;
  • including system headers may lead to significant increase in testing time;
  • there's no way to test something with different library implementations in the same test setup.

This is why we usually model APIs needed for the test in the tests (e.g. see test/clang-tidy/misc-inaccurate-erase.cpp). In this specific case the check doesn't need an actual std::vector<>, it just needs to simulate a specific compile error that would lead to a specific incompleteness in the AST. So, please, reduce the test case (the largest reduction would be the removal of #include <vector>) ;)

16 ↗(On Diff #47795)

I reduce the test case manually.

That's why I was asking about creduce. It can do a much better job with a much less manual effort ;)

hokein updated this revision to Diff 47959.Feb 15 2016, 1:22 AM
hokein marked an inline comment as done.

Minimize test case.

hokein marked an inline comment as done.Feb 15 2016, 1:31 AM
hokein added inline comments.
test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
1 ↗(On Diff #47959)

This is the simplest way to ignore all the compilation errors while keeping assert failure in the test. The check-clang-tools test script handles all stuff for us.

7 ↗(On Diff #47959)

Reduce to the minimal test case now. C-Reduce is a useful tool :D.

alexfh accepted this revision.Feb 16 2016, 2:07 AM
alexfh edited edge metadata.

Looks good. Thank you!

This revision is now accepted and ready to land.Feb 16 2016, 2:07 AM
hokein updated this revision to Diff 48057.Feb 16 2016, 2:30 AM
hokein marked an inline comment as done.
hokein edited edge metadata.

Add a note in testcase.

This revision was automatically updated to reflect the committed changes.