This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix the serialization of LambdaExpr and the bogus mutation in LambdaExpr::getBody
ClosedPublic

Authored by riccibruno on Jun 13 2020, 5:22 AM.

Details

Summary

The body of LambdaExpr is currently not properly serialized. Instead LambdaExpr::getBody
checks if the body has been already deserialized and if not mutates LambdaExpr. This can be
observed with an AST dump test, where the body of the LambdaExpr will be null.

The mutation in LambdaExpr::getBody was left because of another bug: it is not true that the body
of a LambdaExpr is always a CompoundStmt; it can also be a CoroutineBodyStmt wrapping a
CompoundStmt. This is fixed by returning a Stmt * from getBody and introducing a convenience
function getCompoundStmtBody which always returns a CompoundStmt *. This function can be
used by callers who do not care about the coroutine node.

Happily all but one user of getBody treat it as a Stmt * and so this change is non-intrusive.

Diff Detail

Event Timeline

riccibruno created this revision.Jun 13 2020, 5:22 AM
aaron.ballman accepted this revision.Jun 15 2020, 4:59 AM

LGTM with some nits.

clang/include/clang/AST/ExprCXX.h
2012–2017

I wish we'd get the const correctness right when doing this (const methods returning pointers to const objects, not mixing constness like this). I don't insist, but if you put in overloads, I wouldn't be sad either.

clang/test/AST/ast-dump-lambda.cpp
11

Can remove some newlines here.

This revision is now accepted and ready to land.Jun 15 2020, 4:59 AM
riccibruno marked 4 inline comments as done.Jun 17 2020, 2:19 AM
riccibruno added inline comments.
clang/include/clang/AST/ExprCXX.h
2012–2017

I agree, these const-incorrect methods are a bad habit. The overloads even were in a previous version of this patch so I am not sure why I did not include them here. I will definitely include them in the commit.

This revision was automatically updated to reflect the committed changes.
riccibruno marked an inline comment as done.
martong added a subscriber: martong.Jul 1 2020, 2:41 AM

This patch causes a regression (crash) during the deserialization of certain functions. Please see the details and review the supposed fix here: https://reviews.llvm.org/D82940