public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12370] New: [3.4 regression] wrong code involving friends
@ 2003-09-22 21:28 reichelt at gcc dot gnu dot org
  2003-09-22 22:19 ` [Bug c++/12370] " bangerth at dealii dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2003-09-22 21:28 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12370

           Summary: [3.4 regression] wrong code involving friends
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P1
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,rth at redhat dot com
  GCC host triplet: i686-pc-linux-gnu

The following code snippet miscompiles with mainline on i686-pc-linux-gnu:

=====================================================================
template <typename T> struct A
{
    T x;
    A(T t) : x(t) {}
    friend A<int> foo (const A<unsigned>&);
};

A<int> foo (const A<unsigned>& a) { A<int> res(a.x); return res; }

int main()
{
    return foo(A<unsigned>(0)).x;
}
=====================================================================

It should return "0" but returns "16" instead.
If I delete the friend declaration, the code compiles fine.

This regression was introduced between 2003-08-29 22:00 and 23:30.

Richard, there were 5 commits from you in this timeframe

  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00940.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00942.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00943.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00945.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00947.html

and one from Mark (which is about labels and shouldn't be the problem here).
Could you please have a look?

Thanks,
Volker


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/12370] [3.4 regression] wrong code involving friends
  2003-09-22 21:28 [Bug c++/12370] New: [3.4 regression] wrong code involving friends reichelt at gcc dot gnu dot org
@ 2003-09-22 22:19 ` bangerth at dealii dot org
  2003-09-23  8:56 ` [Bug c++/12370] [3.4 regression] wrong code when adding friend pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2003-09-22 22:19 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12370


bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2003-09-22 21:15:15
               date|                            |
   Target Milestone|---                         |3.4


------- Additional Comments From bangerth at dealii dot org  2003-09-22 21:15 -------
Confirmed. There's something odd going on here. It's not
a problem with signed vs unsigned, btw, since we have the
same behavior with this testcase:
------------------------------
struct B {
    int x;
};

template <int=0> struct A
{
    int x;
    friend B foo (const A<>&);
};

B foo (const A<>& a) { B res = {a.x};  return res; }

int main()
{
  return foo((A<>){0}).x;
}
---------------------------------
This returns 120 on my system (and the original testcase returned 84 here,
so this seems to be mostly random). I don't know what the friend declaration
can have possibly to do with the result, but removing it really makes
the bug go away. Likewise for making A a non-template...

W.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/12370] [3.4 regression] wrong code when adding friend
  2003-09-22 21:28 [Bug c++/12370] New: [3.4 regression] wrong code involving friends reichelt at gcc dot gnu dot org
  2003-09-22 22:19 ` [Bug c++/12370] " bangerth at dealii dot org
@ 2003-09-23  8:56 ` pinskia at gcc dot gnu dot org
  2003-09-27  1:01 ` rth at redhat dot com
  2003-10-13 23:06 ` cvs-commit at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-09-23  8:56 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12370


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[3.4 regression] wrong code |[3.4 regression] wrong code
                   |involving friends           |when adding friend


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-09-23 02:12 -------
>From looking into the RTL:
(insn 16 15 17 (set (mem/f:SI (reg/f:SI 56 virtual-outgoing-args) [0 S4 A32])
        (addressof:SI (reg/v:SI 61) 60 0x400e28dc)) -1 (nil)
    (nil))

61 is not used any more after that function or before it either.

Getting rid of the friend:
(insn 16 15 17 (set (mem/f:SI (reg/f:SI 56 virtual-outgoing-args) [0 S4 A32])
        (reg/v/f:SI 58 [ <anonymous> ])) -1 (nil)
    (nil))
Which is right.  Looks some thing is going wrong because of the friend, maybe another GC 
problem again?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/12370] [3.4 regression] wrong code when adding friend
  2003-09-22 21:28 [Bug c++/12370] New: [3.4 regression] wrong code involving friends reichelt at gcc dot gnu dot org
  2003-09-22 22:19 ` [Bug c++/12370] " bangerth at dealii dot org
  2003-09-23  8:56 ` [Bug c++/12370] [3.4 regression] wrong code when adding friend pinskia at gcc dot gnu dot org
@ 2003-09-27  1:01 ` rth at redhat dot com
  2003-10-13 23:06 ` cvs-commit at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rth at redhat dot com @ 2003-09-27  1:01 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12370



------- Additional Comments From rth at redhat dot com  2003-09-26 22:56 -------
Subject: Re:  [3.4 regression] wrong code when adding friend

On Tue, Sep 23, 2003 at 02:12:25AM -0000, pinskia at gcc dot gnu dot org wrote:
> Looks some thing is going wrong because of the friend, maybe another GC 
> problem again?

Not a gc problem, exactly.  It is fallout from one of my patches however.
We were losing track of the fact that nrvo was to be applied, by losing
track of the cached information in cfun.

The following cures the given test case; general testing to follow.


r~


	* decl.c (duplicate_decls): Copy DECL_SAVED_INSNS too.

Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1133
diff -c -p -d -u -r1.1133 decl.c
--- decl.c	26 Sep 2003 15:21:30 -0000	1.1133
+++ decl.c	26 Sep 2003 22:52:54 -0000
@@ -3206,7 +3206,10 @@ duplicate_decls (tree newdecl, tree oldd
 	  if (CAN_HAVE_FULL_LANG_DECL_P (newdecl)
 	      && DECL_LANG_SPECIFIC (newdecl)
 	      && DECL_LANG_SPECIFIC (olddecl))
-	    DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
+	    {
+	      DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
+	      DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
+	    }
 	}
 
       /* Merge the section attribute.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/12370] [3.4 regression] wrong code when adding friend
  2003-09-22 21:28 [Bug c++/12370] New: [3.4 regression] wrong code involving friends reichelt at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2003-09-27  1:01 ` rth at redhat dot com
@ 2003-10-13 23:06 ` cvs-commit at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-10-13 23:06 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12370



------- Additional Comments From cvs-commit at gcc dot gnu dot org  2003-10-13 23:06 -------
Subject: Bug 12370

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	reichelt@gcc.gnu.org	2003-10-13 23:06:38

Modified files:
	gcc/cp         : ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/other: friend2.C 

Log message:
	PR c++/12370
	* g++.dg/other/friend2.C: New test.
	* ChangeLog: Add PR number to patch for PR c++/12370.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3725&r2=1.3726
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3118&r2=1.3119
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/friend2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-10-13 23:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-22 21:28 [Bug c++/12370] New: [3.4 regression] wrong code involving friends reichelt at gcc dot gnu dot org
2003-09-22 22:19 ` [Bug c++/12370] " bangerth at dealii dot org
2003-09-23  8:56 ` [Bug c++/12370] [3.4 regression] wrong code when adding friend pinskia at gcc dot gnu dot org
2003-09-27  1:01 ` rth at redhat dot com
2003-10-13 23:06 ` cvs-commit at gcc dot gnu dot 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).