This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA/dwarf-2] Avoid unnecessary subrange_type (3/3)
> 1) Why do the affected types look like subrange types to begin with? Why
> do they have a TREE_TYPE?
Unfortunately, this is a bit beyond my knowledge of GCC. It looked
deliberate, though, when I looked at what stabs look like for
base types (base types are defined as subrange types of themselves),
so I didn't push the issue further. I'll try to investigate a bit
further on my side, but sure would appreciate it if somebody else
on this list already knew the answer (I work mostly on the debugger,
I don't know GCC that well yet).
> 2) Why not just compare type_name == subtype_name?
> Identifiers are unique.
Nice! I didn't know that. I'll get rid of strcmp. The new code
looks like this (this is nicer):
if (TREE_CODE (type) == TREE_CODE (subtype)
&& int_size_in_bytes (type) == int_size_in_bytes (subtype)
&& TYPE_MIN_VALUE (type) != NULL
&& TYPE_MIN_VALUE (subtype) != NULL
&& tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
&& TYPE_MAX_VALUE (type) != NULL
&& TYPE_MAX_VALUE (subtype) != NULL
&& tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
{
/* The type and its subtype have the same representation. If in
addition the two types also have the same name, then the given
type is not a subrange type, but rather a plain base type. */
tree type_name = TYPE_NAME (type);
tree subtype_name = TYPE_NAME (subtype);
if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
type_name = DECL_NAME (type_name);
if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
subtype_name = DECL_NAME (subtype_name);
if (type_name == subtype_name)
return false;
}
Cheers,
--
Joel