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]

[PATCH] Fix PR34154, unsigned long long switch ranges on HWI32


Where the code uses *signed* comparisons all the time and thus optimizes
the range away as empty.  Duh.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to mainline.

Richard.

2007-11-21  Richard Guenther  <rguenther@suse.de>

	PR middle-end/34154
	* gimplify.c (gimplify_switch_expr): Use tree_int_cst_lt instead
	of the signed INT_CST_LT.
	* stmt.c (expand_case): Likewise.
	(estimate_case_costs): Likewise.

	* testsuite/gcc.c-torture/execute/pr34154.c: New testcase.

Index: gimplify.c
===================================================================
*** gimplify.c	(revision 130268)
--- gimplify.c	(working copy)
*************** gimplify_switch_expr (tree *expr_p, tree
*** 1413,1419 ****
  	    {
  	      /* Discard empty ranges.  */
  	      tree high = CASE_HIGH (elt);
! 	      if (high && INT_CST_LT (high, low))
  	        remove_element = TRUE;
  	    }
  	  else
--- 1413,1419 ----
  	    {
  	      /* Discard empty ranges.  */
  	      tree high = CASE_HIGH (elt);
! 	      if (high && tree_int_cst_lt (high, low))
  	        remove_element = TRUE;
  	    }
  	  else
Index: stmt.c
===================================================================
*** stmt.c	(revision 130268)
--- stmt.c	(working copy)
*************** expand_case (tree exp)
*** 2360,2366 ****
  	  high = CASE_HIGH (elt);
  
  	  /* Discard empty ranges.  */
! 	  if (high && INT_CST_LT (high, low))
  	    continue;
  
  	  case_list = add_case_node (case_list, index_type, low, high,
--- 2360,2366 ----
  	  high = CASE_HIGH (elt);
  
  	  /* Discard empty ranges.  */
! 	  if (high && tree_int_cst_lt (high, low))
  	    continue;
  
  	  case_list = add_case_node (case_list, index_type, low, high,
*************** expand_case (tree exp)
*** 2387,2395 ****
  	    }
  	  else
  	    {
! 	      if (INT_CST_LT (n->low, minval))
  		minval = n->low;
! 	      if (INT_CST_LT (maxval, n->high))
  		maxval = n->high;
  	    }
  	  /* A range counts double, since it requires two compares.  */
--- 2387,2395 ----
  	    }
  	  else
  	    {
! 	      if (tree_int_cst_lt (n->low, minval))
  		minval = n->low;
! 	      if (tree_int_cst_lt (maxval, n->high))
  		maxval = n->high;
  	    }
  	  /* A range counts double, since it requires two compares.  */
*************** estimate_case_costs (case_node_ptr node)
*** 2664,2670 ****
  
    for (n = node; n; n = n->right)
      {
!       if ((INT_CST_LT (n->low, min_ascii)) || INT_CST_LT (max_ascii, n->high))
  	return 0;
  
        for (i = (HOST_WIDE_INT) TREE_INT_CST_LOW (n->low);
--- 2664,2671 ----
  
    for (n = node; n; n = n->right)
      {
!       if (tree_int_cst_lt (n->low, min_ascii)
! 	  || tree_int_cst_lt (max_ascii, n->high))
  	return 0;
  
        for (i = (HOST_WIDE_INT) TREE_INT_CST_LOW (n->low);
Index: testsuite/gcc.c-torture/execute/pr34154.c
===================================================================
*** testsuite/gcc.c-torture/execute/pr34154.c	(revision 0)
--- testsuite/gcc.c-torture/execute/pr34154.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ int foo( unsigned long long aLL )
+ {
+     switch( aLL )
+     {
+         case 1000000000000000000ULL ... 9999999999999999999ULL : return 19 ; 
+         default                                 : return 20 ;
+     };
+ };
+ extern void abort (void);
+ int main()
+ {
+     unsigned long long aLL = 1000000000000000000ULL;
+     if (foo (aLL) != 19)
+ 	abort ();
+     return 0;
+ }


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