diff mbox

Fix for PR c/57490

Message ID BF230D13CA30DD48930C31D4099330003A43C80E@FMSMSX101.amr.corp.intel.com
State New
Headers show

Commit Message

Iyer, Balaji V July 1, 2013, 4:17 p.m. UTC
Hello Everyone,	
	This patch fixes the issue in PR 57490. The issue was that, the C and C++ implementation was not handling array notations inside TRUTH_*_EXPR. I added them and added  the .i test case. Is this OK for trunk?

Here are ChangeLog entries:

gcc/c/ChangeLog
+2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+       * c-array-notation.c (fix_conditional_array_notations_1): Added a
+       check for truth values.
+       (expand_array_notation_exprs): Added truth values case.  Removed an
+       unwanted else.  Added for-loop to walk through subtrees in default
+       case.
+

gcc/cp/ChangeLog
+2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+       * cp-array-notation.c (cp_expand_cond_array_notations): Added a
+       check for truth values.
+       (expand_array_notation_exprs): Added truth values case.  Removed an
+       unwanted else.  Added for-loop to walk through subtrees in default
+       case.
+

gcc/testsuite/ChangeLog
+2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
+
+       PR c/57490
+       * c-c++-common/cilk-plus/AN/pr57490.i: New test.
+       * gcc.dg/cilk-plus/cilk-plus.exp: Added compilation of .i files.
+


Thanks,

Balaji V. Iyer.

Comments

Jakub Jelinek July 1, 2013, 4:24 p.m. UTC | #1
On Mon, Jul 01, 2013 at 04:17:37PM +0000, Iyer, Balaji V wrote:
> gcc/c/ChangeLog
> +2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
> +

The PR c/57490 line belongs to all ChangeLog entries related to the fix, not
just testsuite.

> +       * c-array-notation.c (fix_conditional_array_notations_1): Added a
> +       check for truth values.
> +       (expand_array_notation_exprs): Added truth values case.  Removed an
> +       unwanted else.  Added for-loop to walk through subtrees in default
> +       case.
> +
> 
> gcc/cp/ChangeLog
> +2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
> +
> +       * cp-array-notation.c (cp_expand_cond_array_notations): Added a
> +       check for truth values.
> +       (expand_array_notation_exprs): Added truth values case.  Removed an
> +       unwanted else.  Added for-loop to walk through subtrees in default
> +       case.

I'll leave this to C/C++ maintainers.

> gcc/testsuite/ChangeLog
> +2013-07-01  Balaji V. Iyer  <balaji.v.iyer@intel.com>
> +
> +       PR c/57490
> +       * c-c++-common/cilk-plus/AN/pr57490.i: New test.
> +       * gcc.dg/cilk-plus/cilk-plus.exp: Added compilation of .i files.

Ugh, no.  Please add the test as *.c test instead, and strip all the
unneeded garbage from it.  It would surprise me a lot if the # line ...,
#pragma ident or blank lines were required to reproduce the problem.

	Jakub
diff mbox

Patch

diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index 7788f7b..5747bcb 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -906,6 +906,8 @@  fix_conditional_array_notations_1 (tree stmt)
     cond = COND_EXPR_COND (stmt);
   else if (TREE_CODE (stmt) == SWITCH_EXPR)
     cond = SWITCH_COND (stmt);
+  else if (truth_value_p (TREE_CODE (stmt)))
+    cond = TREE_OPERAND (stmt, 0);
   else
     /* Otherwise dont even touch the statement.  */
     return stmt;
@@ -1232,6 +1234,12 @@  expand_array_notation_exprs (tree t)
     case BIND_EXPR:
       t = expand_array_notation_exprs (BIND_EXPR_BODY (t));
       return t;
+    case TRUTH_ORIF_EXPR:
+    case TRUTH_ANDIF_EXPR:
+    case TRUTH_OR_EXPR:
+    case TRUTH_AND_EXPR:
+    case TRUTH_XOR_EXPR:
+    case TRUTH_NOT_EXPR:
     case COND_EXPR:
       t = fix_conditional_array_notations (t);
 
@@ -1246,8 +1254,6 @@  expand_array_notation_exprs (tree t)
 	    COND_EXPR_ELSE (t) =
 	      expand_array_notation_exprs (COND_EXPR_ELSE (t));
 	}
-      else
-	t = expand_array_notation_exprs (t);
       return t;
     case STATEMENT_LIST:
       {
@@ -1284,6 +1290,10 @@  expand_array_notation_exprs (tree t)
 	 Replace those with just void zero node.  */
       t = void_zero_node;
     default:
+      for (int ii = 0; ii < TREE_CODE_LENGTH (TREE_CODE (t)); ii++)
+	if (contains_array_notation_expr (TREE_OPERAND (t, ii)))
+	  TREE_OPERAND (t, ii) =
+	    expand_array_notation_exprs (TREE_OPERAND (t, ii));
       return t;
     }
   return t;
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index d279ddd..164106f 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -857,6 +857,19 @@  cp_expand_cond_array_notations (tree orig_stmt)
 	  return error_mark_node;
 	}
     }
+  else if (truth_value_p (TREE_CODE (orig_stmt)))
+    {
+      size_t left_rank = 0, right_rank = 0;
+      tree left_expr = TREE_OPERAND (orig_stmt, 0);
+      tree right_expr = TREE_OPERAND (orig_stmt, 1);
+      if (!find_rank (EXPR_LOCATION (left_expr), left_expr, left_expr, true,
+		      &left_rank)
+	  || !find_rank (EXPR_LOCATION (right_expr), right_expr, right_expr,
+			 true, &right_rank))
+	return error_mark_node;
+      if (right_rank == 0 && left_rank == 0)
+	return orig_stmt;
+    }
 
   if (!find_rank (EXPR_LOCATION (orig_stmt), orig_stmt, orig_stmt, true,
 		  &rank))
@@ -1213,6 +1226,12 @@  expand_array_notation_exprs (tree t)
       if (TREE_OPERAND (t, 0) == error_mark_node)
 	return TREE_OPERAND (t, 0); 
       return t;
+    case TRUTH_ANDIF_EXPR:
+    case TRUTH_ORIF_EXPR:
+    case TRUTH_AND_EXPR:
+    case TRUTH_OR_EXPR:
+    case TRUTH_XOR_EXPR:
+    case TRUTH_NOT_EXPR:
     case COND_EXPR:
       t = cp_expand_cond_array_notations (t);
       if (TREE_CODE (t) == COND_EXPR)
@@ -1222,8 +1241,6 @@  expand_array_notation_exprs (tree t)
 	  COND_EXPR_ELSE (t) =
 	    expand_array_notation_exprs (COND_EXPR_ELSE (t));
 	}
-      else
-	t = expand_array_notation_exprs (t);
       return t;
     case FOR_STMT:
       if (contains_array_notation_expr (FOR_COND (t)))
diff --git a/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.i b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.i
new file mode 100644
index 0000000..51aaab2
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cilk-plus/AN/pr57490.i
@@ -0,0 +1,43 @@ 
+# 1 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c"
+# 1 "<command-line>"
+# 1 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c"
+
+
+
+
+
+
+# 1 "/usr/include/assert.h" 1 3 4
+# 16 "/usr/include/assert.h" 3 4
+#pragma ident "@(#)assert.h  1.10	04/05/18 SMI"
+# 26 "/usr/include/assert.h" 3 4
+extern void __assert(const char *, const char *, int);
+# 8 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c" 2
+
+const int n = 8;
+
+float x[8], y[8], z[8];
+
+int main() {
+    int i = 0;
+    float x_sum =0;
+    for(i=1; i<=5; i+=4 ) {
+        x[0:n] = 3;
+        y[0:n] = i;
+        z[0:n] = 0;
+# 28 "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c"
+        (void)((__sec_reduce_add(x[0:n])==3*n) || (__assert("__sec_reduce_add(x[0:n])==3*n", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 28), 0));
+        (void)((__sec_reduce_add(y[0:n])==i*n) || (__assert("__sec_reduce_add(y[0:n])==i*n", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 29), 0));
+        (void)((__sec_reduce_add(z[0:n])==0) || (__assert("__sec_reduce_add(z[0:n])==0", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 30), 0));
+
+        if (x[0:n] >= y[0:n]) {
+            z[0:n] = x[0:n] - y[0:n];
+        } else {
+            z[0:n] = x[0:n] + y[0:n];
+        }
+        (void)((__sec_reduce_add(x[0:n])==3*n) || (__assert("__sec_reduce_add(x[0:n])==3*n", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 43), 0));
+        (void)((__sec_reduce_add(y[0:n])==i*n) || (__assert("__sec_reduce_add(y[0:n])==i*n", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 44), 0));
+        (void)((__sec_reduce_add(z[0:n])==(3>=i?3-i:3+i)*n) || (__assert("__sec_reduce_add(z[0:n])==(3>=i?3-i:3+i)*n", "/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/cilk-plus/AN/an-if.c", 45), 0));
+    }
+    return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cilk-plus/cilk-plus.exp b/gcc/testsuite/gcc.dg/cilk-plus/cilk-plus.exp
index 59b2305..d908b68 100644
--- a/gcc/testsuite/gcc.dg/cilk-plus/cilk-plus.exp
+++ b/gcc/testsuite/gcc.dg/cilk-plus/cilk-plus.exp
@@ -20,26 +20,26 @@ 
 load_lib gcc-dg.exp
 
 dg-init
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O0 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O1 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O2 -ftree-vectorize -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O3 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O0 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O1 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O2 -ftree-vectorize -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -g -O3 -fcilkplus" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O3 -ftree-vectorize -fcilkplus -g" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -O0 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -O1 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -O2 -ftree-vectorize -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -O3 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -g -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -g -O0 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -g -O1 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -g -O2 -ftree-vectorize -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -fcilkplus -g -O3 -std=c99" " "
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.c]] " -O3 -ftree-vectorize -std=c99 -g -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O0 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O1 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O2 -ftree-vectorize -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O3 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -g -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -g -O0 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -g -O1 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -g -O2 -ftree-vectorize -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -g -O3 -fcilkplus" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O3 -ftree-vectorize -fcilkplus -g" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -O0 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -O1 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -O2 -ftree-vectorize -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -O3 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -g -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -g -O0 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -g -O1 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -g -O2 -ftree-vectorize -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -fcilkplus -g -O3 -std=c99" " "
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cilk-plus/AN/*.\[ci\]]] " -O3 -ftree-vectorize -std=c99 -g -fcilkplus" " "
 dg-finish