On Wed, Nov 08, 2017 at 06:38:21PM +0100, Jakub Jelinek wrote: > On Wed, Nov 08, 2017 at 05:17:50PM +0000, Joseph Myers wrote: > > On Wed, 8 Nov 2017, Jakub Jelinek wrote: > > > > > of course only if LVAL is false. Additionally, I've added folding of > > > "foo"[2] into 'o'. We have it in gimple-fold.c or so, so that one > > > > Note that if the 2 there comes from an overflowing expression that's not > > valid as an extension to constant expressions in initializers (that is, > > > > static char c = "foo"[INT_MAX * -2]; > > > > should result in an error with -pedantic-errors because of the overflow, > > just as INT_MAX * -2 by itself wouldn't be a valid initializer in that > > case). > > > > > Not sure about the COND_EXPR/VEC_COND_EXPR cases, right now I'm passing > > > false as LVAL for the first operand (condition) and lval as LVAL for the > > > other two (i.e. if called with lval == true on the whole *_COND_EXPR > > > decl_constant_value_for_optimization etc. isn't performed on op1/op2, > > > while > > > without it it is). Can one take address of the whole COND_EXPR, or > > > have it on LHS of anything in C? If not, perhaps I could just pass false > > > in all the 3 calls. Though, then likely it would be called with lval == > > > false > > > anyway. > > > > Conditional and compound expressions are never valid lvalues in C. > > Ok, so like this if it passes bootstrap/regtest? > > Changes from the last patch: > 1) false instead of lval for COMPOUND_EXPR and *COND_EXPR op1/op2
So... > @@ -278,21 +339,16 @@ c_fully_fold_internal (tree expr, bool i > orig_op0 = op0 = TREE_OPERAND (expr, 0); > orig_op1 = op1 = TREE_OPERAND (expr, 1); > op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands, > - maybe_const_itself, for_int_const); > + maybe_const_itself, for_int_const, > + op0_lval); > STRIP_TYPE_NOPS (op0); > - if (code != MODIFY_EXPR > - && code != PREDECREMENT_EXPR > - && code != PREINCREMENT_EXPR > - && code != POSTDECREMENT_EXPR > - && code != POSTINCREMENT_EXPR) > - op0 = decl_constant_value_for_optimization (op0); > /* The RHS of a MODIFY_EXPR was fully folded when building that > expression for the sake of conversion warnings. */ > if (code != MODIFY_EXPR) > op1 = c_fully_fold_internal (op1, in_init, maybe_const_operands, > - maybe_const_itself, for_int_const); > + maybe_const_itself, for_int_const, > + code == COMPOUND_EXPR ? lval : false); ...shouldn't we be passing just false here? Marek