https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66196
Bug ID: 66196
Summary: Wrong type incompatibility warning for -flto and C
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: hubicka at gcc dot gnu.org
Target Milestone: ---
jan@linux-qos1:~> cat t.c
union a {
int a;
long b;
};
union a a;
jan@linux-qos1:~> cat t2.c
union a {
long b;
int a;
};
union a a;
jan@linux-qos1:~> gcc -O2 -flto t.c t2.c
t2.c:5:9: warning: type of ‘a’ does not match original declaration [enabled by
default]
union a a;
^
t.c:5:9: note: previously declared here
union a a;
^
I believe the warning is wrong here by 6.2.7.1 of the standard:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
Moreover, two structure, union, or enumerated types declared in separate
translation units are compatible if their tags and members satisfy the
following requirements: If one is declared with a tag, the other shall be
declared with the same tag. If both are completed anywhere within their
respective translation units, then the following additional requirements apply:
there shall be a one-to-one correspondence between their members such that each
pair of corresponding members are declared with compatible types; if one member
of the pair is declared with an alignment specifier, the other is declared with
an equivalent alignment specifier; and if one member of the pair is declared
with a name, the other is declared with the same name. For two structures,
corresponding members shall be declared in the same order. For two
structures or unions, corresponding bit-fields shall have the same widths. For
two enumerations, corresponding members shall have the same values.
"For two structures, corresponding members shall be declared in the same
order." seems to rule out unions.
We do not match alignments/memory layout/bitfields in type canonical type code
that we probably should.
I suppose we can't match FIELD_DECL names in current implementation to allow
non-C/C++ matching.
The warning probably translates to a wrong code eventually.