public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: degnbol@danbbs.dk
To: gcc-gnats@gcc.gnu.org
Subject: c/5929: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs
Date: Tue, 12 Mar 2002 15:06:00 -0000	[thread overview]
Message-ID: <20020312225942.21817.qmail@sources.redhat.com> (raw)


>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==


             reply	other threads:[~2002-03-12 23:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-12 15:06 degnbol [this message]
2002-03-12 15:36 neil

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=20020312225942.21817.qmail@sources.redhat.com \
    --to=degnbol@danbbs.dk \
    --cc=gcc-gnats@gcc.gnu.org \
    /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).