https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68764
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=66618, | |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=69960 Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Fixed for GCC 8 by r8-4755-gf9c59f7e9511 (aka PR 66618 and PR 69960). Explicitly this part of c_fully_fold_internal: /* Constants, declarations, statements, errors, and anything else not counted as an expression cannot usefully be folded further at this point. */ - if (!IS_EXPR_CODE_CLASS (kind) - || kind == tcc_statement) - return expr; + if (!IS_EXPR_CODE_CLASS (kind) || kind == tcc_statement) + { + /* Except for variables which we can optimize to its initializer. */ + if (VAR_P (expr) && !lval && (optimize || in_init)) + { + ret = decl_constant_value (expr); + /* Avoid unwanted tree sharing between the initializer and current + function's body where the tree can be modified e.g. by the + gimplifier. */ + if (ret != expr && TREE_STATIC (expr)) + ret = unshare_expr (ret); + return ret; + } + return expr; + }