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

Bruno Ricci via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 13 05:54:19 PDT 2020


riccibruno created this revision.
riccibruno added reviewers: jyknight, GorNishanov, aaron.ballman.
riccibruno added a project: clang.
Herald added subscribers: cfe-commits, modocache.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81787

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81787.270572.patch
Type: text/x-patch
Size: 16992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200613/9e189318/attachment.bin>


More information about the cfe-commits mailing list