This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ipa/61144] [4.9/4.10 Regression] Invalid optimizations for extern vars with local weak definitions
- From: "bugdal at aerifal dot cx" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 20 May 2014 08:11:17 +0000
- Subject: [Bug ipa/61144] [4.9/4.10 Regression] Invalid optimizations for extern vars with local weak definitions
- Auto-submitted: auto-generated
- References: <bug-61144-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61144
--- Comment #19 from Rich Felker <bugdal at aerifal dot cx> ---
Here is the commit that seems to have introduced the bug:
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=df8d3e8981a99e264b49876f0f5064bdb30ac981
In the function ctor_for_folding, the following erroneous logic appears:
+ /* Non-readonly alias of readonly variable is also de-facto readonly,
+ because the variable itself is in readonly section.
+ We also honnor READONLY flag on alias assuming that user knows
+ what he is doing. */
+ if (!TREE_READONLY (decl) && !TREE_READONLY (real_decl))
+ return error_mark_node;
This treats the value of an alias as a compile-time constant if either the
alias itself or the alias target has TREE_READONLY being true. Replacing the &&
with || seems to make the problem go away in my test case, and makes a bit more
sense (perhaps that was the original intent?), but it's only sufficient if
TREE_READONLY is always false for weak aliases (since they can always be
overridden by a strong symbol from another translation unit, even if the alias
is const-qualified). I'm not sure where the value of TREE_READONLY is set for
aliases yet but I'll keep looking...