diff mbox

Fix PR78742

Message ID alpine.LSU.2.11.1612091150310.5294@t29.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Dec. 9, 2016, 10:53 a.m. UTC
The following fixes the bug for the particular testcase by making
cst_and_fits_in_hwi look at the actual value of the constant.

There's still underlying issues in dependence analysis (using ints
to store HOST_WIDE_INTs, failing to check whether the constants
really fit).  But this one makes us behave sanely for sane testcases
and the cst_and_fits_in_hwi should go in independently.

When grepping for cst_and_fits_in_hwi I also spotted one bogus 
use of the predicate.

Bootstrap & regtest pending on x86_64-unknown-linux-gnu.

Richard.

2016-12-09  Richard Biener  <rguenther@suse.de>

	PR middle-end/78742
	* tree.c (cst_and_fits_in_hwi): Look if the actual value fits.
	* tree-object-size.c (compute_builtin_object_size): Use
	tree_fits_shwi_p.
	* tree-data-ref.c (initialize_matrix_A): Remove excess assert.

	* gcc.dg/torture/pr78742.c: New testcase.
diff mbox

Patch

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	(revision 243474)
+++ gcc/tree.c	(working copy)
@@ -1677,7 +1677,7 @@  bool
 cst_and_fits_in_hwi (const_tree x)
 {
   return (TREE_CODE (x) == INTEGER_CST
-	  && TYPE_PRECISION (TREE_TYPE (x)) <= HOST_BITS_PER_WIDE_INT);
+	  && (tree_fits_shwi_p (x) || tree_fits_uhwi_p (x)));
 }
 
 /* Build a newly constructed VECTOR_CST node of length LEN.  */
Index: gcc/tree-object-size.c
===================================================================
--- gcc/tree-object-size.c	(revision 243474)
+++ gcc/tree-object-size.c	(working copy)
@@ -533,7 +533,7 @@  compute_builtin_object_size (tree ptr, i
 	      tree offset = gimple_assign_rhs2 (def);
 	      ptr = gimple_assign_rhs1 (def);
 
-	      if (cst_and_fits_in_hwi (offset)
+	      if (tree_fits_shwi_p (offset)
 		  && compute_builtin_object_size (ptr, object_size_type, psize))
 		{
 		  /* Return zero when the offset is out of bounds.  */
Index: gcc/tree-data-ref.c
===================================================================
--- gcc/tree-data-ref.c	(revision 243474)
+++ gcc/tree-data-ref.c	(working copy)
@@ -2118,8 +2114,6 @@  initialize_matrix_A (lambda_matrix A, tr
   switch (TREE_CODE (chrec))
     {
     case POLYNOMIAL_CHREC:
-      gcc_assert (TREE_CODE (CHREC_RIGHT (chrec)) == INTEGER_CST);
-
       A[index][0] = mult * int_cst_value (CHREC_RIGHT (chrec));
       return initialize_matrix_A (A, CHREC_LEFT (chrec), index + 1, mult);
 
Index: gcc/testsuite/gcc.dg/torture/pr78742.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr78742.c	(revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr78742.c	(working copy)
@@ -0,0 +1,20 @@ 
+/* { dg-do compile } */
+/* { dg-require-effective-target int128 } */
+
+void foo();
+
+void func()
+{
+  int m;
+
+  int tab[m];
+
+  __int128 j;
+  for(; j; j++)
+    {
+      tab[j] = 0;
+      tab[j+1] = 0;
+    }
+
+  foo();
+}