This is an archive of the discontinued LLVM Phabricator instance.

Fix issue with (void)F;
ClosedPublic

Authored by dinesh.d on May 5 2014, 12:53 PM.

Diff Detail

Event Timeline

dinesh.d updated this revision to Diff 9084.May 5 2014, 12:53 PM
dinesh.d retitled this revision from to Fix issue with (void)F;.
dinesh.d updated this object.
dinesh.d edited the test plan for this revision. (Show Details)
dinesh.d added a reviewer: djasper.
djasper edited edge metadata.May 6 2014, 12:51 AM

Please add a test case.

dinesh.d updated this revision to Diff 9103.May 6 2014, 2:21 AM
dinesh.d edited edge metadata.

added test cases

djasper added inline comments.May 6 2014, 2:50 AM
unittests/Format/FormatTest.cpp
4743

This test case is weird, is it taken from real code? I think clang-format might do very strange things to it (as it commonly splits unwrapped lines on the semicolon).

Also, it is missing a trailing semicolon and don't you need braces if there are multiple statements in a DEBUG invocation?

What are you trying to test?

4744

I prefer implicitly concatenating string literals after "\n". Makes the tests easier to read for me. I.e., turn this into:

verifyFormat("void foo() {\n"
             "  assert(t && \"assert msg\");\n"
             "  (void)F;\n"
             "}");

Also, why the function definition and assert?

dinesh.d updated this revision to Diff 9105.May 6 2014, 3:26 AM

update test cases

unittests/Format/FormatTest.cpp
4743

Test string is not quite correct here. Sorry. Update test case.

Though I have looked for (void) in llvm code and tried to mimic
pattern used in test cases.

4744

updated.

I have looked for (void) in llvm code and tried to mimic
pattern used in test cases.

djasper added inline comments.May 6 2014, 3:32 AM
unittests/Format/FormatTest.cpp
4757–4765

IMO, these don't make sense. They are split into different unwrapped lines and your change can't possibly affect the three lines other than "(void)F;". This file (mostly) contains unit tests, i.e. you should try to test the smallest example that reproduces a specific example.

In this case, I think this should simply be:

verifyIndependentOfContext("(void)F;");
dinesh.d added inline comments.May 6 2014, 4:33 AM
unittests/Format/FormatTest.cpp
4757–4765

current clang-format does not handles just '(void)F;' (void) is treated as
cast only if this code is inside a block. verifyIndependentOfContext()
test for both the cases, first as stand-alone string and then, after wrapping
within a function. So above test case will fail for first.

Smallest test case may be

verifyFormat("{ (void)F; }");

Moreover, this is not bug, Tobias has raise issue about change in formatting
for some pattern. If current behaviour is what we want we do not have to do
anything else with this patch, we can restore previous behaviour.

before r207961:

if (test) {
  (void)WasFastQuery;
  assert(WasFastQuery && "More work to do after problem solved?");

  assert(Found && "Invalid reverse map!");
  (void)Found;

  (void)SimplifyICmpOperands(Cond, LHS, RHS);
}

After r207961:

if (test) {
  (void) WasFastQuery;
  assert(WasFastQuery && "More work to do after problem solved?");

  assert(Found && "Invalid reverse map!");
  (void) Found;

  (void) SimplifyICmpOperands(Cond, LHS, RHS);
}
dinesh.d updated this revision to Diff 9107.May 6 2014, 4:34 AM

reduced test case

djasper accepted this revision.May 6 2014, 4:42 AM
djasper edited edge metadata.

Looks good.

This revision is now accepted and ready to land.May 6 2014, 4:42 AM
dinesh.d closed this revision.May 6 2014, 4:57 AM

committed as r208080.

Thanks for review and support.