This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Questions about a constant array reference in the C++ front end
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc at gcc dot gnu dot org
- Cc: nathan at codesourcery dot com
- Date: Sun, 08 May 2005 00:11:34 -0400 (EDT)
- Subject: Questions about a constant array reference in the C++ front end
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.
Another question. How is a RANGE_EXPR used in a C++'s array
constructor? The CONSTRUCTOR section of tree.def says
The TREE_PURPOSE of each node is the corresponding index.
If the TREE_PURPOSE is a RANGE_EXPR, it is a short-hand for many nodes,
one for each index in the range. (If the corresponding TREE_VALUE
has side-effects, they are evaluated once for each element. Wrap the
value in a SAVE_EXPR if you want to evaluate side effects only once.)
I created an array with more than one thousand elements. I still did
not see a RANGE_EXPR in the array's CONSTRUCTOR. How do I get a
RANGE_EXPR in a CONSTRUCTOR?
Kazu Hirata