public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Franz Sirl <Franz.Sirl-kernel@lauterbach.com>
To: gcc-patches@gcc.gnu.org
Cc: Jason Merrill <jason@redhat.com>,
	Richard Henderson <rth@redhat.com>,
	Alan Modra <amodra@bigpond.net.au>,
	Mark Mitchell <mark@codesourcery.com>,
	gcc@gcc.gnu.org
Subject: [PATCH] Fix PR c/6343 (was: Re: GCC 3.1 Prerelease)
Date: Thu, 25 Apr 2002 12:57:00 -0000	[thread overview]
Message-ID: <200204252121.58902@enzo.bigblue.local> (raw)
In-Reply-To: <wvly9fcvpb9.fsf@prospero.cambridge.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2228 bytes --]

On Wednesday 24 April 2002 22:01, Jason Merrill wrote:
> >>>>> "Franz" == Franz Sirl <Franz.Sirl-kernel@lauterbach.com> writes:
> >
> > Hmm, it seems to make more sense for the warning check too, with
> > TREE_USED changed to TREE_SYMBOL_REFERENCED the c++ regression
> > g++.old-deja/g++.jason/template39.C went away along with a bunch of
> > regressions in the libstdc++ testsuite, except one:
> >
> > FAIL: 26_numerics/complex_inserters_extractors.cc (test for excess
> > errors) Excess errors:
> > /home/fsirl/TC/gcc/BUILD/obj-gcc31-ppc/ppc-linux/libstdc++-v3/include/bit
> >s/basic_string.h: In instantiation of `const size_t
> > std::basic_string<char, gnu_char_traits, std::allocator<char> >::npos':
> > /home/fsirl/TC/gcc/BUILD/gcc-3.1/libstdc++-v3/testsuite/26_numerics/compl
> >ex_inserters_extractors.cc:109: instantiated from here
> > /home/fsirl/TC/gcc/BUILD/obj-gcc31-ppc/ppc-linux/libstdc++-v3/include/bit
> >s/basic_string.h:217: warning: weak declaration of `const size_t
> > std::basic_string<char, gnu_char_traits, std::allocator<char> >::npos'
> > after first use may result in unspecified behaviour
> >
> > Can a c++ expert tell me if this warning makes sense in this testcase or
> > does the warning check need still more refinement?
>
> The latter.  We don't want to warn about the C++ frontend's internal
> trickery with DECL_WEAK.

What kind of trickery? Can I detect that in declare_weak?

> I'd prefer to omit the warning entirely on the branch.

Well, I prefer overzealous warnings over no warning at all in the same way I 
prefer ICEs over miscompiled code :-). Besides that extra warning, I'm really 
satisfied now with my patch otherwise and unless you think it's overly 
complicated to get rid of it, I would like to fix it even for the branch.

Attached the patch I successfully bootstrapped and regtested (minus the 
additional libstdc++ fail) on powerpc-linux-gnu and x86-linux-gnu.

Franz.

	PR c/6343
	* c-decl.c (duplicate_decls): Use declare_weak to merge weak status.
	* varasm.c (declare_weak): Make sure we don't give an error on VAR_DECLs.
	Warn about potential miscompilations.
	Mark RTL with SYMBOL_REF_WEAK.

cp:
	* decl.c (duplicate_decls): Use declare_weak to merge weak status.


[-- Attachment #2: gcc-weaksym-6.patch --]
[-- Type: text/plain, Size: 2826 bytes --]

Index: gcc/c-decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.300.2.5
diff -u -p -r1.300.2.5 c-decl.c
--- gcc/c-decl.c	28 Mar 2002 18:49:57 -0000	1.300.2.5
+++ gcc/c-decl.c	23 Apr 2002 21:41:28 -0000
@@ -1955,7 +1955,11 @@ duplicate_decls (newdecl, olddecl, diffe
     }
 
   /* Merge the storage class information.  */
-  DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
+  if (DECL_WEAK (newdecl) && !DECL_WEAK (olddecl))
+    declare_weak (olddecl);
+  if (!DECL_WEAK (newdecl) && DECL_WEAK (olddecl))
+    declare_weak (newdecl);
+
   /* For functions, static overrides non-static.  */
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
Index: gcc/varasm.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.250.2.7
diff -u -p -r1.250.2.7 varasm.c
--- gcc/varasm.c	25 Mar 2002 00:54:26 -0000	1.250.2.7
+++ gcc/varasm.c	23 Apr 2002 21:41:28 -0000
@@ -4998,17 +4998,25 @@ declare_weak (decl)
 {
   if (! TREE_PUBLIC (decl))
     error_with_decl (decl, "weak declaration of `%s' must be public");
-  else if (TREE_ASM_WRITTEN (decl))
+  else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
     error_with_decl (decl, "weak declaration of `%s' must precede definition");
   else if (SUPPORTS_WEAK)
     {
       if (! DECL_WEAK (decl))
 	weak_decls = tree_cons (NULL, decl, weak_decls);
+      if (TREE_CODE (decl) != FUNCTION_DECL && TREE_USED (decl))
+	warning_with_decl (decl, "weak declaration of `%s' after first use may result in unspecified behaviour");
     }
   else
     warning_with_decl (decl, "weak declaration of `%s' not supported");
 
   DECL_WEAK (decl) = 1;
+
+  if (DECL_RTL_SET_P (decl)
+      && GET_CODE (DECL_RTL (decl)) == MEM
+      && XEXP (DECL_RTL (decl), 0)
+      && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
+    SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
 }
 
 /* Emit any pending weak declarations.  */
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.866.2.23
diff -u -p -r1.866.2.23 decl.c
--- gcc/cp/decl.c	16 Apr 2002 03:15:54 -0000	1.866.2.23
+++ gcc/cp/decl.c	23 Apr 2002 21:41:28 -0000
@@ -3645,7 +3645,11 @@ duplicate_decls (newdecl, olddecl)
     }
 
   /* Merge the storage class information.  */
-  DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
+  if (DECL_WEAK (newdecl) && !DECL_WEAK (olddecl))
+    declare_weak (olddecl);
+  if (!DECL_WEAK (newdecl) && DECL_WEAK (olddecl))
+    declare_weak (newdecl);
+
   DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl);
   DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);

  reply	other threads:[~2002-04-25 19:23 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23  2:12 GCC 3.1 Prerelease Mark Mitchell
2002-04-23  3:53 ` Alan Modra
2002-04-23  4:13   ` Franz Sirl
2002-04-23  4:32     ` Alan Modra
2002-04-23 10:40       ` Franz Sirl
2002-04-23 11:42         ` Richard Henderson
2002-04-23 15:08           ` Franz Sirl
2002-04-23 15:10             ` Richard Henderson
2002-04-24 10:56             ` Jason Merrill
2002-04-24 12:04               ` Franz Sirl
2002-04-24 13:03                 ` Richard Henderson
2002-04-24 13:14                 ` Jason Merrill
2002-04-25 12:57                   ` Franz Sirl [this message]
2002-04-25 12:59                     ` [PATCH] Fix PR c/6343 (was: Re: GCC 3.1 Prerelease) Jason Merrill
2002-04-28  8:44                       ` Franz Sirl
2002-04-28 11:59                         ` Mark Mitchell
2002-04-28 15:00                         ` Jason Merrill
2002-04-28 16:36                           ` Mark Mitchell
2002-04-29 11:36                           ` Franz Sirl
2002-04-30  6:20                             ` Jason Merrill
2002-04-30  9:40                               ` Mark Mitchell
2002-04-23 12:22         ` GCC 3.1 Prerelease Jason Merrill
2002-04-23  9:08 ` Per Bothner
2002-04-23  9:30   ` Mark Mitchell
2002-04-23 10:12     ` Per Bothner
2002-04-23 13:25       ` Mark Mitchell
2002-04-23 14:52       ` Tom Tromey
2002-04-23 15:02         ` Per Bothner
2002-04-23 16:11           ` Tom Tromey
2002-04-24 10:14             ` Alexandre Petit-Bianco
2002-04-24 10:30               ` Tom Tromey
2002-04-24 10:32                 ` Mark Mitchell
2002-04-23 13:19 ` Richard Henderson
2002-04-23 13:28   ` Mark Mitchell
2002-04-23 13:35     ` Richard Henderson
2002-04-23 13:50       ` Mark Mitchell
2002-04-23 13:52         ` Richard Henderson
2002-04-23 16:30         ` mips n64 eh failures Richard Henderson
2002-04-23 16:53           ` Mark Mitchell
2002-04-23 16:59             ` Richard Henderson
2002-04-23 18:00               ` Richard Henderson
2002-04-23 18:20                 ` Richard Henderson
2002-04-23 19:35                   ` Richard Henderson
2002-04-24  9:08                     ` Mark Mitchell

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=200204252121.58902@enzo.bigblue.local \
    --to=franz.sirl-kernel@lauterbach.com \
    --cc=amodra@bigpond.net.au \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=mark@codesourcery.com \
    --cc=rth@redhat.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).