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]

Check for conversion overflow in extract_divmod


This fixes the following Ada testcase.  Tested on i686-pc-linux-gnu.

with Ada.Text_Io; use Ada.Text_Io;

procedure t is
   type T is range 1 .. 100;

   C : T;

   procedure X is
   begin
      null;
   end X;

begin
   C := 10;
   X;
   if Duration(2 * C) = 0.0 then 
      raise Program_Error;
   end if;
end t;

Tue Dec 10 17:11:24 2002  Richard Kenner  <kenner at vlsi1 dot ultra dot nyu dot edu>

	* fold-const.c (extract_muldiv, case CONVERT_EXPR): Detect case
	when conversion overflows.

*** gcc/fold-const.c	16 Apr 2003 21:33:19 -0000	1.247
--- gcc/fold-const.c	18 Apr 2003 23:07:07 -0000
***************
*** 4183,4188 ****
  	 we can, replace this expression with the inner simplification for
  	 possible later conversion to our or some other type.  */
!       if (0 != (t1 = extract_muldiv (op0, convert (TREE_TYPE (op0), c), code,
! 				     code == MULT_EXPR ? ctype : NULL_TREE)))
  	return t1;
        break;
--- 4183,4192 ----
  	 we can, replace this expression with the inner simplification for
  	 possible later conversion to our or some other type.  */
!       if ((t2 = convert (TREE_TYPE (op0), c)) != 0
! 	  && TREE_CODE (t2) == INTEGER_CST
! 	  && ! TREE_CONSTANT_OVERFLOW (t2)
! 	  && (0 != (t1 = extract_muldiv (op0, t2, code,
! 					 code == MULT_EXPR
! 					 ? ctype : NULL_TREE))))
  	return t1;
        break;
Index: gcc/fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.247
diff -c -2 -p -r1.247 fold-const.c
*** gcc/fold-const.c	16 Apr 2003 21:33:19 -0000	1.247
--- gcc/fold-const.c	18 Apr 2003 23:07:19 -0000
*************** extract_muldiv_1 (t, c, code, wide_type)
*** 4183,4188 ****
  	 we can, replace this expression with the inner simplification for
  	 possible later conversion to our or some other type.  */
!       if (0 != (t1 = extract_muldiv (op0, convert (TREE_TYPE (op0), c), code,
! 				     code == MULT_EXPR ? ctype : NULL_TREE)))
  	return t1;
        break;
--- 4183,4192 ----
  	 we can, replace this expression with the inner simplification for
  	 possible later conversion to our or some other type.  */
!       if ((t2 = convert (TREE_TYPE (op0), c)) != 0
! 	  && TREE_CODE (t2) == INTEGER_CST
! 	  && ! TREE_CONSTANT_OVERFLOW (t2)
! 	  && (0 != (t1 = extract_muldiv (op0, t2, code,
! 					 code == MULT_EXPR
! 					 ? ctype : NULL_TREE))))
  	return t1;
        break;


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