aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorDavid Pagan <dave.pagan@oracle.com>2018-03-13 18:10:09 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2018-03-13 18:10:09 +0000
commitada6bad9780d405aea40acbea4f0813b05e3733a (patch)
treefb467b2bf55a3765f69f31dbf4f572aef4e42353 /gcc/c
parentb34f5c5e69bb024f41b4e15869f7ff18c3f8dd6f (diff)
downloadgcc-ada6bad9780d405aea40acbea4f0813b05e3733a.zip
gcc-ada6bad9780d405aea40acbea4f0813b05e3733a.tar.gz
gcc-ada6bad9780d405aea40acbea4f0813b05e3733a.tar.bz2
PR c/46921 Lost side effect when struct initializer expression uses comma operator
This patch fixes improper handling of comma operator expression in a struct field initializer as described in: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46921 Currently, function output_init_element () does not evaluate the left hand expression in a comma operator that's used for a struct initializer field if the right hand side is zero-sized. However, the left hand expression must be evaluated if it's found to have side effects (for example, a function call). Patch was successfully bootstrapped and tested on x86_64-linux. gcc/c: 2018-03-13 David Pagan <dave.pagan@oracle.com> PR c/46921 * c-typeck.c (output_init_element): Ensure field initializer expression is always evaluated if there are side effects. gcc/testsuite: 2018-03-13 David Pagan <dave.pagan@oracle.com> PR c/46921 * gcc.dg/pr46921.c: New test. From-SVN: r258497
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 599ffa2..8147835 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2018-03-13 David Pagan <dave.pagan@oracle.com>
+
+ PR c/46921
+ * c-typeck.c (output_init_element): Ensure field initializer
+ expression is always evaluated if there are side effects.
+
2018-03-06 Jakub Jelinek <jakub@redhat.com>
PR c/84721
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 1eae4ea..2ac8500 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -9208,12 +9208,14 @@ output_init_element (location_t loc, tree value, tree origtype,
"enum conversion in initialization is invalid in C++");
}
- /* If this field is empty (and not at the end of structure),
- don't do anything other than checking the initializer. */
+ /* If this field is empty and does not have side effects (and is not at
+ the end of structure), don't do anything other than checking the
+ initializer. */
if (field
&& (TREE_TYPE (field) == error_mark_node
|| (COMPLETE_TYPE_P (TREE_TYPE (field))
&& integer_zerop (TYPE_SIZE (TREE_TYPE (field)))
+ && !TREE_SIDE_EFFECTS (new_value)
&& (TREE_CODE (constructor_type) == ARRAY_TYPE
|| DECL_CHAIN (field)))))
return;