OSDN Git Service

[clang][Serialization] Fix the serialization of ConstantExpr.
authorBruno Ricci <riccibrun@gmail.com>
Sun, 21 Jun 2020 12:02:48 +0000 (13:02 +0100)
committerBruno Ricci <riccibrun@gmail.com>
Sun, 21 Jun 2020 12:59:10 +0000 (13:59 +0100)
commite7ce0528202306d8b751f132d9d3a6519ce4e688
treeca931bf6339f82ab32e858ce74af87188faab3f3
parentef3adbfc70bd593e14430c2db31c1426d3834fb4
[clang][Serialization] Fix the serialization of ConstantExpr.

The serialization of ConstantExpr has currently a number of problems:

- Some fields are just not serialized (ConstantExprBits.APValueKind and
  ConstantExprBits.IsImmediateInvocation).

- ASTStmtReader::VisitConstantExpr forgets to add the trailing APValue
  to the list of objects to be destroyed when the APValue needs cleanup.

While we are at it, bring the serialization of ConstantExpr more in-line
with what is done with the other expressions by doing the following NFCs:

- Get rid of ConstantExpr::DefaultInit. It is better to not initialize
  the fields of an empty ConstantExpr since this will allow msan to
  detect if a field was not deserialized.

- Move the initialization of the fields of ConstantExpr to the constructor;
  ConstantExpr::Create allocates the memory and ConstantExpr::ConstantExpr
  is responsible for the initialization.

Review after commit since this is a straightforward mechanical fix
similar to the other serialization fixes.
clang/include/clang/AST/Expr.h
clang/include/clang/AST/Stmt.h
clang/lib/AST/Expr.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/AST/ast-dump-constant-expr.cpp [new file with mode: 0644]