I was just testing the patch below which runs into latent issues when
building libjava (at least)...

/space/rguenther/src/svn/trunk/libjava/java/lang/natClassLoader.cc: In 
function ‘java::lang::Class* _Jv_FindClassInCache(_Jv_Utf8Const*)’:
/space/rguenther/src/svn/trunk/libjava/java/lang/natClassLoader.cc:97:1: 
error:BB 3 last statement has incorrectly set lp
 _Jv_FindClassInCache (_Jv_Utf8Const *name)
 ^
/space/rguenther/src/svn/trunk/libjava/java/lang/natClassLoader.cc:97:1: 
internal compiler error: verify_flow_info failed
0x8e2132 verify_flow_info()
        /space/rguenther/src/svn/trunk/gcc/cfghooks.c:261

so I have to debug that first.  Still IMHO the patch makes sense apart
from the ugly need to go through a INTEGER_CST tree when converting
a wide_int to a widest_int (ugh).  Any wide-int folks around that
can suggest something better here (reason: the two integers we compare
do not have to have the same type/precision - see tree_int_cst_lt
which also uses widest_ints).

Richard.

2015-07-10  Richard Biener  <rguent...@suse.de>

        * tree-eh.c (in_array_bounds_p): Use value-range information
        when available.

Index: gcc/tree-eh.c
===================================================================
--- gcc/tree-eh.c       (revision 225655)
+++ gcc/tree-eh.c       (working copy)
@@ -2532,8 +2532,11 @@ in_array_bounds_p (tree ref)
 {
   tree idx = TREE_OPERAND (ref, 1);
   tree min, max;
+  wide_int idx_min, idx_max;
 
-  if (TREE_CODE (idx) != INTEGER_CST)
+  if (TREE_CODE (idx) != INTEGER_CST
+      && (TREE_CODE (idx) != SSA_NAME
+         || get_range_info (idx, &idx_min, &idx_max) != VR_RANGE))
     return false;
 
   min = array_ref_low_bound (ref);
@@ -2544,11 +2547,26 @@ in_array_bounds_p (tree ref)
       || TREE_CODE (max) != INTEGER_CST)
     return false;
 
-  if (tree_int_cst_lt (idx, min)
-      || tree_int_cst_lt (max, idx))
-    return false;
+  if (TREE_CODE (idx) == INTEGER_CST)
+    {
+      if (tree_int_cst_lt (idx, min)
+         || tree_int_cst_lt (max, idx))
+       return false;
+
+      return true;
+    }
+  else
+    {
+      if (wi::lts_p (wi::to_widest (wide_int_to_tree (TREE_TYPE (idx),
+                                                     idx_min)),
+                    wi::to_widest (min))
+         || wi::lts_p (wi::to_widest (max),
+                       wi::to_widest (wide_int_to_tree (TREE_TYPE (idx),
+                                                        idx_max))))
+       return false;
 
-  return true;
+      return true;
+    }
 }
 
 /* Returns true if it is possible to prove that the range of

Reply via email to