public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32992] New: Incorrect code generated for anonymous union
@ 2007-08-05 1:27 scovich at gmail dot com
2007-08-06 5:08 ` [Bug c++/32992] Incorrect code generated for anonymous union and return pinskia at gcc dot gnu dot org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: scovich at gmail dot com @ 2007-08-05 1:27 UTC (permalink / raw)
To: gcc-bugs
Compiling and running the code below produces the following output:
$ g++ -Wall -DT=long -g3 union-bug.C && ./a.out
&array= 0x7fff11782ef0
&a= 0x7fff11782f20
B={1,3,5}
A={-1719443200,4196007,-1719451616}
A and B should contain the same values, but A contains garbage instead because
the two members of the union do not reside at the same address.
Changing T 'int' produces the expected output:
$ g++ -Wall -DT=int -g3 union-bug.C && ./a.out
&array= 0x7fff1fbf6370
&a= 0x7fff1fbf6370
B={1,3,5}
A={1,3,5}
'char' and 'short' also work correctly; '__m128i' (SSE register) breaks.
This bug affects both gcc-4.1.2 and gcc-4.3
// union-bug.C
#include <cstdio>
struct A {
T _a;
T _b;
T _c;
};
struct B {
T _array[3];
operator A() {
union {
T array[3];
A a;
};
printf("&array= %p\n&a= %p\n", &array, &a);
for(int i=0; i < 3; i++)
array[i] = _array[i];
return a;
}
};
int main() {
B b = {{1,3,5}};
A a = b;
printf("B={%d,%d,%d}\n", (int) b._array[0], (int) b._array[1], (int)
b._array[2]);
printf("A={%d,%d,%d}\n", (int) a._a, (int) a._b, (int) a._c);
return 0;
}
--
Summary: Incorrect code generated for anonymous union
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: scovich at gmail dot com
GCC target triplet: x86_64-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
@ 2007-08-06 5:08 ` pinskia at gcc dot gnu dot org
2007-08-10 0:51 ` [Bug c++/32992] [4.1/4.2/4.3 Regression] " pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-06 5:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-08-06 05:07 -------
This is a front-end bug.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
GCC target triplet|x86_64-linux-gnu |
Keywords| |wrong-code
Summary|Incorrect code generated for|Incorrect code generated for
|anonymous union |anonymous union and return
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
2007-08-06 5:08 ` [Bug c++/32992] Incorrect code generated for anonymous union and return pinskia at gcc dot gnu dot org
@ 2007-08-10 0:51 ` pinskia at gcc dot gnu dot org
2007-08-13 16:03 ` jakub at gcc dot gnu dot org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-10 0:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-08-10 00:51 -------
This is most likely caused by:
2005-09-09 Richard Henderson <rth@redhat.com>
PR debug/20998
* cp-tree.def (ALIAS_DECL): Remove.
* cp-lang.c (cp_init_ts): Remove support for it.
* error.c (dump_decl): Likewise.
* name-lookup.c (pushdecl): Likewise.
* semantics.c (finish_id_expression): Likewise.
* decl2.c (build_anon_union_vars): Use a VAR_DECL with
DECL_VALUE_EXPR instead.
Confirmed.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Known to fail| |4.1.0 4.2.0 4.3.0
Known to work| |4.0.0 3.4.0 3.3.3
Last reconfirmed|0000-00-00 00:00:00 |2007-08-10 00:51:02
date| |
Summary|Incorrect code generated for|[4.1/4.2/4.3 Regression]
|anonymous union and return |Incorrect code generated for
| |anonymous union and return
Target Milestone|--- |4.1.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
2007-08-06 5:08 ` [Bug c++/32992] Incorrect code generated for anonymous union and return pinskia at gcc dot gnu dot org
2007-08-10 0:51 ` [Bug c++/32992] [4.1/4.2/4.3 Regression] " pinskia at gcc dot gnu dot org
@ 2007-08-13 16:03 ` jakub at gcc dot gnu dot org
2007-08-15 12:09 ` jakub at gcc dot gnu dot org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-08-13 16:03 UTC (permalink / raw)
To: gcc-bugs
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2007-08-10 00:51:02 |2007-08-13 16:03:38
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
` (2 preceding siblings ...)
2007-08-13 16:03 ` jakub at gcc dot gnu dot org
@ 2007-08-15 12:09 ` jakub at gcc dot gnu dot org
2007-08-20 8:11 ` jakub at gcc dot gnu dot org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-08-15 12:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jakub at gcc dot gnu dot org 2007-08-15 12:08 -------
Subject: Bug 32992
Author: jakub
Date: Wed Aug 15 12:08:42 2007
New Revision: 127510
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127510
Log:
PR c++/32992
* typeck.c (check_return_expr): Don't NRV optimize vars in
anonymous unions.
* decl.c (finish_function): Comment fix.
* g++.dg/opt/nrv14.C: New test.
Added:
trunk/gcc/testsuite/g++.dg/opt/nrv14.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/decl.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
` (3 preceding siblings ...)
2007-08-15 12:09 ` jakub at gcc dot gnu dot org
@ 2007-08-20 8:11 ` jakub at gcc dot gnu dot org
2007-08-20 8:17 ` jakub at gcc dot gnu dot org
2007-08-20 8:19 ` jakub at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-08-20 8:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from jakub at gcc dot gnu dot org 2007-08-20 08:11 -------
Subject: Bug 32992
Author: jakub
Date: Mon Aug 20 08:10:54 2007
New Revision: 127640
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127640
Log:
PR c++/32992
* typeck.c (check_return_expr): Don't NRV optimize vars in
anonymous unions.
* decl.c (finish_function): Comment fix.
* g++.dg/opt/nrv14.C: New test.
Added:
branches/gcc-4_2-branch/gcc/testsuite/g++.dg/opt/nrv14.C
Modified:
branches/gcc-4_2-branch/gcc/cp/ChangeLog
branches/gcc-4_2-branch/gcc/cp/decl.c
branches/gcc-4_2-branch/gcc/cp/typeck.c
branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
` (4 preceding siblings ...)
2007-08-20 8:11 ` jakub at gcc dot gnu dot org
@ 2007-08-20 8:17 ` jakub at gcc dot gnu dot org
2007-08-20 8:19 ` jakub at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-08-20 8:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from jakub at gcc dot gnu dot org 2007-08-20 08:17 -------
Subject: Bug 32992
Author: jakub
Date: Mon Aug 20 08:17:21 2007
New Revision: 127641
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127641
Log:
PR c++/32992
* typeck.c (check_return_expr): Don't NRV optimize vars in
anonymous unions.
* decl.c (finish_function): Comment fix.
* g++.dg/opt/nrv14.C: New test.
Added:
branches/gcc-4_1-branch/gcc/testsuite/g++.dg/opt/nrv14.C
Modified:
branches/gcc-4_1-branch/gcc/cp/ChangeLog
branches/gcc-4_1-branch/gcc/cp/decl.c
branches/gcc-4_1-branch/gcc/cp/typeck.c
branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/32992] [4.1/4.2/4.3 Regression] Incorrect code generated for anonymous union and return
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
` (5 preceding siblings ...)
2007-08-20 8:17 ` jakub at gcc dot gnu dot org
@ 2007-08-20 8:19 ` jakub at gcc dot gnu dot org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu dot org @ 2007-08-20 8:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from jakub at gcc dot gnu dot org 2007-08-20 08:19 -------
Fixed.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32992
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-08-20 8:19 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-05 1:27 [Bug c++/32992] New: Incorrect code generated for anonymous union scovich at gmail dot com
2007-08-06 5:08 ` [Bug c++/32992] Incorrect code generated for anonymous union and return pinskia at gcc dot gnu dot org
2007-08-10 0:51 ` [Bug c++/32992] [4.1/4.2/4.3 Regression] " pinskia at gcc dot gnu dot org
2007-08-13 16:03 ` jakub at gcc dot gnu dot org
2007-08-15 12:09 ` jakub at gcc dot gnu dot org
2007-08-20 8:11 ` jakub at gcc dot gnu dot org
2007-08-20 8:17 ` jakub at gcc dot gnu dot org
2007-08-20 8:19 ` jakub 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).