[Sema] No -Wtautological-pointer-compare warning on variables within parentheses
AbandonedPublic

Authored by danielmarjamaki on Oct 10 2017, 3:42 AM.

Details

Summary

Submitting a patch to Bugzilla 20951.

Simply replaced the function call IgnoreImpCasts to IgnoreParenImpCasts which seems to more appropriate.
I also had to modify a test cast in test/Sema/conditional-expr.c

/E

Diff Detail

Repository
rL LLVM
erikv created this revision.Oct 10 2017, 3:42 AM
lebedev.ri added inline comments.
test/Sema/conditional-expr.c
84

Please don't just remove previous tests.
E.g. does the old test no longer warns?

danielmarjamaki added a subscriber: danielmarjamaki.

I think a test for -Wtautological-pointer-compare should be added that shows that the bug is fixed.

test/Sema/conditional-expr.c
84

no test is removed. The expected-warning is unchanged.

the problem with the test was that this comparison is always true:

(&x) != ((void *)0)

the address of x is never 0!

Fixing https://bugs.llvm.org/show_bug.cgi?id=20951 means Clang will warn:

warning: comparison of address of 'x' not equal to a null pointer is always true [-Wtautological-pointer-compare]

We changed the test so the -Wtautological-pointer-compare is not reported... but the original warning is still reported.

erikv retitled this revision from Patch to Bugzilla 20951 to [Sema] No -Wtautological-pointer-compare warning on variables within parentheses.Oct 10 2017, 4:11 AM
erikv edited the summary of this revision. (Show Details)
erikv set the repository for this revision to rL LLVM.
erikv updated this revision to Diff 118347.Oct 10 2017, 4:29 AM

Added new test

LGTM! However I would like to see a review from somebody else also.

There are a number of diagnostics that might be affected. The Sema::DiagnoseAlwaysNonNullPointer diagnoses these:

diag::warn_this_null_compare
diag::warn_this_bool_conversion
diag::warn_address_of_reference_null_compare
diag::warn_address_of_reference_bool_conversion
diag::warn_nonnull_expr_compare
diag::warn_cast_nonnull_to_bool
diag::warn_null_pointer_compare <-- I think this is the one bug 20951 is about
diag::warn_impcast_pointer_to_bool

It seems to me that it is an improvement for all these warnings to skip the parentheses. However there is a danger that parentheses should hide some warnings to make it possible for users to hide unwanted warnings. But if that was the design decision then some regression test should complain when we skip the parentheses.

danielmarjamaki commandeered this revision.Mon, Jan 15, 12:35 AM
danielmarjamaki edited reviewers, added: erikv; removed: danielmarjamaki.
danielmarjamaki abandoned this revision.Mon, Jan 15, 12:35 AM

Erik and I will not continue working on this. Feel free to take over the patch or write a new patch.