public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/68764] C frontend does not fold away trivial expressions that refer to const variables
[not found] <bug-68764-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-24 22:20 ` pinskia at gcc dot gnu.org
2021-09-27 20:42 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-24 22:20 UTC (permalink / raw)
To: gcc-bugs
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;
+ }
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/68764] C frontend does not fold away trivial expressions that refer to const variables
[not found] <bug-68764-4@http.gcc.gnu.org/bugzilla/>
2021-09-24 22:20 ` [Bug c/68764] C frontend does not fold away trivial expressions that refer to const variables pinskia at gcc dot gnu.org
@ 2021-09-27 20:42 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-27 20:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68764
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |8.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-27 20:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-68764-4@http.gcc.gnu.org/bugzilla/>
2021-09-24 22:20 ` [Bug c/68764] C frontend does not fold away trivial expressions that refer to const variables pinskia at gcc dot gnu.org
2021-09-27 20:42 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).