[Bug c/46921] Lost side effect when struct initializer expression uses comma operator

2018-03-13 Thread jsm28 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46921

--- Comment #5 from Joseph S. Myers  ---
Author: jsm28
Date: Tue Mar 13 18:10:09 2018
New Revision: 258497

URL: https://gcc.gnu.org/viewcvs?rev=258497&root=gcc&view=rev
Log:
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  

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  

PR c/46921
* gcc.dg/pr46921.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/pr46921.c
Modified:
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/testsuite/ChangeLog

[Bug c/46921] Lost side effect when struct initializer expression uses comma operator

2018-03-13 Thread jsm28 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46921

Joseph S. Myers  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |8.0

--- Comment #6 from Joseph S. Myers  ---
Fixed for GCC 8.

[Bug c/46921] Lost side effect when struct initializer expression uses comma operator

2018-03-02 Thread dave.pagan at oracle dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46921

--- Comment #4 from Dave Pagan  ---
Patch submitted for review:

https://gcc.gnu.org/ml/gcc-patches/2018-02/msg01471.html

[Bug c/46921] Lost side effect when struct initializer expression uses comma operator

2018-02-21 Thread dave.pagan at oracle dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46921

Dave Pagan  changed:

   What|Removed |Added

Summary|Dropped side effect with|Lost side effect when
   |combination of statement|struct initializer
   |expression and struct   |expression uses comma
   |initializer |operator

--- Comment #3 from Dave Pagan  ---
When emitting initializer elements (output_init_element), the left hand
expression of a comma operator with result size zero is not evaluated. It
should be, however, if the expression is marked as having side effects.