From c54b0a5e4b261487b58d4ec2db7219f8f5c7233d Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Sun, 1 Jul 2001 20:50:03 +0000 Subject: [PATCH] expr.c (expand_expr, [...]): Correct check for side-effects in the value of an array element. * 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 | 2 +- gcc/testsuite/g++.old-deja/g++.other/array6.C | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/array6.C diff --git a/gcc/expr.c b/gcc/expr.c index c5276f2556ec..afa55a687083 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -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 index 000000000000..ab076f2af383 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/array6.C @@ -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; +}; -- 2.47.2