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]

Re: [RFC] PR34389 -Wconversion produces wrong warning


On 18/02/2008, Joseph S. Myers <joseph@codesourcery.com> wrote:
>
> I agree with that in principle - but I also think it's useful to avoid
> warning for such cases as short = (int & 0x7fff) when written directly by
> the user (with any non-negative constant in the range of short there).  I
> suppose there are other cases where it may be less likely that the user
> will write the code created by the compiler, but anything affecting
> expressions directly written by the user would still be of some use after
> the front end no longer does the present folding.  (This means there
> should be testcases where the problem expressions are written directly by
> the user, not just the tests where they are compiler-generated.)

My patch can handle

short x;
short y = ((int)x & 0x7fff)

because this case is covered in build_bin_op, where it is transformed
into (int)(x&0x7fff). So this case seems easy.

But it will still warn for

int x;
short y = x &  0x7fff;

Do we have any function or piece of code that tells when y = x & z
does not lose information or change a value? I really don't know what
the rules are for all combinations of precision/signedness of y, x and
z, and taking into account that each of them may contain an arbitrary
number of casts.

Cheers,

Manuel.


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