On 10/22/14 06:58, Richard Biener wrote:
The following fixes a bug in fold-const.c which happily drops side-effects when simplifying X - X to 0. I ran into this because on match-and-simplify I cannot simplify expressions with TREE_SIDE_EFFECTS and it happens that TYPE_SIZE for VLAs has side-effects because it usually contains a SAVE_EXPR which are forced to have side-effects (even if its arg does not have side-effects). This is appearantly because you can use SAVE_EXPRs to force creation of initialized temporaries at defined place in the instruction stream. For example fold-const.c currently would miscompile (save_expr<global> - save_expr<global>, (global = 1, save_expr<global>)) Of course all this makes my life hard on match-and-simplify branch and I wonder why we need to use SAVE_EXPRs for these cases where the initialization of a new temporary could be done explicitely (using INIT_EXPR or TARGET_EXPR). Anyway - fixing the fold-const.c bug requires fixing the bug I run into on match-and-simplify branch - here by simply "stripping" the side-effects to get to the actual difference of the two DECL_FIELD_OFFSETs (I wonder if I missed an obvious tool to do such stripping). Bootstrap & regtest running on x86_64-unknown-linux-gnu. Of course this doesn't help me on match-and-simplify branch (example testcase that ICEs there with the assert in stor-layout.c visible below is gcc.c-torture/execute/20040308-1.c). In theory it should be ok to simplify these late in GIMPLE and for the stor-layout.c case unset TREE_SIDE_EFFECTS temporarily to make generic_simplify happy ... (ugh). Thanks, Richard. 2014-10-22 Richard Biener <rguent...@suse.de> * fold-const.c (fold_binary_loc): Preserve side-effects of X - X when simplifying to 0. * stor-layout.c (finish_bitfield_representative): Strip side-effects of evaluating the difference of two DECL_FIELD_OFFSET.
OK. jeff