rs6000.c warnings

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Wed Mar 20 12:47:00 GMT 2002


 > From: David Edelsohn <dje@watson.ibm.com>
 > 
 > [I am explicitly cc'ing Zack and Kaveh because they have a lot of
 > experience with warnings and seem to have opinions about this subject :-]
 > 
 > 	rs6000.c currently produces
 > 
 > warning: signed and unsigned type in conditional expression
 > 
 > because of the RS6000_ARG_SIZE macro:
 > 
 > #define RS6000_ARG_SIZE(MODE, TYPE)                                   \
 > ((MODE) != BLKmode                                                    \
 >  ? (GET_MODE_SIZE (MODE) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD     \
 >  : ((unsigned HOST_WIDE_INT) int_size_in_bytes (TYPE)                 \
 >     + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
 > 
 > 	The warning occurs because UNITS_PER_WORD is an integer constant
 > assumed signed and int_size_in_bytes is not constant.  The code in
 > c-typeck.c to build a conditional expression skips the warning if the
 > expression is constant, but the function call defeats that exception.
 > This appears to be GCC being a little overly-aggressize with warnings.

I think I have a different conclusion about why this warns.  The
critical bit here is that GET_MODE_SIZE returns an unsigned char.
Arithmetic on it is promoted to int, so the first branch of the ?: is
signed.  See: http://gcc.gnu.org/ml/gcc-patches/2001-12/msg01906.html
The second branch is clearly unsigned due to the cast, thus yielding
the warning.


 > 	I can remove the warning by REMOVING the cast of int_size_in_bytes
 > to unsigned H_W_I.  This macro only is used to set or modify "int", so
 > making the expression signed isn't a problem.  I could change
 > UNITS_PER_WORD to constants with "u" appended (which also fixes the
 > warning), but that is not too appealing.

Please no, adding "u" would counter-productively generate
-Wtraditional warnings. :-)


 > 	I am not sure what promotion will occur.  Removing the cast makes
 > one part of the expression unsigned (GET_MODE_SIZE) and the other part
 > signed (int_size_in_bytes).  A warning that encourages me to make an
 > expression asymmeric seems like a bad warning.
 > 
 > 	Does removing the cast seem like a reasonable solution?  Is there
 > a way for GCC to ignore the signedness of non-negative constant integers
 > combined with variable expressions?
 > Thanks, David

If you accept my analysis above as correct, then its *currently*
asymmetric and your suggestion to remove the cast balances both as
signed expressions.

		--Kaveh
--
Kaveh R. Ghazi			Director of Systems Architecture
ghazi@caip.rutgers.edu		Qwest Global Services



More information about the Gcc-patches mailing list