Questions about a constant array reference in the C++ front end
Mark Mitchell
mark@codesourcery.com
Tue May 10 00:41:00 GMT 2005
Kazu Hirata wrote:
> Hi,
>
> I have two questions about the C++ front end.
>
> Consider a C++ program
>
> static const int array[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2 };
>
> int
> foo (int a)
> {
> return array[7];
> }
>
> I am trying to fold array[7] into 2. It turns out that if T is an
> ARRAY_REF,
>
> TREE_READONLY (TREE_OPERAND (T, 0))
>
> is 0. Why? This would be 1 if the program is fed into the C front
> end, which is needed to safely fold a constant array reference.
That's a bug, or, rather, a place where the C++ front-end is failing to
give full information to the optimizer. It should be TREE_READONLY.
There are some tricky bits, in that if we're doing a dynamic
initialization, we presently cannot mark it TREE_READONLY, but this is a
static initialization, so it should be fine. Isn't TREE_OPERAND (T, 0)
the VAR_DECL for array itself? If so, waht's probably going wrong is
that it's not being marked TREE_READONLY because we're afraid of the
dynamic initialization case. We're missing a call to
c_apply_quals_to_decl (sp?) somewhere.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
More information about the Gcc
mailing list