This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Enum initialization modifies expression's type
- To: Alexandre Oliva <aoliva at cygnus dot com>
- Subject: Re: Enum initialization modifies expression's type
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Tue, 23 May 2000 23:27:27 -0600
- cc: gcc-patches at gcc dot gnu dot org
- Reply-To: law at cygnus dot com
In message <orhfboejl4.fsf@tamanduatei.dcc.unicamp.br>you write:
> --=-=-=
>
> The testcase in the attached patch failed because build_enumerator()
> modified the type of the initializer, that was a constant obtained
> from the size_table, and already referenced as TYPE_SIZE of the
> `void*' type. Then, when the size was given to size_binop(), it
> didn't have the same type as the other argument, so we crashed.
>
> This patch fixes this problem. Ok to install?
>
>
> --=-=-=
> Content-Type: text/x-patch
> Content-Disposition: inline; filename=enum-sizeof.patch
>
> Index: gcc/ChangeLog
> from Alexandre Oliva <aoliva@cygnus.com>
>
> * c-decl.c (build_enumerator): Don't modify the value's type,
> convert it.
I was going to recommend you install a similar patch for C++, but looking
at its build_enumerator function, I think it already handles this case
by making a copy of the node in question (if its necessary).
Can you try the code in the C++ front-end and see if it fixes the
problem? If so, I would prefer to use the same solution in the C
front-end as we're using in the C++ front-end.
I'm assuming the problem is clobbering the TREE_TYPE of VALUE, right?
The C++ code in question which I think handles this issue:
/* We always have to copy here; not all INTEGER_CSTs are unshared.
Even in other cases, we will later (in finish_enum) be setting
the type of VALUE. But, we don't need to make a copy if this
VALUE is one of the enumeration constants for this same
enumeration type. */
for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
if (TREE_VALUE (values) == value)
break;
/* If we didn't break out of the loop, then we do need a copy. */
if (!values && value)
value = copy_node (value);
> * gcc.c-torture/compile/20000523-1.c: New test.
This is fine. Please install the new test.
jeff