> >> PR middle-end/66325
> >> * c-decl.c (start_enum): Set TYPE_PACKED consistently among type
> >> variants.
> >> Index: c-decl.c
> >> ===================================================================
> >> --- c-decl.c (revision 224250)
> >> +++ c-decl.c (working copy)
> >> @@ -7946,7 +7946,8 @@
> >> the_enum->enum_overflow = 0;
> >>
> >> if (flag_short_enums)
> >> - TYPE_PACKED (enumtype) = 1;
> >> + for (tree v = TYPE_MAIN_VARIANT (enumtype); v ;v = TYPE_NEXT_VARIANT
> >> (v))
>
> Though I wonder why flag_short_enums was not true when building the
> (main-)variant?
What I believe happens is that there is forward declaration of enum that leads
to biuld incomplete enum type that has no packed flag set. Then we produce
a type variant and after that we complete the main variant, but do not update
the other variant.
Actually looking into where the variant is updated, it happens in finish_enum
that copies many flags, perhaps it would make more sense to copy TYPE_PACKED
there?
> Looks like -fshort-enums is also 'Optimization', so the above is bogus for
>
> enum foo {x = 1 };
>
> void __attribute__((optimize(short-enums))) foo()
> {
> const enum foo x = 1;
> }
>
> no? The main variant is correctly _not_ packed but now you make it
> packed as you reach foo ()?
Perhaps it is defined as Optimization but it does not bind to uses of types:
enum foo {a,b,c};
__attribute__((optimize("short-enums")))
main()
{
const enum foo x;
enum bar {a,b,c};
printf ("%i %i\n",sizeof (x), sizeof(enum bar));
}
prints
4 1
it depends when the main variant is finished. I wonder if there is any
practical value on support Optimization attribute for this kind of ABI breaking
options. It may be easier to simply drop the Optimization flag completely from
-fshort-enums and friends.
-fshort-double ICEs at initialization time at least since 4.8.x
$ gcc t.c -fshort-double
<built-in>: internal compiler error: in layout_type, at stor-layout.c:2220
0xafe41b layout_type(tree_node*)
../../gcc/stor-layout.c:2219
so I suggest dropping that flag completely.
Honza
>
> Richard.
>
> > Please fix the formatting here: no space before ;.
> >
> > Ok with that change.
> >
> > Marek