diff mbox series

[committed] Add tests

Message ID 1ee589b9-55f6-d70d-77d7-9caa52377e47@redhat.com
State New
Headers show
Series [committed] Add tests | expand

Commit Message

Jeff Law Dec. 6, 2017, 11:50 p.m. UTC
Richi's fix for 83202 fixed a few other bugs in the BZ database.  This
patch adds regression tests for the 3 I trivially found.

Committing to the trunk.

Jeff
commit 813ce64afdf420b8d5e3fee59473f2527c5d0d4d
Author: Jeff Law <law@torsion.usersys.redhat.com>
Date:   Wed Dec 6 18:46:01 2017 -0500

            PR tree-optimization/69224
            PR tree-optimization/80907
            PR tree-optimization/82286
            * gcc.dg/pr69224.c: New test.
            * gcc.dg/pr80907.c: New test.
            * gcc.dg/pr82286.c: New test.

Comments

Martin Sebor Dec. 7, 2017, 3:14 a.m. UTC | #1
On 12/06/2017 04:50 PM, Jeff Law wrote:
>
> Richi's fix for 83202 fixed a few other bugs in the BZ database.  This
> patch adds regression tests for the 3 I trivially found.
>
> Committing to the trunk.

The test submitted in pr82286 relied on the ERROR macro being
defined to trigger the false positive (I tend to get tripped
by this style of tests).  It doesn't look to me like it has
changed in the regression test but the macro isn't defined.

Martin

diff --git a/gcc/testsuite/gcc.dg/pr82286.c b/gcc/testsuite/gcc.dg/pr82286.c
new file mode 100644
index 00000000000..13e22501d48
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82286.c
@@ -0,0 +1,60 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds" } */
+
+#include <stdio.h>
+#include <math.h>
+
+#define MAX_MATRIX_SIZE      (10)
+
...
+      sum = p_input_matrix->data[col][row] - sum;
+      if (row == col) {
+	if (sum >= 0.0) {
+#if ERROR
+	  tmp.data[row][col] = sqrtf (sum);
+#else
+	  tmp.data[row][col] = sum;
+#endif
+	}
diff mbox series

Patch

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d7196733dd8..3298549a9ca 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@ 
+2017-12-04  Jeff Law  <law@redhat.com>
+
+	PR tree-optimization/69224
+	PR tree-optimization/80907
+	PR tree-optimization/82286
+	* gcc.dg/pr69224.c: New test.
+	* gcc.dg/pr80907.c: New test.
+	* gcc.dg/pr82286.c: New test.
+
 2017-12-06  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/80259
diff --git a/gcc/testsuite/gcc.dg/pr69224.c b/gcc/testsuite/gcc.dg/pr69224.c
new file mode 100644
index 00000000000..606b7fee2ae
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69224.c
@@ -0,0 +1,27 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds" } */
+
+struct S {
+        int a;
+        int b;
+        int c;
+        int d;
+        int e;
+        float x[5];
+        float y[5];      // Comment these two lines out to
+        float z[5 - 1];  // remove the warning
+};
+void f(struct S *s, float a[], float **b, float c[]) {
+        if ((s->b == 1) && (s->d > 0)) {
+                for (int i = 0; i < s->a; i++) {
+                        if (a[i] != 0.0) {
+                                for (int j = 0; j < s->d - 1; j++) {
+                                        if ((c[i] >= s->x[j]) && (c[i] <= s->x[j + 1])) {
+                                                b[2*j][i] = s->x[j];
+                                                break;
+                                        }
+                                }
+                        }
+                }
+        }
+}
diff --git a/gcc/testsuite/gcc.dg/pr80907.c b/gcc/testsuite/gcc.dg/pr80907.c
new file mode 100644
index 00000000000..56e1d362593
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr80907.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds" } */
+
+
+
+int x[3];
+int n=2;
+void foo() 
+{
+    for(int i=0;i<n;i++) for(int j=0;j<=i;j++) x[i+j]++;
+}
+
diff --git a/gcc/testsuite/gcc.dg/pr82286.c b/gcc/testsuite/gcc.dg/pr82286.c
new file mode 100644
index 00000000000..13e22501d48
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82286.c
@@ -0,0 +1,60 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds" } */
+
+#include <stdio.h>
+#include <math.h>
+
+#define MAX_MATRIX_SIZE      (10)
+
+typedef struct
+{
+  unsigned int nof_rows;
+  unsigned int nof_cols;
+  float data[MAX_MATRIX_SIZE][MAX_MATRIX_SIZE];
+} MATRIX_TYPE;
+
+extern void mtrx_decompose_matrix (MATRIX_TYPE * p_input_matrix);
+
+void
+mtrx_decompose_matrix (MATRIX_TYPE * p_input_matrix)
+{
+  unsigned int row;
+  unsigned int col;
+  unsigned int sub;
+  float sum;
+  MATRIX_TYPE tmp;
+
+  for (row = 0; row < MAX_MATRIX_SIZE; row++) {
+    for (col = 0; col < MAX_MATRIX_SIZE; col++) {
+      tmp.data[row][col] = 0.0;
+    }
+  }
+  tmp.nof_cols = 0;
+  tmp.nof_rows = 0;
+
+  for (row = 0; row < p_input_matrix->nof_rows; row++) {
+    for (col = row; col < p_input_matrix->nof_cols; col++) {
+      sum = 0.0f;
+      for (sub = 0; sub < row; sub++) {
+	sum += tmp.data[row][sub] * tmp.data[col][sub];
+      }
+      sum = p_input_matrix->data[col][row] - sum;
+      if (row == col) {
+	if (sum >= 0.0) {
+#if ERROR
+	  tmp.data[row][col] = sqrtf (sum);
+#else
+	  tmp.data[row][col] = sum;
+#endif
+	}
+	else {
+	  tmp.data[row][col] = 0.0f;
+	}
+      }
+      else {
+	tmp.data[col][row] = sum / tmp.data[row][row];
+      }
+    }
+  }
+}
+