expr.c (expand_expr, [...]): Correct check for side-effects in the value of an array...
authorMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Jul 2001 20:50:03 +0000 (20:50 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sun, 1 Jul 2001 20:50:03 +0000 (20:50 +0000)
* expr.c (expand_expr, case ARRAY_REF): Correct check for
side-effects in the value of an array element.

From-SVN: r43680

gcc/expr.c
gcc/testsuite/g++.old-deja/g++.other/array6.C [new file with mode: 0644]

index c5276f2556ecbc95b718f8824cd66a359c855dbf..afa55a687083d2703f42001031a8192fd13c83cf 100644 (file)
@@ -6902,7 +6902,7 @@ expand_expr (exp, target, tmode, modifier)
                         elem = TREE_CHAIN (elem))
                      ;
 
-                   if (elem && !TREE_SIDE_EFFECTS (elem))
+                   if (elem && !TREE_SIDE_EFFECTS (TREE_VALUE (elem)))
                      return expand_expr (fold (TREE_VALUE (elem)), target,
                                          tmode, ro_modifier);
                  }
diff --git a/gcc/testsuite/g++.old-deja/g++.other/array6.C b/gcc/testsuite/g++.old-deja/g++.other/array6.C
new file mode 100644 (file)
index 0000000..ab076f2
--- /dev/null
@@ -0,0 +1,20 @@
+// Special g++ Options: -O1
+
+int count = 0;
+
+double foo () {
+  count++;
+  return 0;
+};
+
+double bar () {
+  const double x[1] = { foo() };
+  return x[0];
+};
+
+int main () 
+{
+  bar();
+  if (count != 1)
+    return 1;
+};