c/5929: gcc 2.95-3.04 miscompiles anonymous unions inside anonymous structs
degnbol@danbbs.dk
degnbol@danbbs.dk
Tue Mar 12 15:06:00 GMT 2002
>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==
More information about the Gcc-bugs
mailing list