egcs, cexp.y warning patch for noise in MAX_WCHAR_TYPE_SIZE

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sun Jul 12 18:28:00 GMT 1998


	I get the following warning when bootstrapping the a recent
(1998-07-11) egcs CVS checkout on mips-sgi-irix6.2 with cc for stage1:

 > cc  -DIN_GCC    -g  -DHAVE_CONFIG_H     -I. -I. -I./config -c ./cexp.c
 > cfe: Warning 848: cexp.y, line 663: Lshift with undefined behaviour.
 >         mask = (64   < 32                            ? ~ (~ (int ) 0 << 64  )                        : ~ (int ) 0) ;
 >         --------------------                    ----------^
 > cfe: Warning 848: cexp.y, line 670: Lshift with undefined behaviour.
 >         mask = (64   < 32                            ? ~ (~ (int ) 0 << 64  )                        : ~ (int ) 0) ;
 >         --------------------                    ----------^
 > 

	I believe the warning stems from the definition of the macro
MAX_WCHAR_TYPE_MASK.

 > #define MAX_WCHAR_TYPE_MASK (MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT \
 > ? ~ (~ (HOST_WIDE_INT) 0 << MAX_WCHAR_TYPE_SIZE) \
 > : ~ (HOST_WIDE_INT) 0)

	Now from the definition it looks as if the problematic Lshift is
correctly protected by the "<" conditional, exactly because of the
width/size issue.  I.e., it looks like it does the right thing. 

	However, both clauses of the ?: are still evaluated, so in the
interest of eliminating warning noise, I was wondering if there is a way
to write this so the compiler doesn't needlessly complain.  Eg:

--- cexp.y~	Sun Jul 12 20:39:51 1998
+++ cexp.y	Sun Jul 12 20:44:26 1998
@@ -158,9 +158,11 @@
 			    ? (~ (~ (HOST_WIDE_INT) 0 << MAX_CHAR_TYPE_SIZE)) \
 			    : ~ (HOST_WIDE_INT) 0)
 
-#define MAX_WCHAR_TYPE_MASK (MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT \
-			     ? ~ (~ (HOST_WIDE_INT) 0 << MAX_WCHAR_TYPE_SIZE) \
-			     : ~ (HOST_WIDE_INT) 0)
+#if MAX_WCHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT
+#define MAX_WCHAR_TYPE_MASK (~ (~ (HOST_WIDE_INT) 0 << MAX_WCHAR_TYPE_SIZE))
+#else
+#define MAX_WCHAR_TYPE_MASK (~ (HOST_WIDE_INT) 0)
+#endif
 
 /* Suppose A1 + B1 = SUM1, using 2's complement arithmetic ignoring overflow.
    Suppose A, B and SUM have the same respective signs as A1, B1, and SUM1.


	I'm mainly concerned whether the definition of MAX_WCHAR_TYPE_SIZE
in the #if expression is always something that all cpp's can parse.
(I'm pretty sure HOST_BITS_PER_WIDE_INT is okay because I see it is
evaluated in #if conditionals elsewhere in the source code.)

	In scanning the source, I'm pretty sure it is.  So is the above
patch okay to install?

		Thanks,
		--Kaveh
--
Kaveh R. Ghazi			Project Manager / Custom Development
ghazi@caip.rutgers.edu		Icon CMT Corp.



More information about the Gcc-patches mailing list