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]

Re: Constants out of range



My previous attempt at fixing this broke some assumptions on the C4x;
basically that DImode is not supported on the C4x.  We need a better
way to determine the largest supported target integer.  The type of
an integer literal should be the smallest type capable of representing
it, call that it's natural type.  So we already have to go through the
list of supported integer types to find the natural type.  This search
will top out at the widest supported target, at which point we can
pedwarn if the literal is still too large.

If no one sees a problem with this, I'll commit this in a few days.

                                        -gavin...


	* c-lex.c (yylex) : Change the way we check to see if a literal
	is larger than can be represented by the widest supported target
	integer type.


Index: gcc/c-lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lex.c,v
retrieving revision 1.46
diff -c -p -r1.46 c-lex.c
*** gcc/c-lex.c	1999/02/22 08:18:56	1.46
--- gcc/c-lex.c	1999/02/25 16:45:49
*************** yylex ()
*** 1698,1717 ****
  		c = GETC();
  	      }
  
! 	    /* If the constant won't fit in the targets widest int,
! 	       or it won't fit in the host's representation for ints, 
! 	       then warn that the constant is out of range. */
! 
! #if HOST_BITS_PER_WIDE_INT >= 64
! 	    bytes = TYPE_PRECISION (intTI_type_node) / HOST_BITS_PER_CHAR;
! #else
! 	    bytes = TYPE_PRECISION (intDI_type_node) / HOST_BITS_PER_CHAR;
! #endif
  
  	    warn = overflow;
- 	    for (i = bytes; i < TOTAL_PARTS; i++)
- 	      if (parts[i])
- 		warn = 1;
  	    if (warn)
  	      pedwarn ("integer constant out of range");
  
--- 1698,1707 ----
  		c = GETC();
  	      }
  
! 	    /* If it won't fit in the host's representation for integers,
! 	       then pedwarn. */
  
  	    warn = overflow;
  	    if (warn)
  	      pedwarn ("integer constant out of range");
  
*************** yylex ()
*** 1802,1808 ****
  	    if (pedantic && !flag_traditional && !spec_long_long && !warn
  		&& (TYPE_PRECISION (long_integer_type_node)
  		    < TYPE_PRECISION (type)))
! 	      pedwarn ("integer constant out of range");
  
  	    if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
  	      warning ("decimal constant is so large that it is unsigned");
--- 1792,1801 ----
  	    if (pedantic && !flag_traditional && !spec_long_long && !warn
  		&& (TYPE_PRECISION (long_integer_type_node)
  		    < TYPE_PRECISION (type)))
! 	      {
! 		warn = 1;
! 		pedwarn ("integer constant out of range");
! 	      }
  
  	    if (base == 10 && ! spec_unsigned && TREE_UNSIGNED (type))
  	      warning ("decimal constant is so large that it is unsigned");
*************** yylex ()
*** 1830,1835 ****
--- 1823,1837 ----
  	      }
  	    else
  	      TREE_TYPE (yylval.ttype) = type;
+ 
+ 
+ 	    /* If it's still an integer (not a complex), and it doesn't
+ 	       fit in the type we choose for it, then pedwarn. */
+ 
+ 	    if (! warn
+ 		&& TREE_CODE (TREE_TYPE (yylval.ttype)) == INTEGER_TYPE
+ 		&& ! int_fits_type_p (yylval.ttype, TREE_TYPE (yylval.ttype)))
+ 	      pedwarn ("integer constant out of range");
  	  }
  
  	UNGETC (c);


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