Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

warning #1476: field uses tail padding

fons-rademakers
Beginner
586 Views
Hi,

with the latest compiler patch l_cc_pc_8.0.066, I get now several tail padding warnings (#1476). Does this warning mean a changed padding behaviour in the compiler or is it just a new warning for previously existing behavior? Does gcc 3.2.3 behave the same? Should I fix the code or disable the warning?

Any help appreciated.

Cheers, Fons.
0 Kudos
5 Replies
Maximillia_D_Intel
586 Views

Dear Fons,

Without seeing your testcase I can't know for sure. This looks like recently implemented diagnostics pinpointing an ABI noncompliance issue that gcc accepts without a warning. We recently turned on this warning to assist developers. The issue has to do with reuse of bits at the end of a class. You can 'fix' your code by addingmore padding so that the class size modulo 8 bits is 0.Let me know if you have more questions.

Best regards,

Max

0 Kudos
fons-rademakers
Beginner
586 Views
Hi Max,

so to be ABI compliant the derived class should not put any data members in the tail padding of its base class? Could this not be done automatically by the compiler (possibly via a compiler option)? Since now icc is doing the same as g++ does this mean that g++ 3.2.3 is also not ABI compliant?

Cheers, Fons.
0 Kudos
Maximillia_D_Intel
586 Views

Dear Fons,

I asked one of our C++ FE developers to respond and here are her comments:

If you look at the Gnu 3.2 docs you will see this description under the -Wabi switch:

The known incompatibilites at this point include:
Incorrect handling of tail-padding for bit-fields. G++ may attempt to pack data into the same byte as a base class. For example:
struct A { virtual void f(); int f1 : 1; };
struct B : public A { int f2 : 1; };

In this case, G++ will place B::f2 into the same byte asA::f1; other compilers will not. You can avoid this problem by explicitly padding A so that its size is a multiple of the byte size on your platform; that will cause G++ and other compilers to layout B identically.

The Intel compiler did its best to emulate the g++ bugs/incompatibilities but it could not do it perfectly so a couple of warnings were recently added to the compiler to let users know when their code was potentially incompatible. g++ 3.4 has fixed these problems and the 8.1 version of icpc will emulate these fixes under the -gcc-version=340 switch.

Hope this helps,

Max

0 Kudos
fons-rademakers
Beginner
586 Views
Hi Max,

using the following little test program I get the 1476 warning on IA-32 and IA-64:

#include #stdio.h# // avoid html tags

class A { public: virtual void f() {}; char a; };
class B : public A { short b; };

int main()
{
printf("sizeof A = %ld ", sizeof(A));
printf("sizeof B = %ld ", sizeof(B));

return 0;
}

as you can see there are no bitfields involved. Also both gcc 3.2 and gcc 3.4 report a size for B of 8 (16 on IA-64), both with and without the -Wabi flag. Also icc returns 8 and 16 but generates the warning, while compatible with g++ in -Wabi mode. Maybe the warning should only be issued in the bit field tail padding case?

Cheers, Fons.
0 Kudos
Judith_W_Intel
Employee
586 Views
/*
Thanks for the example.
There are a few different warnings that we added to the compiler.
You can seetwo of themwith the example below.
nht6011-531> icc -c t2.cpp
t2.cpp(22): warning #1476: field uses tail padding of a base class
char m3; // Offset 5 in S3 (reuses tail padding of direct base S1).
^
t2.cpp(21): warning #1505: size of class is affected by tail padding
struct S3: S1, virtual S2 {
^
The warning you are seeing, #1476, just warns whenever you are using
the tail padding of a base class regardless of whether it may cause
trouble or not.The other warning, #1505, indicates
that not only are you using the tail padding of a base class,
but you are also hitting a potential ABI binary incompatibility, since
The default (IA-64-based) GNU C++ ABI deviates from the IA-64 ABI
specifications by allowing the tail padding for indirect bases to be
reused.
You can see the difference in the example below. Note the size
difference between the non-conformant and conformant ABI.
nht6011-597> g++ -fabi-version=0 t2.cpp && a.out
size of S3 8
nht6011-598> g++ -fabi-version=1 t2.cpp && a.out
size of S3 12
*/

extern "C" int printf(const char*,...);
struct S1 {
char m1; // Offset 4 in S1 (virtual function table pointer at offset 0)
S1() {}
virtual ~S1() {}
};
struct S2 {
short m2;
S2() {}
};
struct S3: S1, virtual S2 {
char m3; // Offset 5 in S3 (reuses tail padding of direct base S1).
S3() {}
};
int main() {
printf("size of S3 %d ",sizeof(S3));
return 0;
}
Judy
0 Kudos
Reply