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: Patch for `switch' warning (would like a review)


> Date: Fri, 17 Jan 2003 15:19:24 -0500 (EST)
> From: "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu>
> Cc: gcc-patches@gcc.gnu.org
> X-OriginalArrivalTime: 17 Jan 2003 20:19:03.0296 (UTC) FILETIME=[AD948000:01C2BE65]
> 
>  > From: Geoff Keating <geoffk@geoffk.org>
>  > 
>  > "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
>  > 
>  > > Here's one I don't feel is 100% obvious.  I get one of those "long in
>  > > switch not converted to int" warnings in this code.
>  > > 
>  > > If we assume the host platforms is always 32-bit int, then the cast is
>  > > okay.  But I wasn't sure we could make that assumption.
>  > 
>  > We can assume that 'int' is at least 32 bits, but I believe that means
>  > that this code would fail if any mode contains 32 or more bytes, which
>  > I don't think is unlikely in the future, so it would be better to
>  > convert it to if-else statements.
> 
> 
> 
> Hmm, the if-else turned out to be gross.  How about this?
> 
> I check if we're <= 0xffff before entering the switch which allows me
> to cast to int inside the switch.  Then I moved the `default' block
> down below so it's unconditionally run if none of the switch cases
> match and return.
> 
> Tested on the primary platform cross-configs with -Werror (warning is
> gone) and by bootstrapping on sparc-sun-solaris2.7.  Testsuite in
> progress, if it passes, ok to install?

Yes, this is OK.  I actually like it even more than a plain if-else chain.

> 		--Kaveh
> 
> 
> 2003-01-17  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
> 
> 	* ra-build.c (undef_to_size_word): Avoid `switch' warning.
-- 
- Geoffrey Keating <geoffk@geoffk.org>


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