yronglin created this revision. Herald added a subscriber: arphaman. Herald added a project: All. yronglin requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Signed-off-by: yronglin <yronglin...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D158296 Files: clang/include/clang/AST/Expr.h clang/lib/AST/Expr.cpp clang/lib/Serialization/ASTReaderStmt.cpp Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -1378,9 +1378,8 @@ void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) { VisitExpr(E); unsigned numSemanticExprs = Record.readInt(); - assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs); - E->PseudoObjectExprBits.ResultIndex = Record.readInt(); - + assert(numSemanticExprs + 1 == E->getNumSubExprs()); + E->setResultExprIndex(Record.readInt()); // Read the syntactic expression. E->getSubExprsBuffer()[0] = Record.readSubExpr(); Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -4839,7 +4839,7 @@ PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) : Expr(PseudoObjectExprClass, shell) { - PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; + setNumSubExprs(numSemanticExprs + 1); } PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, @@ -4870,8 +4870,9 @@ Expr *syntax, ArrayRef<Expr *> semantics, unsigned resultIndex) : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) { - PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; - PseudoObjectExprBits.ResultIndex = resultIndex + 1; + + setNumSubExprs(semantics.size() + 1); + setResultExprIndex(resultIndex + 1); for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { Expr *E = (i == 0 ? syntax : semantics[i-1]); Index: clang/include/clang/AST/Expr.h =================================================================== --- clang/include/clang/AST/Expr.h +++ clang/include/clang/AST/Expr.h @@ -6310,6 +6310,18 @@ return PseudoObjectExprBits.NumSubExprs; } + void setNumSubExprs(unsigned Val) { + assert(Val <= std::numeric_limits<uint16_t>::max() && + "The value of NumSubExprs too large."); + PseudoObjectExprBits.NumSubExprs = Val; + } + + void setResultExprIndex(unsigned Val) { + assert(Val <= std::numeric_limits<uint16_t>::max() && + "The value of NumSubExprs too large."); + PseudoObjectExprBits.ResultIndex = Val; + } + public: /// NoResult - A value for the result index indicating that there is /// no semantic result.
Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -1378,9 +1378,8 @@ void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) { VisitExpr(E); unsigned numSemanticExprs = Record.readInt(); - assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs); - E->PseudoObjectExprBits.ResultIndex = Record.readInt(); - + assert(numSemanticExprs + 1 == E->getNumSubExprs()); + E->setResultExprIndex(Record.readInt()); // Read the syntactic expression. E->getSubExprsBuffer()[0] = Record.readSubExpr(); Index: clang/lib/AST/Expr.cpp =================================================================== --- clang/lib/AST/Expr.cpp +++ clang/lib/AST/Expr.cpp @@ -4839,7 +4839,7 @@ PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs) : Expr(PseudoObjectExprClass, shell) { - PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1; + setNumSubExprs(numSemanticExprs + 1); } PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax, @@ -4870,8 +4870,9 @@ Expr *syntax, ArrayRef<Expr *> semantics, unsigned resultIndex) : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) { - PseudoObjectExprBits.NumSubExprs = semantics.size() + 1; - PseudoObjectExprBits.ResultIndex = resultIndex + 1; + + setNumSubExprs(semantics.size() + 1); + setResultExprIndex(resultIndex + 1); for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) { Expr *E = (i == 0 ? syntax : semantics[i-1]); Index: clang/include/clang/AST/Expr.h =================================================================== --- clang/include/clang/AST/Expr.h +++ clang/include/clang/AST/Expr.h @@ -6310,6 +6310,18 @@ return PseudoObjectExprBits.NumSubExprs; } + void setNumSubExprs(unsigned Val) { + assert(Val <= std::numeric_limits<uint16_t>::max() && + "The value of NumSubExprs too large."); + PseudoObjectExprBits.NumSubExprs = Val; + } + + void setResultExprIndex(unsigned Val) { + assert(Val <= std::numeric_limits<uint16_t>::max() && + "The value of NumSubExprs too large."); + PseudoObjectExprBits.ResultIndex = Val; + } + public: /// NoResult - A value for the result index indicating that there is /// no semantic result.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits