public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15580] New: wrong code generation in c++ assignment operator
@ 2004-05-22 22:37 gcc-bugzilla at gcc dot gnu dot org
  2004-05-22 22:38 ` [Bug c++/15580] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-05-22 22:37 UTC (permalink / raw)
  To: gcc-bugs

`this' calculated incorrectly for the assignment operator of the virtual base.

Environment:
gcc 3.3.x

How-To-Repeat:

[8<---test.cc---]
struct A { int a; };
struct B : virtual A { };
struct C : virtual A { };
struct D : B, C { };

int
main()
{
    D d;
    d = d;
    d.a = 5;
}
[--->8]

g++ test.cc
./a.out

no optimization should be used, otherwise `d.a' reference will be cached
from assignment operation. in any doubt this is an optimizer error here
is a modified version of the same test.cc which will crash in any of -Oxx
switches:
[...]

void test(D d);

int
main()
{
    D d;
    d = d;
    test(d);
}

void test(D d)
{
}

>Workaround:
downgrade to 3.2.x
------- Additional Comments From unicorn at re dot com dot ua  2004-05-21 23:45 -------
Fix:
downgrade to 3.2.x
- or -
here is a patch for gcc version 3.3.3 [FreeBSD] 20031106:

Index: method.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/cp/method.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 method.c
--- method.c    22 Aug 2003 02:56:03 -0000      1.1.1.10
+++ method.c    21 May 2004 04:52:33 -0000
@@ -665,15 +665,17 @@
       for (i = 0; i < CLASSTYPE_N_BASECLASSES (current_class_type); ++i)
        {
          tree binfo;
+         tree dst;
          tree converted_parm;
 
          binfo = BINFO_BASETYPE (TYPE_BINFO (current_class_type), i);
          /* We must convert PARM directly to the base class
             explicitly since the base class may be ambiguous.  */
          converted_parm = build_base_path (PLUS_EXPR, parm, binfo, 1);
+         dst = build_base_path (PLUS_EXPR, current_class_ref, binfo, 1);
          /* Call the base class assignment operator.  */
          finish_expr_stmt 
-           (build_special_member_call (current_class_ref, 
+           (build_special_member_call (dst, 
                                        ansi_assopname (NOP_EXPR),
                                        build_tree_list (NULL_TREE, 
                                                         converted_parm),

-- 
           Summary: wrong code generation in c++ assignment operator
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: unicorn at re dot com dot ua
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
@ 2004-05-22 22:38 ` pinskia at gcc dot gnu dot org
  2004-05-22 22:57 ` unicorn at freeshell dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-22 22:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-21 23:58 -------
I cannot reproduce this at all on 3.3.3, 3.4.0 or 3.2.3.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
  2004-05-22 22:38 ` [Bug c++/15580] " pinskia at gcc dot gnu dot org
@ 2004-05-22 22:57 ` unicorn at freeshell dot org
  2004-05-22 23:08 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: unicorn at freeshell dot org @ 2004-05-22 22:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From unicorn at freeshell dot org  2004-05-22 00:38 -------
(In reply to comment #2)
> I cannot reproduce this at all on 3.3.3, 3.4.0 or 3.2.3.

3.2.x hasn't this bug. 
(proposed patch was created after comparition of do_build_assign_ref 
routines of 3.2.3 and 3.3.3)

I did't test this on 3.4, but I'm completely sure 3.3.3 has this bug.
It may not show because of optimization or someth else.

try this:
#include <iostream>

struct A { 
    const A &operator = (const A &r) {
        std::cout << this << std::endl;
    }
};
struct B : virtual A { };
struct C : virtual A { };
struct D : B, C { };

int
main()
{
     D d0, d1;
     d0 = d1;
}

On 3.2 this will produce two equal address (as it has to be for virtual
inheritance), but 3.3 will show a different one.

-- 


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
  2004-05-22 22:38 ` [Bug c++/15580] " pinskia at gcc dot gnu dot org
  2004-05-22 22:57 ` unicorn at freeshell dot org
@ 2004-05-22 23:08 ` pinskia at gcc dot gnu dot org
  2004-05-22 23:18 ` unicorn at freeshell dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-22 23:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-22 00:51 -------
I cannot produce it at all:
tin:~/src/gnu/gcctest>g++ pr15580.cc <-- the mainline
tin:~/src/gnu/gcctest>./a.out
0xbffec920
0xbffec920
tin:~/src/gnu/gcctest>~/ia32_linux_gcc3_4/bin/g++ pr15580.cc <-- released 3.4.0
tin:~/src/gnu/gcctest>./a.out
0xbffec920
0xbffec920
tin:~/src/gnu/gcctest>~/ia32_linux_gcc3_3/bin/g++ pr15580.cc -static <-- release of 3.3.3
./a.
tin:~/src/gnu/gcctest>./a.out 
0xbffec920
0xbffec920
tin:~/src/gnu/gcctest>~/ia32_linux_gcc3_3_1/bin/g++ pr15580.cc -static <-- a prelease of 3.3.1
tin:~/src/gnu/gcctest>./a.out 
0xbffec920
0xbffec920

So either it was fixed in a later version of 3.3.3 which is most likely, since you are using an old prelease 
of 3.3.3, can you try the released version?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
           Keywords|                            |wrong-code


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-05-22 23:08 ` pinskia at gcc dot gnu dot org
@ 2004-05-22 23:18 ` unicorn at freeshell dot org
  2004-05-23  2:18 ` alfred dot minarik dot 1 at aon dot at
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: unicorn at freeshell dot org @ 2004-05-22 23:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From unicorn at freeshell dot org  2004-05-22 01:47 -------
(In reply to comment #4)
> So either it was fixed in a later version of 3.3.3 which is most likely, since
you are using an old prelease 
> of 3.3.3, can you try the released version?
Thank you.
I gues, this is a problem. freebsd still uses outdated gcc 3.3.3 as a system
compiller. I manage to submit a fbsd PR with a reference to this one.

-- 


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-05-22 23:18 ` unicorn at freeshell dot org
@ 2004-05-23  2:18 ` alfred dot minarik dot 1 at aon dot at
  2004-05-23  5:04 ` alfred dot minarik dot 1 at aon dot at
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: alfred dot minarik dot 1 at aon dot at @ 2004-05-23  2:18 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 587 bytes --]


------- Additional Comments From alfred dot minarik dot 1 at aon dot at  2004-05-22 05:03 -------
I´m able to reproduce this on

$ uname -a
CYGWIN_NT-5.0 w2k 1.5.9(0.112/4/2) 2004-03-18 23:05 i686 unknown unknown Cygwin

$ gcc --version
gcc (GCC) 3.3.1 (cygming special)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ pr15580.cc

$ ./a.exe
0x22f058
0x22f05c

Alfred

-- 


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2004-05-23  2:18 ` alfred dot minarik dot 1 at aon dot at
@ 2004-05-23  5:04 ` alfred dot minarik dot 1 at aon dot at
  2004-05-23  8:18 ` giovannibajo at libero dot it
  2004-05-23  9:57 ` unicorn at freeshell dot org
  7 siblings, 0 replies; 9+ messages in thread
From: alfred dot minarik dot 1 at aon dot at @ 2004-05-23  5:04 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]


------- Additional Comments From alfred dot minarik dot 1 at aon dot at  2004-05-22 05:20 -------
(In reply to comment #6)
> I´m able to reproduce this on
> $ uname -a
> CYGWIN_NT-5.0 w2k 1.5.9(0.112/4/2) 2004-03-18 23:05 i686 unknown unknown 
Cygwin
> $ gcc --version
> gcc (GCC) 3.3.1 (cygming special)
> Copyright (C) 2003 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> $ g++ pr15580.cc
> $ ./a.exe
> 0x22f058
> 0x22f05c
> Alfred

but seems fixed in 3.4.0

$ uname -a
CYGWIN_NT-5.0 w2k 1.5.9(0.112/4/2) 2004-03-18 23:05 i686 unknown unknown 

$ gcc --version
gcc (GCC) 3.4.0
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ pr15580.cc

$ ./a.exe
0x22f058
0x22f058

Alfred

-- 


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2004-05-23  5:04 ` alfred dot minarik dot 1 at aon dot at
@ 2004-05-23  8:18 ` giovannibajo at libero dot it
  2004-05-23  9:57 ` unicorn at freeshell dot org
  7 siblings, 0 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-05-23  8:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-05-22 09:10 -------
So closing as already fixed at least in 3.3.3.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |3.3.3


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


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

* [Bug c++/15580] wrong code generation in c++ assignment operator
  2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2004-05-23  8:18 ` giovannibajo at libero dot it
@ 2004-05-23  9:57 ` unicorn at freeshell dot org
  7 siblings, 0 replies; 9+ messages in thread
From: unicorn at freeshell dot org @ 2004-05-23  9:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From unicorn at freeshell dot org  2004-05-22 15:06 -------
It was fixed in gcc-3_3-branch at 2004-01-21 05:04:06.
here is original PR: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13009

-- 


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


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

end of thread, other threads:[~2004-05-22 15:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-22 22:37 [Bug c++/15580] New: wrong code generation in c++ assignment operator gcc-bugzilla at gcc dot gnu dot org
2004-05-22 22:38 ` [Bug c++/15580] " pinskia at gcc dot gnu dot org
2004-05-22 22:57 ` unicorn at freeshell dot org
2004-05-22 23:08 ` pinskia at gcc dot gnu dot org
2004-05-22 23:18 ` unicorn at freeshell dot org
2004-05-23  2:18 ` alfred dot minarik dot 1 at aon dot at
2004-05-23  5:04 ` alfred dot minarik dot 1 at aon dot at
2004-05-23  8:18 ` giovannibajo at libero dot it
2004-05-23  9:57 ` unicorn at freeshell 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).