diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -6310,6 +6310,18 @@ return PseudoObjectExprBits.NumSubExprs; } + void setNumSubExprs(unsigned Val) { + assert(Val <= std::numeric_limits::max() && + "The value of NumSubExprs too large."); + PseudoObjectExprBits.NumSubExprs = Val; + } + + void setResultExprIndex(unsigned Val) { + assert(Val <= std::numeric_limits::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. diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/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 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]); diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/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();