This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix a bogus -Wconversion warning
ClosedPublic

Authored by erik.pilkington on Feb 12 2019, 1:33 PM.

Details

Summary

DiagnoseFloatingImpCast expects an integer type, but the changes introduced in D50467 caused us to warn on any builtin type, even pseudo-object type. This lead to us warning in this property expression's syntactic form. Its not clear to me that we should even be analyzing the syntactic form here, but this patch fixes the regression.

rdar://47644670

Thanks!
Erik

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptFeb 12 2019, 1:33 PM
nickdesaulniers accepted this revision.Feb 12 2019, 4:38 PM

Thanks for fixing this regression (sorry, I caused it). Doesn't regress the tests I added. You'll probably want to request to Hans that this gets picked up for the 8.0 release. Not sure if @rsmith has comments on the added fixme?

clang/test/SemaObjC/conversion.m
23

does this need a // no-warning comment?

This revision is now accepted and ready to land.Feb 12 2019, 4:38 PM
erik.pilkington marked 2 inline comments as done.

I was taking a final look at this, and I noticed that we were sending the wrong arguments to DiagnoseFloatingImpCast. The expression argument is meant to be the source expression with floating-point type, but we were sending in the compound assignment operator, with integral type. Similarly, the type argument is meant to be the (integral) destination type, but we were sending in the floating-point RHS type. This lead to bad diagnostics:

t.c:3:7: warning: implicit conversion turns floating-point number into integer: 'int' to 'double' [-Wfloat-conversion]
    integral_value += double_value;

When really it ought to be 'double' to 'int'. Fix this by just directly calling DiagnoseImpCast, since we don't really need anything DiagnoseFloatingImpCast does anyways.

erik.pilkington requested review of this revision.Feb 13 2019, 4:52 PM

Basically LGTM, especially if we need an emergency fix, but please consider addressing my comment before committing since I'd expect it to be straightforward to solve.

clang/lib/Sema/SemaChecking.cpp
10634

Yeah, can we just make a predicate function for this rank comparison? And really it shouldn't be based on rank: while a difference in FP rank *often* corresponds to a difference in representable range, there are exceptions (notably with long double on non-x86 targets (as well as Win64) which is often equivalent to either double or __float128), and we should probably treat those like we do the integer types, i.e. ignore them.

Fix this by just directly calling DiagnoseImpCast, since we don't really need anything DiagnoseFloatingImpCast does anyways.

Good catch; thanks for fixing and improving the tests.

erik.pilkington marked an inline comment as done.
erik.pilkington added inline comments.
clang/lib/Sema/SemaChecking.cpp
10634

There is another place that we're doing this in this file, so I put it in a follow up: https://reviews.llvm.org/D58254. Thanks!

This revision was not accepted when it landed; it landed in state Needs Review.Feb 14 2019, 2:47 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2019, 2:47 PM