This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
tcc_statement vs. tcc_expression in the C++ frontend
- From: Ian Lance Taylor <ian at airs dot com>
- To: gcc at gcc dot gnu dot org
- Date: 23 Apr 2005 12:06:55 -0400
- Subject: tcc_statement vs. tcc_expression in the C++ frontend
The description of tcc_statement in tree.h says "A statement
expression, which have side effects but usually no interesting value."
There are a number of entries in cp/cp-tree.def which are marked as
tcc_expression, although they seem to me to be better described as
tcc_statement, to wit:
IF_STMT
WHILE_STMT
DO_STMT
FOR_STMT
BREAK_STMT
CONTINUE_STMT
SWITCH_STMT
and perhaps also:
EH_SPEC_BLOCK
USING_STMT
CLEANUP_STMT
TRY_BLOCK
HANDLER
I tracked the first list above back to when they were introduced:
Tue Feb 20 18:21:51 1996 Jason Merrill <jason@yorick.cygnus.com>
* call.c class.c cp-tree.h cvt.c decl.c decl2.c error.c expr.c
init.c lex.c method.c parse.y pt.c repo.c search.c spew.c tree.c
tree.def typeck.c typeck2.c xref.c: Massive, systemic changes for
the new template implementation.
They were all introduced with class "e", which was later renamed to
tcc_expression, which is what they are today.
In a quick look at the C++ front end, I can only find one bit of code
which cares whether it is looking at a tcc_expression or a
tcc_statement: value_dependent_expression_p in pt.c. That function
will always return false for a statement. For all of the tree codes
listed above, currently class tcc_expression, the function will call
itself recursively on expression operands. I haven't tried to track
all the calls to see whether any of the above codes can be passed to
value_dependent_expression_p, but it doesn't seem likely.
In the main compiler, the main difference between tcc_expression and
tcc_statement is whether TREE_SIDE_EFFECTS is set. (There are also
some checks in tree-browser.c on EXPRESSION_CLASS_P which are probably
unimportant.) For tcc_statement, TREE_SIDE_EFFECTS is always set.
For tcc_expression, it is not. However, it happens that the C++
frontend builds the above codes using the function build_stmt, and
that function will always set TREE_SIDE_EFFECTS for them.
Anyhow, I'm testing the obvious patch to use tcc_statement instead of
tcc_expression in cp-tree.def, and I will submit it to gcc-patches if
it works. At the moment I'm curious as to whether anybody has a
reason why these codes should be tcc_expression rather than
tcc_statement.
Ian