This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] PR34389 -Wconversion produces wrong warning


The following patch  fixes PR 34389 in a ugly way, in my own opinion,
but I am not able to come up with any other way to fix this.

A more detailed analysis is in the PR. In summary the problem here is
that fold_unary converts (T)(x & c) into (T)x & (T)c which in this
case is (int) (x & 0x7fff) into ((int)x & 0x7fff). By using
get_unwidened, we could handle the first form. However, get_unwidened
won't handle the latter. Thus, when Wconversion sees that this
expression is assigned to a short, it concludes that there may be a
loss of precision.

Bootstrapped and regression tested in x86_64-unknown-linux-gnu. This
patch only affects Wconversion, which is new in 4.3.

Is this OK to commit? Any suggestions?

Cheers,

Manuel.

2008-02-16  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

 PR c/34389
 * c-common.c (conversion_warning): Handle '&' expressions correctly.

testsuite/
  * gcc.dg/Wconversion-pr34389.c: New.

Attachment: fix-pr34389.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]