[PR c++/87137] GCC-8 Fix

Liu Hao lh_mouse@126.com
Thu Aug 30 03:08:00 GMT 2018


在 2018-08-30 01:36, Nathan Sidwell 写道:
> But, it would be bad to make that particular ABI fix in a point release, 
> so this patch just reverts the regression I caused.  Sadly, because it 
> requires understanding TEMPLATE_DECL, we can't simply update 
> place_field.  Instead I temporarily stitch out undesired DECLs around 
> the call to place_field.  This seems the least intrusive, and happens 
> only when ms_bitfield_layout_p is in effect.
> 
>

It is strictly an ABI break but I doubt whether code in real world that 
got broken by this bug ever exists. Usually when people expect 
consecutive bitfields to be packed into a single word they wouldn't put 
irrelevant declarations between them.

An important reason why such code could be rare is that the following 
code compiles differently as C and C++:

```
E:\Desktop>cat test.cc
#include <stdio.h>

struct foo
   {
     unsigned a : 21;
     union x1 { char x; };
     unsigned b : 11;
     union x1 u;
   };

struct bar
   {
     union x2 { char x; };
     unsigned a : 21;
     unsigned b : 11;
     union x2 u;
   };

int main(void)
   {
     printf("%d\n", (int)sizeof(struct foo));
     printf("%d\n", (int)sizeof(struct bar));
   }
```

When compiled as C the output is:
```
E:\Desktop>cl /nologo /Tctest.cc /Fe:a.exe && a.exe
test.cc
16
12
```

while as C++ the output is:
```
E:\Desktop>cl /nologo /Tptest.cc /Fe:a.exe && a.exe
test.cc
8
8
```

Basing on the fact that such code is rare I think it should be safe to 
trade tolerance (or 'compatibility for this bug') for the correct behavior.


-- 
Best regards,
LH_Mouse



More information about the Gcc-patches mailing list