This is the mail archive of the
mailing list for the GCC project.
Re: [tree-ssa] fix C enum representation
- From: law at redhat dot com
- To: Richard Henderson <rth at twiddle dot net>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 05 Jan 2004 16:07:12 -0700
- Subject: Re: [tree-ssa] fix C enum representation
- Reply-to: law at redhat dot com
In message <20040105223751.GA7814@twiddle.net>, Richard Henderson writes:
>Fixes enum types to have the proper TYPE_MIN/MAX_VALUE for the
>compatible integer type. This lets us remove some special case
>hacks for switch statements.
>I thought about putting this on mainline as well, but testing
>revealed that it broke -Wswitch. Fixing that would require
>backporting another much larger patch from tree-ssa branch.
>At which point I gave it up as a bad idea.
> * c-tree.h (struct lang_type): Add enum_min, enum_max.
> * c-decl.c (finish_enum): Set them. Set TYPE_MIN/MAX_VALUE to
> the limits of the compatible type, not to the enumerators.
> (check_bitfield_type_and_width): Use them.
> (finish_struct): Clear allocated struct lang_type.
> * gimplify.c (gimplify_switch_expr): Remove special handling of
> outer cast in a switch.
> * tree-ssa-dom.c (record_equivalences_from_incoming_edge): Likewise.
Note you can probably clean up a long standing minor turd in shorten_compare
/* In C, if TYPE is an enumeration, then we need to get its
min/max values from it's underlying integral type, not the
enumerated type itself. In C++, TYPE_MAX_VALUE and
TYPE_MIN_VALUE have already been set correctly on the
enumeration type. */
if (!c_dialect_cxx() && TREE_CODE (type) == ENUMERAL_TYPE)
type = c_common_type_for_size (TYPE_PRECISION (type), unsignedp0);