public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/5929: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs
@ 2002-03-12 15:06 degnbol
  0 siblings, 0 replies; 2+ messages in thread
From: degnbol @ 2002-03-12 15:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5929
>Category:       c
>Synopsis:       gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 12 15:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Gunnar Degnbol
>Release:        Cygwin gcc 2.95-3, RH gcc 2.96.98, gcc 3.0.3, gcc  3.0.4
>Organization:
>Environment:
Cygwin/Windows NT4 (gcc 2.95-3)
RH Linux 7.2 (gcc 3.0.3, gcc 3.0.4)
>Description:
The members of an anonymous union inside an anonymous struct are aligned with the first member of the anonymous struct. This affects Windows VARIANTs used in C programs. The bug does 
not affect C++ programs. 
>How-To-Repeat:
$ gcc anonbug.c -o anonbug
$ ./anonbug
offset v1 = 0
offset v2 = 4
offset v3 = 8
offset u1 = 4
offset u2 = 4
$ g++ anonbug.c -o anonbug # or MS/Borland/intel C/C++
$ ./anonbug 
offset v1 = 0
offset v2 = 4
offset v3 = 8
offset u1 = 12
offset u2 = 12
>Fix:
Not a fix but a workaround that works for me.

A Windows VARIANT (Cygwin/Mingw32 oaidl.h, WINE oleauto.h) has this structure: 

struct tagVARIANT {
    union {
        struct {
            VARTYPE vt;
            // reserved fields
            union {
                // any kind of variable
            };
        };
        DECIMAL decVal;
    };
} VARIANT;

Since nobody (?) actually uses decVal, a workaround for this specific instance is to #ifdef __cplusplus the outer anonymous union and struct.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="anonbug.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="anonbug.c"

I2lmZGVmIF9fY3BsdXNwbHVzDQpleHRlcm4gIkMiIHsNCiNlbmRpZg0KDQppbnQgcHJpbnRmKGNo
YXIgKiwgLi4uKTsNCg0Kc3RydWN0IF9uZXN0ZWRhbm9uIHsNCiAgICBpbnQgdjE7DQogICAgc3Ry
dWN0IHsNCiAgICAgICAgaW50IHYyOw0KICAgICAgICBpbnQgdjM7DQogICAgICAgIHVuaW9uIHsN
CiAgICAgICAgICAgIGludCB1MTsNCiAgICAgICAgICAgIGludCB1MjsNCiAgICAgICAgfTsNCiAg
ICB9Ow0KfTsNCg0KaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKiphcmd2KQ0Kew0KICAgIHN0cnVj
dCBfbmVzdGVkYW5vbiBzOw0KICAgIHByaW50Zigib2Zmc2V0IHYxID0gJWRcbiIsIChpbnQpJnMu
djEgLSAoaW50KSZzKTsNCiAgICBwcmludGYoIm9mZnNldCB2MiA9ICVkXG4iLCAoaW50KSZzLnYy
IC0gKGludCkmcyk7DQogICAgcHJpbnRmKCJvZmZzZXQgdjMgPSAlZFxuIiwgKGludCkmcy52MyAt
IChpbnQpJnMpOw0KICAgIHByaW50Zigib2Zmc2V0IHUxID0gJWRcbiIsIChpbnQpJnMudTEgLSAo
aW50KSZzKTsNCiAgICBwcmludGYoIm9mZnNldCB1MiA9ICVkXG4iLCAoaW50KSZzLnUyIC0gKGlu
dCkmcyk7DQp9DQoNCiNpZmRlZiBfX2NwbHVzcGx1cw0KfQ0KI2VuZGlmDQoNCg==


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

* Re: c/5929: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs
@ 2002-03-12 15:36 neil
  0 siblings, 0 replies; 2+ messages in thread
From: neil @ 2002-03-12 15:36 UTC (permalink / raw)
  To: degnbol, gcc-bugs, gcc-prs, neil, nobody

Synopsis: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs

Responsible-Changed-From-To: unassigned->neil
Responsible-Changed-By: neil
Responsible-Changed-When: Tue Mar 12 15:36:37 2002
Responsible-Changed-Why:
    Mine.
State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Tue Mar 12 15:36:37 2002
State-Changed-Why:
    I fixed this for 3.1, which will give:
    
    neil@cat:/tmp$ ./a.out 
    offset v1 = 0
    offset v2 = 4
    offset v3 = 8
    offset u1 = 12
    offset u2 = 12
    neil@cat:/tmp$

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5929


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

end of thread, other threads:[~2002-03-12 23:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-12 15:06 c/5929: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs degnbol
2002-03-12 15:36 neil

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).