This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] simplify-bool-expr ignores template instantiations
ClosedPublic

Authored by njames93 on Jun 6 2020, 3:43 PM.

Diff Detail

Event Timeline

njames93 created this revision.Jun 6 2020, 3:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2020, 3:43 PM

Thank you for looking into it!

aaron.ballman added inline comments.Jun 7 2020, 8:10 AM
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
425

This is changing the behavior so that now it will diagnose in header files, no? Why is the correct change to replace this with unless(isInTemplateInstantiation()) instead of adding the new matcher?

njames93 marked an inline comment as done.Jun 7 2020, 8:55 AM
njames93 added inline comments.
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
425

It's changing behaviour that arguably shouldn't have been in the first place. But perhaps that change should go on a new patch or update the description of this one

aaron.ballman added inline comments.Jun 7 2020, 9:06 AM
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
425

I'll admit that the original code seems a bit suspect to me. I sort of wonder if it was being used to suppress diagnosing macros unless they're considered to be under the user's control. e.g., macros in headers may not be plausible to change but macros in source files are.

If changes should be made here, I don't have strong opinions on whether it requires a separate patch or can be done in this one, but I'd like to better understand why the original code was incorrect (if it is in fact incorrect).

njames93 marked an inline comment as done.Jun 7 2020, 10:26 AM
njames93 added inline comments.
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
425

So having a look in the archives shows this condition was on the first draft for this check. But I couldn't see any discussion about it.

aaron.ballman added inline comments.
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
425

Drat, that matches my digging too. I think the current patch should leave this requirement in place so we can get the bug fix in while we figure out what to do with this bit (assuming the bug fix doesn't rely on this change somehow). If you want to remove the main file requirement in another patch, I'd suggest adding @LegalizeAdulthood as a reviewer to see if they remember why this condition was in place and (I believe) wasn't tested.

njames93 updated this revision to Diff 269076.Jun 7 2020, 2:35 PM

Added back isExpansionInMainFile check

Should put a follow up to query removing this check.

This isn't needed if https://reviews.llvm.org/D80961 is merged.

Yeah, the restriction to the header file is a bug. It was a misconception on my part when I originally wrote the matcher.

See https://bugs.llvm.org/show_bug.cgi?id=26332 which should also be fixed by the change here.

I had attempted to make progress on fixing that bug (26332) but some retooling of the testing framework is needed to validate
that the header has a fixit applied to it. I made some progress by refactoring the python script, but as usual it got bogged
down in clang review hell and I haven't had time to make any more forward progress on it.

Yeah, the restriction to the header file is a bug. It was a misconception on my part when I originally wrote the matcher.

Excellent, thank you for weighing in! I'm fine with the original version of the patch going in with that modification if you'd like to go that route.

This isn't needed if https://reviews.llvm.org/D80961 is merged.

Alternatively, I would be fine waiting until that review is merged and making only the main file expansion fixes.

Yeah, the restriction to the header file is a bug. It was a misconception on my part when I originally wrote the matcher.

Excellent, thank you for weighing in! I'm fine with the original version of the patch going in with that modification if you'd like to go that route.

This isn't needed if https://reviews.llvm.org/D80961 is merged.

Alternatively, I would be fine waiting until that review is merged and making only the main file expansion fixes.

It may be better to not wait for larger refactoring but handle known false-positive immediately.

njames93 updated this revision to Diff 271047.Jun 16 2020, 4:46 AM

Removed isExpansionInMainFile check as per original authors comment

lebedev.ri accepted this revision.Jun 16 2020, 4:59 AM

LG, unless @aaron.ballman has concerns.
Thanks.

This revision is now accepted and ready to land.Jun 16 2020, 4:59 AM
This revision was automatically updated to reflect the committed changes.