TARGET_EXPR question...
Chris Lattner
sabre@nondot.org
Fri Oct 10 20:45:00 GMT 2003
I have a question about the TARGET_EXPR_CLEANUP operand of TARGET_EXPR
nodes. According to the documentation:
"The third operand to the TARGET_EXPR, if present, is a cleanup-expression
(i.e., destructor call) for the temporary. If this expression is orphaned,
then this expression must be executed when the statement containing this
expression is complete." ...
My reading of this is that the cleanup should only be executed if the
TARGET_EXPR is orphaned, not if it's normal. This makes the tree
representation much more difficult to deal with outside of the expander
(which is the only place that trivially knows if a "target" will be
available when the TARGET_EXPR is expanded).
Unfortunately also, this is not just a matter of optimization either (the
compiler cannot "choose" to not create an alias and run the cleanup for
normal TARGET_EXPRs). For example, in a case like this:
struct A {
A();
A(const A &);
~A();
};
...
throw A();
...
Here, an exception object is allocated, a "normal" TARGET_EXPR is created
as an alias for the space in the exception object. The A() constructor is
called to initialize the object in the exception, and then the thow
happens. Because this is a "normal" TARGET_EXPR, the cleanup (which
would run ~A()) is not run, and things are all ok. The compiler _cannot_
make a bitwise copy of the object and unconditionally run the cleanup: it
would have to run the copy ctor, which the tree representation doesn't
expose).
Unfortunately, for my code, it's difficult to tell the difference between
a normal and orphaned target expression, so I don't know whether to run
the cleanup or not.
Is there something I'm missing here about TARGET_EXPR's? Is there some
way to determine whether a target_expr is orphaned or not?
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the Gcc
mailing list