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]

[PATCH] Fix convert_and_check ICE


Hi!

The testcase below fails tree checking, because int_fits_type_p is called on
REAL_CST which is not valid argument to it.
This patch fixes this (and warns about stuff like
short int a = 65536.0; while does not about short int a = 65535.0;
).
Ok to commit?

2001-02-09  Jakub Jelinek  <jakub@redhat.com>

	* c-common.c (constant_fits_type_p): New function.
	(convert_and_check): Use it.

	* gcc.c-torture/compile/20010209-1.c: New test.

--- gcc/c-common.c.jj	Mon Jan 29 15:41:58 2001
+++ gcc/c-common.c	Fri Feb  9 13:08:39 2001
@@ -232,6 +232,7 @@ static void add_attribute		PARAMS ((enum
 						 int, int, int));
 static void init_attributes		PARAMS ((void));
 static int default_valid_lang_attribute PARAMS ((tree, tree, tree, tree));
+static int constant_fits_type_p		PARAMS ((tree, tree));
 
 /* Keep a stack of if statements.  We record the number of compound
    statements seen up to the if keyword, as well as the line number
@@ -1189,6 +1190,20 @@ unsigned_conversion_warning (result, ope
     }
 }
 
+/* Nonzero if constant C has a value that is permissible
+   for type TYPE (an INTEGER_TYPE).  */
+
+static int
+constant_fits_type_p (c, type)
+     tree c, type;
+{
+  if (TREE_CODE (c) == INTEGER_CST)
+    return int_fits_type_p (c, type);
+
+  c = convert (type, c);
+  return !TREE_OVERFLOW (c);
+}     
+
 /* Convert EXPR to TYPE, warning about conversion problems with constants.
    Invoke this function on every expression that is converted implicitly,
    i.e. because of language rules and not because of an explicit cast.  */
@@ -1216,7 +1231,7 @@ convert_and_check (type, expr)
 	       don't warn unless pedantic.  */
 	    if ((pedantic
 		 || TREE_UNSIGNED (type)
-		 || ! int_fits_type_p (expr, unsigned_type (type)))
+		 || ! constant_fits_type_p (expr, unsigned_type (type)))
 	        && skip_evaluation == 0)
 	      warning ("overflow in implicit constant conversion");
 	}
--- gcc/testsuite/gcc.c-torture/compile/20010209-1.c.jj	Fri Feb  9 12:34:27 2001
+++ gcc/testsuite/gcc.c-torture/compile/20010209-1.c	Fri Feb  9 12:50:58 2001
@@ -0,0 +1,7 @@
+short int a;
+
+int main (void)
+{
+  a = 65535.0;
+  return 0;
+}

	Jakub


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