This is an archive of the discontinued LLVM Phabricator instance.

Create ConstantExpr class
ClosedPublic

Authored by void on Oct 20 2018, 3:38 PM.

Details

Summary

A ConstantExpr class represents a full expression that's in a
context where a constant expression is required. This class reflects
the path the evaluator took to reach the expression rather than
the syntactic context in which the expression occurs.

In the future, the class will be expanded to cache the result of
the evaluated expression so that it's not needlessly re-evaluated.

Diff Detail

Repository
rC Clang

Event Timeline

void created this revision.Oct 20 2018, 3:38 PM
void updated this revision to Diff 170321.Oct 20 2018, 3:39 PM

Looks fine as far as it goes, but we're going to need to change all the places that skip past ExprWithCleanups to also step over this node. Since both nodes represent the boundary of a particular kind of full-expression, it'd make sense to me for them to at least have a common base class for such "skipping" purposes.

lib/AST/StmtProfile.cpp
1001

This is unnecessary: this visitor visits the children of the node for you.

void updated this revision to Diff 170324.Oct 20 2018, 5:36 PM
void marked an inline comment as done.

Create a "FullExpression" parent class and skip full expressions in all places we skip with ExprWithCleanups.

void marked an inline comment as not done.Oct 20 2018, 5:37 PM
void updated this revision to Diff 170325.Oct 20 2018, 5:54 PM

Thanks, this is looking good.

include/clang/AST/Expr.h
875–876

All of our expression classes have names ending Expr; I don't think we should deviate from that convention here.

887–890

These should not be virtual; this class hierarchy uses LLVM-style RTTI rather than vtables. If you want to provide these convenience methods on FullExpr, you can manually dispatch on the dynamic type using dyn_cast or similar.

925–926

The children range for a ConstantExpr should comprise Val itself, not Val's children.

include/clang/Basic/StmtNodes.td
97

Please add a def FullExpr : DStmt<Expr, 1> and change this and ExprWithCleanups to be : DStmt<FullExpr> so that our visitors will be able to visit the FullExpr base class.

lib/AST/Expr.cpp
3145–3146

Please add a FIXME here to move this into the return false; block. (Keeping this functionally identical to an ExprWithCleanups with no cleanups for now seems fine.)

void marked 6 inline comments as done.Oct 28 2018, 1:33 AM
void added inline comments.
lib/AST/StmtProfile.cpp
1001

If I don't have this then the link fails because it cannot find this.

void updated this revision to Diff 171417.Oct 28 2018, 1:34 AM
void marked an inline comment as done.
rsmith accepted this revision.Oct 30 2018, 5:43 PM

Thanks, looks good. I don't mind if you address the comments below before this commit or in a separate commit.

include/clang/AST/Expr.h
898

I think it'd be cleaner and simpler to move this field into the base class, merging it with the corresponding member of ExprWithCleanups.

include/clang/AST/StmtDataCollectors.td
17–23

Do we need this? I think we probably don't:
a) we don't have corresponding code for ExprWithCleanups
b) we already add the type via the Expr handler
c) the type of ConstantExpr doesn't actually add any new information because it's always the same as the type of the wrapped expression

lib/AST/StmtProfile.cpp
1001

No worries: I think this comment was against a previous version where you were also explicitly visiting the substatement of S.

This revision is now accepted and ready to land.Oct 30 2018, 5:43 PM
void added a comment.Oct 30 2018, 7:21 PM

Thanks, Richard! :-)

void closed this revision.Oct 30 2018, 8:02 PM
void marked 2 inline comments as done.
void added inline comments.
include/clang/AST/Expr.h
898

Oh good. I was wanting to do that. Done. :-)

I think you may have accidentally commited the wrong patch.

+struct ConstantExpr : public FullExpr {

Is causing a warning right now, not sure where that came from.

void marked 4 inline comments as done.Oct 30 2018, 9:59 PM

That change was intentional. But I guess it's causing issues. I'll change it to a class.

Ah, it was causing this warning during build:

/SourceCache/llvm-trunk-8.0/tools/clang/include/clang/AST/Expr.h:903:1: warning: 'ConstantExpr' defined as a struct here but previously declared as a class [-Wmismatched-tags]
void added a subscriber: rsmith.Oct 30 2018, 10:07 PM

I didn't see that during my tests. Probably different -W flags or
something. I reverted that bit. I hope it fixes the problem.

-bw