PR c/46921 Lost side effect when struct initializer expression uses comma operator
commit1b2ff8ae15d5750c8dcc7f494c0c3e89fb04373b
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Mar 2018 18:10:09 +0000 (13 18:10 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 13 Mar 2018 18:10:09 +0000 (13 18:10 +0000)
treefb467b2bf55a3765f69f31dbf4f572aef4e42353
parent3a484eea97ae64ec104d97f4e4eb3358cb1ff5ff
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258497 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr46921.c [new file with mode: 0644]