From: Alexander Monakov <amonakov@ispras.ru>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Rich Felker <dalias@libc.org>,
Richard Biener <richard.guenther@gmail.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] proposed fix for bug # 61144
Date: Tue, 22 Jul 2014 17:18:00 -0000 [thread overview]
Message-ID: <alpine.LNX.2.00.1407222054570.25299@monopod.intra.ispras.ru> (raw)
In-Reply-To: <20140616085601.GA14894@kam.mff.cuni.cz>
On Mon, 16 Jun 2014, Jan Hubicka wrote:
> > > /* Variables declared 'const' without an initializer
> > > have zero as the initializer if they may not be
> > > overridden at link or run time. */
> > > if (!DECL_INITIAL (real_decl)
> > > && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
> > > return error_mark_node;
> > >
> > > Honza?
> >
> > Indeed, this may be a better place to do it as long as
> > decl_replaceable_p reliably returns true for weak aliases. If so, the
> > following might work:
> >
> > if ((!DECL_INITIAL (real_decl) && DECL_EXTERNAL (decl))
> > || decl_replaceable_p (decl)))
> > return error_mark_node;
> >
> > On the other hand, I might just separate it out into two separate if
> > statements since they should probably have their own comments.
>
> Yep, this looks like correct change. I used to have FIXME on this but
> it seems it went away during some cleanups - the original condition was
> comming from expmed's folding and indeed it looked unsafe to me.
>
> This change is OK with the testcase (if it passes testing)
I'd like to push this topic forward a bit. I've bootstrapped and regtested a
version of the patch based on the initial proposal to check DECL_WEAK. The
approach with decl_replaceable_p looks not that easy; I'll expand in a
followup email.
OK for trunk/branch?
2014-07-22 Rich Felker <dalias@libc.org>
Alexander Monakov <amonakov@ispras.ru>
gcc/
PR ipa/61144
* varpool.c (ctor_for_folding): Reject weak data.
gcc/testsuite/
PR ipa/61144
* gcc.dg/special/wkali-3.c: New test.
* gcc.dg/special/wkali-3a.c: Auxiliary file.
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 04ce714..9ef2195 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -378,6 +378,9 @@ ctor_for_folding (tree decl)
return error_mark_node;
}
+ if (DECL_WEAK (decl) && !DECL_VIRTUAL_P (decl))
+ return error_mark_node;
+
gcc_assert (TREE_CODE (decl) == VAR_DECL);
real_node = node = varpool_get_node (decl);
diff --git a/gcc/testsuite/gcc.dg/special/wkali-3.c b/gcc/testsuite/gcc.dg/special/wkali-3.c
new file mode 100644
index 0000000..407ace6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/special/wkali-3.c
@@ -0,0 +1,17 @@
+/* { dg-do run } */
+/* { dg-require-weak "" } */
+/* { dg-require-alias "" } */
+/* { dg-additional-sources "wkali-3a.c" } */
+
+#include <stdlib.h>
+
+static const int dummy = 0;
+extern const int foo __attribute__((__weak__, __alias__("dummy")));
+
+int main(void) {
+
+ if (foo)
+ exit(0);
+ else
+ abort();
+}
diff --git a/gcc/testsuite/gcc.dg/special/wkali-3a.c b/gcc/testsuite/gcc.dg/special/wkali-3a.c
new file mode 100644
index 0000000..b3bc6a4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/special/wkali-3a.c
@@ -0,0 +1,3 @@
+/* { dg-do run } */
+
+int foo = 1;
next prev parent reply other threads:[~2014-07-22 17:10 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-21 1:59 Rich Felker
2014-05-21 9:17 ` Richard Biener
2014-05-22 3:59 ` Rich Felker
2014-05-23 18:26 ` Jeff Law
2014-06-06 17:14 ` Rich Felker
2014-06-09 11:41 ` Alexander Monakov
2014-06-09 18:46 ` Rich Felker
2014-06-16 9:06 ` Jan Hubicka
2014-06-16 13:38 ` Rich Felker
2014-06-16 16:05 ` Jan Hubicka
2014-06-16 16:35 ` Rich Felker
2014-06-14 21:24 ` Rich Felker
2014-06-16 8:56 ` Jan Hubicka
2014-07-22 17:18 ` Alexander Monakov [this message]
2014-07-22 17:23 ` Alexander Monakov
2014-07-22 17:30 ` Rich Felker
2014-07-23 9:06 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LNX.2.00.1407222054570.25299@monopod.intra.ispras.ru \
--to=amonakov@ispras.ru \
--cc=dalias@libc.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).