[clang] Fix the serialization of LambdaExpr and the bogus mutation in LambdaExpr...
authorBruno Ricci <riccibrun@gmail.com>
Thu, 18 Jun 2020 11:51:11 +0000 (12:51 +0100)
committerBruno Ricci <riccibrun@gmail.com>
Thu, 18 Jun 2020 12:37:24 +0000 (13:37 +0100)
commit05843dc6ab97a00cbde7aa4f08bf3692eb83109d
tree583c4a6c124deeab1317180416c196f63ca5316c
parenteb4c758fe4b60ae3779d3e9401d00ee1450ae41b
[clang] Fix the serialization of LambdaExpr and the bogus mutation in LambdaExpr::getBody

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.

Differential Revision: https://reviews.llvm.org/D81787

Reviewed By: aaron.ballman
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/AST/ast-dump-lambda.cpp