This is an archive of the discontinued LLVM Phabricator instance.

Syntax tree: ignore implicit expressions at the top level of statements
ClosedPublic

Authored by gribozavr on Jun 2 2020, 10:48 AM.

Details

Summary

I changed markStmtChild to ignore implicit expressions the same way as
markExprChild does it already. The test that I modified crashes
without this change.

Diff Detail

Event Timeline

gribozavr created this revision.Jun 2 2020, 10:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2020, 10:48 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr updated this revision to Diff 267937.Jun 2 2020, 11:00 AM

Refactored makeStmtChild to have fewer redundant checks.

Harbormaster completed remote builds in B58790: Diff 267937.
hlopko accepted this revision.Jun 3 2020, 12:26 AM

LGTM :)

This revision is now accepted and ready to land.Jun 3 2020, 12:26 AM
eduucaldas accepted this revision.Jun 3 2020, 1:04 AM
eduucaldas added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
1048

I thought this treatement of derived class should be done by RecursiveASTVisitor
This is kinda the task of WalkUpFrom*, unfortunately WalkUpFromThis follows the order:
WalkUpFromBase;
VisitThis;

And we would've wanted the opposite order:
VisitThis
WalkUpFromBase

gribozavr2 added inline comments.
clang/lib/Tooling/Syntax/BuildTree.cpp
1048

Unfortunately I don't see how to implement this behavior (cheaply) in the visitation methods of RecursiveASTVisitor. The crux of the issue is that we are inserting a syntax tree node (ExpressionStatement) that does not correspond to any semantic AST node. We want to do it for every Expr that appears in a Stmt position -- so we need to know the parent node, or in this case, more precisely, that this Expr node is in a Stmt position.

This revision was automatically updated to reflect the committed changes.