1 //===- ASTReaderStmt.cpp - Stmt/Expr Deserialization ----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Statement/expression deserialization.  This implements the
10 // ASTReader::ReadStmt method.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTConcept.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/AttrIterator.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/DeclAccessPair.h"
19 #include "clang/AST/DeclCXX.h"
20 #include "clang/AST/DeclGroup.h"
21 #include "clang/AST/DeclObjC.h"
22 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/DeclarationName.h"
24 #include "clang/AST/DependenceFlags.h"
25 #include "clang/AST/Expr.h"
26 #include "clang/AST/ExprCXX.h"
27 #include "clang/AST/ExprObjC.h"
28 #include "clang/AST/ExprOpenMP.h"
29 #include "clang/AST/NestedNameSpecifier.h"
30 #include "clang/AST/OpenMPClause.h"
31 #include "clang/AST/OperationKinds.h"
32 #include "clang/AST/Stmt.h"
33 #include "clang/AST/StmtCXX.h"
34 #include "clang/AST/StmtObjC.h"
35 #include "clang/AST/StmtOpenMP.h"
36 #include "clang/AST/StmtVisitor.h"
37 #include "clang/AST/TemplateBase.h"
38 #include "clang/AST/Type.h"
39 #include "clang/AST/UnresolvedSet.h"
40 #include "clang/Basic/CapturedStmt.h"
41 #include "clang/Basic/ExpressionTraits.h"
42 #include "clang/Basic/LLVM.h"
43 #include "clang/Basic/Lambda.h"
44 #include "clang/Basic/LangOptions.h"
45 #include "clang/Basic/OpenMPKinds.h"
46 #include "clang/Basic/OperatorKinds.h"
47 #include "clang/Basic/SourceLocation.h"
48 #include "clang/Basic/Specifiers.h"
49 #include "clang/Basic/TypeTraits.h"
50 #include "clang/Lex/Token.h"
51 #include "clang/Serialization/ASTBitCodes.h"
52 #include "clang/Serialization/ASTRecordReader.h"
53 #include "llvm/ADT/BitmaskEnum.h"
54 #include "llvm/ADT/DenseMap.h"
55 #include "llvm/ADT/SmallString.h"
56 #include "llvm/ADT/SmallVector.h"
57 #include "llvm/ADT/StringRef.h"
58 #include "llvm/Bitstream/BitstreamReader.h"
59 #include "llvm/Support/Casting.h"
60 #include "llvm/Support/ErrorHandling.h"
61 #include <algorithm>
62 #include <cassert>
63 #include <cstdint>
64 #include <string>
65 
66 using namespace clang;
67 using namespace serialization;
68 
69 namespace clang {
70 
71   class ASTStmtReader : public StmtVisitor<ASTStmtReader> {
72     ASTRecordReader &Record;
73     llvm::BitstreamCursor &DeclsCursor;
74 
75     SourceLocation readSourceLocation() {
76       return Record.readSourceLocation();
77     }
78 
79     SourceRange readSourceRange() {
80       return Record.readSourceRange();
81     }
82 
83     std::string readString() {
84       return Record.readString();
85     }
86 
87     TypeSourceInfo *readTypeSourceInfo() {
88       return Record.readTypeSourceInfo();
89     }
90 
91     Decl *readDecl() {
92       return Record.readDecl();
93     }
94 
95     template<typename T>
96     T *readDeclAs() {
97       return Record.readDeclAs<T>();
98     }
99 
100   public:
101     ASTStmtReader(ASTRecordReader &Record, llvm::BitstreamCursor &Cursor)
102         : Record(Record), DeclsCursor(Cursor) {}
103 
104     /// The number of record fields required for the Stmt class
105     /// itself.
106     static const unsigned NumStmtFields = 0;
107 
108     /// The number of record fields required for the Expr class
109     /// itself.
110     static const unsigned NumExprFields = NumStmtFields + 4;
111 
112     /// Read and initialize a ExplicitTemplateArgumentList structure.
113     void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
114                                    TemplateArgumentLoc *ArgsLocArray,
115                                    unsigned NumTemplateArgs);
116 
117     /// Read and initialize a ExplicitTemplateArgumentList structure.
118     void ReadExplicitTemplateArgumentList(ASTTemplateArgumentListInfo &ArgList,
119                                           unsigned NumTemplateArgs);
120 
121     void VisitStmt(Stmt *S);
122 #define STMT(Type, Base) \
123     void Visit##Type(Type *);
124 #include "clang/AST/StmtNodes.inc"
125   };
126 
127 } // namespace clang
128 
129 void ASTStmtReader::ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args,
130                                               TemplateArgumentLoc *ArgsLocArray,
131                                               unsigned NumTemplateArgs) {
132   SourceLocation TemplateKWLoc = readSourceLocation();
133   TemplateArgumentListInfo ArgInfo;
134   ArgInfo.setLAngleLoc(readSourceLocation());
135   ArgInfo.setRAngleLoc(readSourceLocation());
136   for (unsigned i = 0; i != NumTemplateArgs; ++i)
137     ArgInfo.addArgument(Record.readTemplateArgumentLoc());
138   Args.initializeFrom(TemplateKWLoc, ArgInfo, ArgsLocArray);
139 }
140 
141 void ASTStmtReader::VisitStmt(Stmt *S) {
142   assert(Record.getIdx() == NumStmtFields && "Incorrect statement field count");
143 }
144 
145 void ASTStmtReader::VisitNullStmt(NullStmt *S) {
146   VisitStmt(S);
147   S->setSemiLoc(readSourceLocation());
148   S->NullStmtBits.HasLeadingEmptyMacro = Record.readInt();
149 }
150 
151 void ASTStmtReader::VisitCompoundStmt(CompoundStmt *S) {
152   VisitStmt(S);
153   SmallVector<Stmt *, 16> Stmts;
154   unsigned NumStmts = Record.readInt();
155   while (NumStmts--)
156     Stmts.push_back(Record.readSubStmt());
157   S->setStmts(Stmts);
158   S->CompoundStmtBits.LBraceLoc = readSourceLocation();
159   S->RBraceLoc = readSourceLocation();
160 }
161 
162 void ASTStmtReader::VisitSwitchCase(SwitchCase *S) {
163   VisitStmt(S);
164   Record.recordSwitchCaseID(S, Record.readInt());
165   S->setKeywordLoc(readSourceLocation());
166   S->setColonLoc(readSourceLocation());
167 }
168 
169 void ASTStmtReader::VisitCaseStmt(CaseStmt *S) {
170   VisitSwitchCase(S);
171   bool CaseStmtIsGNURange = Record.readInt();
172   S->setLHS(Record.readSubExpr());
173   S->setSubStmt(Record.readSubStmt());
174   if (CaseStmtIsGNURange) {
175     S->setRHS(Record.readSubExpr());
176     S->setEllipsisLoc(readSourceLocation());
177   }
178 }
179 
180 void ASTStmtReader::VisitDefaultStmt(DefaultStmt *S) {
181   VisitSwitchCase(S);
182   S->setSubStmt(Record.readSubStmt());
183 }
184 
185 void ASTStmtReader::VisitLabelStmt(LabelStmt *S) {
186   VisitStmt(S);
187   bool IsSideEntry = Record.readInt();
188   auto *LD = readDeclAs<LabelDecl>();
189   LD->setStmt(S);
190   S->setDecl(LD);
191   S->setSubStmt(Record.readSubStmt());
192   S->setIdentLoc(readSourceLocation());
193   S->setSideEntry(IsSideEntry);
194 }
195 
196 void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) {
197   VisitStmt(S);
198   // NumAttrs in AttributedStmt is set when creating an empty
199   // AttributedStmt in AttributedStmt::CreateEmpty, since it is needed
200   // to allocate the right amount of space for the trailing Attr *.
201   uint64_t NumAttrs = Record.readInt();
202   AttrVec Attrs;
203   Record.readAttributes(Attrs);
204   (void)NumAttrs;
205   assert(NumAttrs == S->AttributedStmtBits.NumAttrs);
206   assert(NumAttrs == Attrs.size());
207   std::copy(Attrs.begin(), Attrs.end(), S->getAttrArrayPtr());
208   S->SubStmt = Record.readSubStmt();
209   S->AttributedStmtBits.AttrLoc = readSourceLocation();
210 }
211 
212 void ASTStmtReader::VisitIfStmt(IfStmt *S) {
213   VisitStmt(S);
214 
215   bool HasElse = Record.readInt();
216   bool HasVar = Record.readInt();
217   bool HasInit = Record.readInt();
218 
219   S->setStatementKind(static_cast<IfStatementKind>(Record.readInt()));
220   S->setCond(Record.readSubExpr());
221   S->setThen(Record.readSubStmt());
222   if (HasElse)
223     S->setElse(Record.readSubStmt());
224   if (HasVar)
225     S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
226   if (HasInit)
227     S->setInit(Record.readSubStmt());
228 
229   S->setIfLoc(readSourceLocation());
230   S->setLParenLoc(readSourceLocation());
231   S->setRParenLoc(readSourceLocation());
232   if (HasElse)
233     S->setElseLoc(readSourceLocation());
234 }
235 
236 void ASTStmtReader::VisitSwitchStmt(SwitchStmt *S) {
237   VisitStmt(S);
238 
239   bool HasInit = Record.readInt();
240   bool HasVar = Record.readInt();
241   bool AllEnumCasesCovered = Record.readInt();
242   if (AllEnumCasesCovered)
243     S->setAllEnumCasesCovered();
244 
245   S->setCond(Record.readSubExpr());
246   S->setBody(Record.readSubStmt());
247   if (HasInit)
248     S->setInit(Record.readSubStmt());
249   if (HasVar)
250     S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
251 
252   S->setSwitchLoc(readSourceLocation());
253   S->setLParenLoc(readSourceLocation());
254   S->setRParenLoc(readSourceLocation());
255 
256   SwitchCase *PrevSC = nullptr;
257   for (auto E = Record.size(); Record.getIdx() != E; ) {
258     SwitchCase *SC = Record.getSwitchCaseWithID(Record.readInt());
259     if (PrevSC)
260       PrevSC->setNextSwitchCase(SC);
261     else
262       S->setSwitchCaseList(SC);
263 
264     PrevSC = SC;
265   }
266 }
267 
268 void ASTStmtReader::VisitWhileStmt(WhileStmt *S) {
269   VisitStmt(S);
270 
271   bool HasVar = Record.readInt();
272 
273   S->setCond(Record.readSubExpr());
274   S->setBody(Record.readSubStmt());
275   if (HasVar)
276     S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
277 
278   S->setWhileLoc(readSourceLocation());
279   S->setLParenLoc(readSourceLocation());
280   S->setRParenLoc(readSourceLocation());
281 }
282 
283 void ASTStmtReader::VisitDoStmt(DoStmt *S) {
284   VisitStmt(S);
285   S->setCond(Record.readSubExpr());
286   S->setBody(Record.readSubStmt());
287   S->setDoLoc(readSourceLocation());
288   S->setWhileLoc(readSourceLocation());
289   S->setRParenLoc(readSourceLocation());
290 }
291 
292 void ASTStmtReader::VisitForStmt(ForStmt *S) {
293   VisitStmt(S);
294   S->setInit(Record.readSubStmt());
295   S->setCond(Record.readSubExpr());
296   S->setConditionVariable(Record.getContext(), readDeclAs<VarDecl>());
297   S->setInc(Record.readSubExpr());
298   S->setBody(Record.readSubStmt());
299   S->setForLoc(readSourceLocation());
300   S->setLParenLoc(readSourceLocation());
301   S->setRParenLoc(readSourceLocation());
302 }
303 
304 void ASTStmtReader::VisitGotoStmt(GotoStmt *S) {
305   VisitStmt(S);
306   S->setLabel(readDeclAs<LabelDecl>());
307   S->setGotoLoc(readSourceLocation());
308   S->setLabelLoc(readSourceLocation());
309 }
310 
311 void ASTStmtReader::VisitIndirectGotoStmt(IndirectGotoStmt *S) {
312   VisitStmt(S);
313   S->setGotoLoc(readSourceLocation());
314   S->setStarLoc(readSourceLocation());
315   S->setTarget(Record.readSubExpr());
316 }
317 
318 void ASTStmtReader::VisitContinueStmt(ContinueStmt *S) {
319   VisitStmt(S);
320   S->setContinueLoc(readSourceLocation());
321 }
322 
323 void ASTStmtReader::VisitBreakStmt(BreakStmt *S) {
324   VisitStmt(S);
325   S->setBreakLoc(readSourceLocation());
326 }
327 
328 void ASTStmtReader::VisitReturnStmt(ReturnStmt *S) {
329   VisitStmt(S);
330 
331   bool HasNRVOCandidate = Record.readInt();
332 
333   S->setRetValue(Record.readSubExpr());
334   if (HasNRVOCandidate)
335     S->setNRVOCandidate(readDeclAs<VarDecl>());
336 
337   S->setReturnLoc(readSourceLocation());
338 }
339 
340 void ASTStmtReader::VisitDeclStmt(DeclStmt *S) {
341   VisitStmt(S);
342   S->setStartLoc(readSourceLocation());
343   S->setEndLoc(readSourceLocation());
344 
345   if (Record.size() - Record.getIdx() == 1) {
346     // Single declaration
347     S->setDeclGroup(DeclGroupRef(readDecl()));
348   } else {
349     SmallVector<Decl *, 16> Decls;
350     int N = Record.size() - Record.getIdx();
351     Decls.reserve(N);
352     for (int I = 0; I < N; ++I)
353       Decls.push_back(readDecl());
354     S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Record.getContext(),
355                                                    Decls.data(),
356                                                    Decls.size())));
357   }
358 }
359 
360 void ASTStmtReader::VisitAsmStmt(AsmStmt *S) {
361   VisitStmt(S);
362   S->NumOutputs = Record.readInt();
363   S->NumInputs = Record.readInt();
364   S->NumClobbers = Record.readInt();
365   S->setAsmLoc(readSourceLocation());
366   S->setVolatile(Record.readInt());
367   S->setSimple(Record.readInt());
368 }
369 
370 void ASTStmtReader::VisitGCCAsmStmt(GCCAsmStmt *S) {
371   VisitAsmStmt(S);
372   S->NumLabels = Record.readInt();
373   S->setRParenLoc(readSourceLocation());
374   S->setAsmString(cast_or_null<StringLiteral>(Record.readSubStmt()));
375 
376   unsigned NumOutputs = S->getNumOutputs();
377   unsigned NumInputs = S->getNumInputs();
378   unsigned NumClobbers = S->getNumClobbers();
379   unsigned NumLabels = S->getNumLabels();
380 
381   // Outputs and inputs
382   SmallVector<IdentifierInfo *, 16> Names;
383   SmallVector<StringLiteral*, 16> Constraints;
384   SmallVector<Stmt*, 16> Exprs;
385   for (unsigned I = 0, N = NumOutputs + NumInputs; I != N; ++I) {
386     Names.push_back(Record.readIdentifier());
387     Constraints.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
388     Exprs.push_back(Record.readSubStmt());
389   }
390 
391   // Constraints
392   SmallVector<StringLiteral*, 16> Clobbers;
393   for (unsigned I = 0; I != NumClobbers; ++I)
394     Clobbers.push_back(cast_or_null<StringLiteral>(Record.readSubStmt()));
395 
396   // Labels
397   for (unsigned I = 0, N = NumLabels; I != N; ++I)
398     Exprs.push_back(Record.readSubStmt());
399 
400   S->setOutputsAndInputsAndClobbers(Record.getContext(),
401                                     Names.data(), Constraints.data(),
402                                     Exprs.data(), NumOutputs, NumInputs,
403                                     NumLabels,
404                                     Clobbers.data(), NumClobbers);
405 }
406 
407 void ASTStmtReader::VisitMSAsmStmt(MSAsmStmt *S) {
408   VisitAsmStmt(S);
409   S->LBraceLoc = readSourceLocation();
410   S->EndLoc = readSourceLocation();
411   S->NumAsmToks = Record.readInt();
412   std::string AsmStr = readString();
413 
414   // Read the tokens.
415   SmallVector<Token, 16> AsmToks;
416   AsmToks.reserve(S->NumAsmToks);
417   for (unsigned i = 0, e = S->NumAsmToks; i != e; ++i) {
418     AsmToks.push_back(Record.readToken());
419   }
420 
421   // The calls to reserve() for the FooData vectors are mandatory to
422   // prevent dead StringRefs in the Foo vectors.
423 
424   // Read the clobbers.
425   SmallVector<std::string, 16> ClobbersData;
426   SmallVector<StringRef, 16> Clobbers;
427   ClobbersData.reserve(S->NumClobbers);
428   Clobbers.reserve(S->NumClobbers);
429   for (unsigned i = 0, e = S->NumClobbers; i != e; ++i) {
430     ClobbersData.push_back(readString());
431     Clobbers.push_back(ClobbersData.back());
432   }
433 
434   // Read the operands.
435   unsigned NumOperands = S->NumOutputs + S->NumInputs;
436   SmallVector<Expr*, 16> Exprs;
437   SmallVector<std::string, 16> ConstraintsData;
438   SmallVector<StringRef, 16> Constraints;
439   Exprs.reserve(NumOperands);
440   ConstraintsData.reserve(NumOperands);
441   Constraints.reserve(NumOperands);
442   for (unsigned i = 0; i != NumOperands; ++i) {
443     Exprs.push_back(cast<Expr>(Record.readSubStmt()));
444     ConstraintsData.push_back(readString());
445     Constraints.push_back(ConstraintsData.back());
446   }
447 
448   S->initialize(Record.getContext(), AsmStr, AsmToks,
449                 Constraints, Exprs, Clobbers);
450 }
451 
452 void ASTStmtReader::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) {
453   VisitStmt(S);
454   assert(Record.peekInt() == S->NumParams);
455   Record.skipInts(1);
456   auto *StoredStmts = S->getStoredStmts();
457   for (unsigned i = 0;
458        i < CoroutineBodyStmt::SubStmt::FirstParamMove + S->NumParams; ++i)
459     StoredStmts[i] = Record.readSubStmt();
460 }
461 
462 void ASTStmtReader::VisitCoreturnStmt(CoreturnStmt *S) {
463   VisitStmt(S);
464   S->CoreturnLoc = Record.readSourceLocation();
465   for (auto &SubStmt: S->SubStmts)
466     SubStmt = Record.readSubStmt();
467   S->IsImplicit = Record.readInt() != 0;
468 }
469 
470 void ASTStmtReader::VisitCoawaitExpr(CoawaitExpr *E) {
471   VisitExpr(E);
472   E->KeywordLoc = readSourceLocation();
473   for (auto &SubExpr: E->SubExprs)
474     SubExpr = Record.readSubStmt();
475   E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
476   E->setIsImplicit(Record.readInt() != 0);
477 }
478 
479 void ASTStmtReader::VisitCoyieldExpr(CoyieldExpr *E) {
480   VisitExpr(E);
481   E->KeywordLoc = readSourceLocation();
482   for (auto &SubExpr: E->SubExprs)
483     SubExpr = Record.readSubStmt();
484   E->OpaqueValue = cast_or_null<OpaqueValueExpr>(Record.readSubStmt());
485 }
486 
487 void ASTStmtReader::VisitDependentCoawaitExpr(DependentCoawaitExpr *E) {
488   VisitExpr(E);
489   E->KeywordLoc = readSourceLocation();
490   for (auto &SubExpr: E->SubExprs)
491     SubExpr = Record.readSubStmt();
492 }
493 
494 void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
495   VisitStmt(S);
496   Record.skipInts(1);
497   S->setCapturedDecl(readDeclAs<CapturedDecl>());
498   S->setCapturedRegionKind(static_cast<CapturedRegionKind>(Record.readInt()));
499   S->setCapturedRecordDecl(readDeclAs<RecordDecl>());
500 
501   // Capture inits
502   for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
503                                            E = S->capture_init_end();
504        I != E; ++I)
505     *I = Record.readSubExpr();
506 
507   // Body
508   S->setCapturedStmt(Record.readSubStmt());
509   S->getCapturedDecl()->setBody(S->getCapturedStmt());
510 
511   // Captures
512   for (auto &I : S->captures()) {
513     I.VarAndKind.setPointer(readDeclAs<VarDecl>());
514     I.VarAndKind.setInt(
515         static_cast<CapturedStmt::VariableCaptureKind>(Record.readInt()));
516     I.Loc = readSourceLocation();
517   }
518 }
519 
520 void ASTStmtReader::VisitExpr(Expr *E) {
521   VisitStmt(E);
522   E->setType(Record.readType());
523   E->setDependence(static_cast<ExprDependence>(Record.readInt()));
524   E->setValueKind(static_cast<ExprValueKind>(Record.readInt()));
525   E->setObjectKind(static_cast<ExprObjectKind>(Record.readInt()));
526   assert(Record.getIdx() == NumExprFields &&
527          "Incorrect expression field count");
528 }
529 
530 void ASTStmtReader::VisitConstantExpr(ConstantExpr *E) {
531   VisitExpr(E);
532 
533   auto StorageKind = Record.readInt();
534   assert(E->ConstantExprBits.ResultKind == StorageKind && "Wrong ResultKind!");
535 
536   E->ConstantExprBits.APValueKind = Record.readInt();
537   E->ConstantExprBits.IsUnsigned = Record.readInt();
538   E->ConstantExprBits.BitWidth = Record.readInt();
539   E->ConstantExprBits.HasCleanup = false; // Not serialized, see below.
540   E->ConstantExprBits.IsImmediateInvocation = Record.readInt();
541 
542   switch (StorageKind) {
543   case ConstantExpr::RSK_None:
544     break;
545 
546   case ConstantExpr::RSK_Int64:
547     E->Int64Result() = Record.readInt();
548     break;
549 
550   case ConstantExpr::RSK_APValue:
551     E->APValueResult() = Record.readAPValue();
552     if (E->APValueResult().needsCleanup()) {
553       E->ConstantExprBits.HasCleanup = true;
554       Record.getContext().addDestruction(&E->APValueResult());
555     }
556     break;
557   default:
558     llvm_unreachable("unexpected ResultKind!");
559   }
560 
561   E->setSubExpr(Record.readSubExpr());
562 }
563 
564 void ASTStmtReader::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
565   VisitExpr(E);
566 
567   E->setLocation(readSourceLocation());
568   E->setLParenLocation(readSourceLocation());
569   E->setRParenLocation(readSourceLocation());
570 
571   E->setTypeSourceInfo(Record.readTypeSourceInfo());
572 }
573 
574 void ASTStmtReader::VisitPredefinedExpr(PredefinedExpr *E) {
575   VisitExpr(E);
576   bool HasFunctionName = Record.readInt();
577   E->PredefinedExprBits.HasFunctionName = HasFunctionName;
578   E->PredefinedExprBits.Kind = Record.readInt();
579   E->setLocation(readSourceLocation());
580   if (HasFunctionName)
581     E->setFunctionName(cast<StringLiteral>(Record.readSubExpr()));
582 }
583 
584 void ASTStmtReader::VisitDeclRefExpr(DeclRefExpr *E) {
585   VisitExpr(E);
586 
587   E->DeclRefExprBits.HasQualifier = Record.readInt();
588   E->DeclRefExprBits.HasFoundDecl = Record.readInt();
589   E->DeclRefExprBits.HasTemplateKWAndArgsInfo = Record.readInt();
590   E->DeclRefExprBits.HadMultipleCandidates = Record.readInt();
591   E->DeclRefExprBits.RefersToEnclosingVariableOrCapture = Record.readInt();
592   E->DeclRefExprBits.NonOdrUseReason = Record.readInt();
593   unsigned NumTemplateArgs = 0;
594   if (E->hasTemplateKWAndArgsInfo())
595     NumTemplateArgs = Record.readInt();
596 
597   if (E->hasQualifier())
598     new (E->getTrailingObjects<NestedNameSpecifierLoc>())
599         NestedNameSpecifierLoc(Record.readNestedNameSpecifierLoc());
600 
601   if (E->hasFoundDecl())
602     *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
603 
604   if (E->hasTemplateKWAndArgsInfo())
605     ReadTemplateKWAndArgsInfo(
606         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
607         E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
608 
609   E->D = readDeclAs<ValueDecl>();
610   E->setLocation(readSourceLocation());
611   E->DNLoc = Record.readDeclarationNameLoc(E->getDecl()->getDeclName());
612 }
613 
614 void ASTStmtReader::VisitIntegerLiteral(IntegerLiteral *E) {
615   VisitExpr(E);
616   E->setLocation(readSourceLocation());
617   E->setValue(Record.getContext(), Record.readAPInt());
618 }
619 
620 void ASTStmtReader::VisitFixedPointLiteral(FixedPointLiteral *E) {
621   VisitExpr(E);
622   E->setLocation(readSourceLocation());
623   E->setScale(Record.readInt());
624   E->setValue(Record.getContext(), Record.readAPInt());
625 }
626 
627 void ASTStmtReader::VisitFloatingLiteral(FloatingLiteral *E) {
628   VisitExpr(E);
629   E->setRawSemantics(
630       static_cast<llvm::APFloatBase::Semantics>(Record.readInt()));
631   E->setExact(Record.readInt());
632   E->setValue(Record.getContext(), Record.readAPFloat(E->getSemantics()));
633   E->setLocation(readSourceLocation());
634 }
635 
636 void ASTStmtReader::VisitImaginaryLiteral(ImaginaryLiteral *E) {
637   VisitExpr(E);
638   E->setSubExpr(Record.readSubExpr());
639 }
640 
641 void ASTStmtReader::VisitStringLiteral(StringLiteral *E) {
642   VisitExpr(E);
643 
644   // NumConcatenated, Length and CharByteWidth are set by the empty
645   // ctor since they are needed to allocate storage for the trailing objects.
646   unsigned NumConcatenated = Record.readInt();
647   unsigned Length = Record.readInt();
648   unsigned CharByteWidth = Record.readInt();
649   assert((NumConcatenated == E->getNumConcatenated()) &&
650          "Wrong number of concatenated tokens!");
651   assert((Length == E->getLength()) && "Wrong Length!");
652   assert((CharByteWidth == E->getCharByteWidth()) && "Wrong character width!");
653   E->StringLiteralBits.Kind = Record.readInt();
654   E->StringLiteralBits.IsPascal = Record.readInt();
655 
656   // The character width is originally computed via mapCharByteWidth.
657   // Check that the deserialized character width is consistant with the result
658   // of calling mapCharByteWidth.
659   assert((CharByteWidth ==
660           StringLiteral::mapCharByteWidth(Record.getContext().getTargetInfo(),
661                                           E->getKind())) &&
662          "Wrong character width!");
663 
664   // Deserialize the trailing array of SourceLocation.
665   for (unsigned I = 0; I < NumConcatenated; ++I)
666     E->setStrTokenLoc(I, readSourceLocation());
667 
668   // Deserialize the trailing array of char holding the string data.
669   char *StrData = E->getStrDataAsChar();
670   for (unsigned I = 0; I < Length * CharByteWidth; ++I)
671     StrData[I] = Record.readInt();
672 }
673 
674 void ASTStmtReader::VisitCharacterLiteral(CharacterLiteral *E) {
675   VisitExpr(E);
676   E->setValue(Record.readInt());
677   E->setLocation(readSourceLocation());
678   E->setKind(static_cast<CharacterLiteral::CharacterKind>(Record.readInt()));
679 }
680 
681 void ASTStmtReader::VisitParenExpr(ParenExpr *E) {
682   VisitExpr(E);
683   E->setLParen(readSourceLocation());
684   E->setRParen(readSourceLocation());
685   E->setSubExpr(Record.readSubExpr());
686 }
687 
688 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
689   VisitExpr(E);
690   unsigned NumExprs = Record.readInt();
691   assert((NumExprs == E->getNumExprs()) && "Wrong NumExprs!");
692   for (unsigned I = 0; I != NumExprs; ++I)
693     E->getTrailingObjects<Stmt *>()[I] = Record.readSubStmt();
694   E->LParenLoc = readSourceLocation();
695   E->RParenLoc = readSourceLocation();
696 }
697 
698 void ASTStmtReader::VisitUnaryOperator(UnaryOperator *E) {
699   VisitExpr(E);
700   bool hasFP_Features = Record.readInt();
701   assert(hasFP_Features == E->hasStoredFPFeatures());
702   E->setSubExpr(Record.readSubExpr());
703   E->setOpcode((UnaryOperator::Opcode)Record.readInt());
704   E->setOperatorLoc(readSourceLocation());
705   E->setCanOverflow(Record.readInt());
706   if (hasFP_Features)
707     E->setStoredFPFeatures(
708         FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
709 }
710 
711 void ASTStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) {
712   VisitExpr(E);
713   assert(E->getNumComponents() == Record.peekInt());
714   Record.skipInts(1);
715   assert(E->getNumExpressions() == Record.peekInt());
716   Record.skipInts(1);
717   E->setOperatorLoc(readSourceLocation());
718   E->setRParenLoc(readSourceLocation());
719   E->setTypeSourceInfo(readTypeSourceInfo());
720   for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
721     auto Kind = static_cast<OffsetOfNode::Kind>(Record.readInt());
722     SourceLocation Start = readSourceLocation();
723     SourceLocation End = readSourceLocation();
724     switch (Kind) {
725     case OffsetOfNode::Array:
726       E->setComponent(I, OffsetOfNode(Start, Record.readInt(), End));
727       break;
728 
729     case OffsetOfNode::Field:
730       E->setComponent(
731           I, OffsetOfNode(Start, readDeclAs<FieldDecl>(), End));
732       break;
733 
734     case OffsetOfNode::Identifier:
735       E->setComponent(
736           I,
737           OffsetOfNode(Start, Record.readIdentifier(), End));
738       break;
739 
740     case OffsetOfNode::Base: {
741       auto *Base = new (Record.getContext()) CXXBaseSpecifier();
742       *Base = Record.readCXXBaseSpecifier();
743       E->setComponent(I, OffsetOfNode(Base));
744       break;
745     }
746     }
747   }
748 
749   for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I)
750     E->setIndexExpr(I, Record.readSubExpr());
751 }
752 
753 void ASTStmtReader::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E) {
754   VisitExpr(E);
755   E->setKind(static_cast<UnaryExprOrTypeTrait>(Record.readInt()));
756   if (Record.peekInt() == 0) {
757     E->setArgument(Record.readSubExpr());
758     Record.skipInts(1);
759   } else {
760     E->setArgument(readTypeSourceInfo());
761   }
762   E->setOperatorLoc(readSourceLocation());
763   E->setRParenLoc(readSourceLocation());
764 }
765 
766 static ConstraintSatisfaction
767 readConstraintSatisfaction(ASTRecordReader &Record) {
768   ConstraintSatisfaction Satisfaction;
769   Satisfaction.IsSatisfied = Record.readInt();
770   if (!Satisfaction.IsSatisfied) {
771     unsigned NumDetailRecords = Record.readInt();
772     for (unsigned i = 0; i != NumDetailRecords; ++i) {
773       Expr *ConstraintExpr = Record.readExpr();
774       if (/* IsDiagnostic */Record.readInt()) {
775         SourceLocation DiagLocation = Record.readSourceLocation();
776         std::string DiagMessage = Record.readString();
777         Satisfaction.Details.emplace_back(
778             ConstraintExpr, new (Record.getContext())
779                                 ConstraintSatisfaction::SubstitutionDiagnostic{
780                                     DiagLocation, DiagMessage});
781       } else
782         Satisfaction.Details.emplace_back(ConstraintExpr, Record.readExpr());
783     }
784   }
785   return Satisfaction;
786 }
787 
788 void ASTStmtReader::VisitConceptSpecializationExpr(
789         ConceptSpecializationExpr *E) {
790   VisitExpr(E);
791   unsigned NumTemplateArgs = Record.readInt();
792   E->NestedNameSpec = Record.readNestedNameSpecifierLoc();
793   E->TemplateKWLoc = Record.readSourceLocation();
794   E->ConceptName = Record.readDeclarationNameInfo();
795   E->NamedConcept = readDeclAs<ConceptDecl>();
796   E->FoundDecl = Record.readDeclAs<NamedDecl>();
797   E->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
798   llvm::SmallVector<TemplateArgument, 4> Args;
799   for (unsigned I = 0; I < NumTemplateArgs; ++I)
800     Args.push_back(Record.readTemplateArgument());
801   E->setTemplateArguments(Args);
802   E->Satisfaction = E->isValueDependent() ? nullptr :
803       ASTConstraintSatisfaction::Create(Record.getContext(),
804                                         readConstraintSatisfaction(Record));
805 }
806 
807 static concepts::Requirement::SubstitutionDiagnostic *
808 readSubstitutionDiagnostic(ASTRecordReader &Record) {
809   std::string SubstitutedEntity = Record.readString();
810   SourceLocation DiagLoc = Record.readSourceLocation();
811   std::string DiagMessage = Record.readString();
812   return new (Record.getContext())
813       concepts::Requirement::SubstitutionDiagnostic{SubstitutedEntity, DiagLoc,
814                                                     DiagMessage};
815 }
816 
817 void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
818   VisitExpr(E);
819   unsigned NumLocalParameters = Record.readInt();
820   unsigned NumRequirements = Record.readInt();
821   E->RequiresExprBits.RequiresKWLoc = Record.readSourceLocation();
822   E->RequiresExprBits.IsSatisfied = Record.readInt();
823   E->Body = Record.readDeclAs<RequiresExprBodyDecl>();
824   llvm::SmallVector<ParmVarDecl *, 4> LocalParameters;
825   for (unsigned i = 0; i < NumLocalParameters; ++i)
826     LocalParameters.push_back(cast<ParmVarDecl>(Record.readDecl()));
827   std::copy(LocalParameters.begin(), LocalParameters.end(),
828             E->getTrailingObjects<ParmVarDecl *>());
829   llvm::SmallVector<concepts::Requirement *, 4> Requirements;
830   for (unsigned i = 0; i < NumRequirements; ++i) {
831     auto RK =
832         static_cast<concepts::Requirement::RequirementKind>(Record.readInt());
833     concepts::Requirement *R = nullptr;
834     switch (RK) {
835       case concepts::Requirement::RK_Type: {
836         auto Status =
837             static_cast<concepts::TypeRequirement::SatisfactionStatus>(
838                 Record.readInt());
839         if (Status == concepts::TypeRequirement::SS_SubstitutionFailure)
840           R = new (Record.getContext())
841               concepts::TypeRequirement(readSubstitutionDiagnostic(Record));
842         else
843           R = new (Record.getContext())
844               concepts::TypeRequirement(Record.readTypeSourceInfo());
845       } break;
846       case concepts::Requirement::RK_Simple:
847       case concepts::Requirement::RK_Compound: {
848         auto Status =
849             static_cast<concepts::ExprRequirement::SatisfactionStatus>(
850                 Record.readInt());
851         llvm::PointerUnion<concepts::Requirement::SubstitutionDiagnostic *,
852                            Expr *> E;
853         if (Status == concepts::ExprRequirement::SS_ExprSubstitutionFailure) {
854           E = readSubstitutionDiagnostic(Record);
855         } else
856           E = Record.readExpr();
857 
858         llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> Req;
859         ConceptSpecializationExpr *SubstitutedConstraintExpr = nullptr;
860         SourceLocation NoexceptLoc;
861         if (RK == concepts::Requirement::RK_Simple) {
862           Req.emplace();
863         } else {
864           NoexceptLoc = Record.readSourceLocation();
865           switch (/* returnTypeRequirementKind */Record.readInt()) {
866             case 0:
867               // No return type requirement.
868               Req.emplace();
869               break;
870             case 1: {
871               // type-constraint
872               TemplateParameterList *TPL = Record.readTemplateParameterList();
873               if (Status >=
874                   concepts::ExprRequirement::SS_ConstraintsNotSatisfied)
875                 SubstitutedConstraintExpr =
876                     cast<ConceptSpecializationExpr>(Record.readExpr());
877               Req.emplace(TPL);
878             } break;
879             case 2:
880               // Substitution failure
881               Req.emplace(readSubstitutionDiagnostic(Record));
882               break;
883           }
884         }
885         if (Expr *Ex = E.dyn_cast<Expr *>())
886           R = new (Record.getContext()) concepts::ExprRequirement(
887                   Ex, RK == concepts::Requirement::RK_Simple, NoexceptLoc,
888                   std::move(*Req), Status, SubstitutedConstraintExpr);
889         else
890           R = new (Record.getContext()) concepts::ExprRequirement(
891                   E.get<concepts::Requirement::SubstitutionDiagnostic *>(),
892                   RK == concepts::Requirement::RK_Simple, NoexceptLoc,
893                   std::move(*Req));
894       } break;
895       case concepts::Requirement::RK_Nested: {
896         if (/* IsSubstitutionDiagnostic */Record.readInt()) {
897           R = new (Record.getContext()) concepts::NestedRequirement(
898               readSubstitutionDiagnostic(Record));
899           break;
900         }
901         Expr *E = Record.readExpr();
902         if (E->isInstantiationDependent())
903           R = new (Record.getContext()) concepts::NestedRequirement(E);
904         else
905           R = new (Record.getContext())
906               concepts::NestedRequirement(Record.getContext(), E,
907                                           readConstraintSatisfaction(Record));
908       } break;
909     }
910     if (!R)
911       continue;
912     Requirements.push_back(R);
913   }
914   std::copy(Requirements.begin(), Requirements.end(),
915             E->getTrailingObjects<concepts::Requirement *>());
916   E->RBraceLoc = Record.readSourceLocation();
917 }
918 
919 void ASTStmtReader::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
920   VisitExpr(E);
921   E->setLHS(Record.readSubExpr());
922   E->setRHS(Record.readSubExpr());
923   E->setRBracketLoc(readSourceLocation());
924 }
925 
926 void ASTStmtReader::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
927   VisitExpr(E);
928   E->setBase(Record.readSubExpr());
929   E->setRowIdx(Record.readSubExpr());
930   E->setColumnIdx(Record.readSubExpr());
931   E->setRBracketLoc(readSourceLocation());
932 }
933 
934 void ASTStmtReader::VisitOMPArraySectionExpr(OMPArraySectionExpr *E) {
935   VisitExpr(E);
936   E->setBase(Record.readSubExpr());
937   E->setLowerBound(Record.readSubExpr());
938   E->setLength(Record.readSubExpr());
939   E->setStride(Record.readSubExpr());
940   E->setColonLocFirst(readSourceLocation());
941   E->setColonLocSecond(readSourceLocation());
942   E->setRBracketLoc(readSourceLocation());
943 }
944 
945 void ASTStmtReader::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
946   VisitExpr(E);
947   unsigned NumDims = Record.readInt();
948   E->setBase(Record.readSubExpr());
949   SmallVector<Expr *, 4> Dims(NumDims);
950   for (unsigned I = 0; I < NumDims; ++I)
951     Dims[I] = Record.readSubExpr();
952   E->setDimensions(Dims);
953   SmallVector<SourceRange, 4> SRs(NumDims);
954   for (unsigned I = 0; I < NumDims; ++I)
955     SRs[I] = readSourceRange();
956   E->setBracketsRanges(SRs);
957   E->setLParenLoc(readSourceLocation());
958   E->setRParenLoc(readSourceLocation());
959 }
960 
961 void ASTStmtReader::VisitOMPIteratorExpr(OMPIteratorExpr *E) {
962   VisitExpr(E);
963   unsigned NumIters = Record.readInt();
964   E->setIteratorKwLoc(readSourceLocation());
965   E->setLParenLoc(readSourceLocation());
966   E->setRParenLoc(readSourceLocation());
967   for (unsigned I = 0; I < NumIters; ++I) {
968     E->setIteratorDeclaration(I, Record.readDeclRef());
969     E->setAssignmentLoc(I, readSourceLocation());
970     Expr *Begin = Record.readSubExpr();
971     Expr *End = Record.readSubExpr();
972     Expr *Step = Record.readSubExpr();
973     SourceLocation ColonLoc = readSourceLocation();
974     SourceLocation SecColonLoc;
975     if (Step)
976       SecColonLoc = readSourceLocation();
977     E->setIteratorRange(I, Begin, ColonLoc, End, SecColonLoc, Step);
978     // Deserialize helpers
979     OMPIteratorHelperData HD;
980     HD.CounterVD = cast_or_null<VarDecl>(Record.readDeclRef());
981     HD.Upper = Record.readSubExpr();
982     HD.Update = Record.readSubExpr();
983     HD.CounterUpdate = Record.readSubExpr();
984     E->setHelper(I, HD);
985   }
986 }
987 
988 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
989   VisitExpr(E);
990   unsigned NumArgs = Record.readInt();
991   bool HasFPFeatures = Record.readInt();
992   assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
993   E->setRParenLoc(readSourceLocation());
994   E->setCallee(Record.readSubExpr());
995   for (unsigned I = 0; I != NumArgs; ++I)
996     E->setArg(I, Record.readSubExpr());
997   E->setADLCallKind(static_cast<CallExpr::ADLCallKind>(Record.readInt()));
998   if (HasFPFeatures)
999     E->setStoredFPFeatures(
1000         FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
1001 }
1002 
1003 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
1004   VisitCallExpr(E);
1005 }
1006 
1007 void ASTStmtReader::VisitMemberExpr(MemberExpr *E) {
1008   VisitExpr(E);
1009 
1010   bool HasQualifier = Record.readInt();
1011   bool HasFoundDecl = Record.readInt();
1012   bool HasTemplateInfo = Record.readInt();
1013   unsigned NumTemplateArgs = Record.readInt();
1014 
1015   E->Base = Record.readSubExpr();
1016   E->MemberDecl = Record.readDeclAs<ValueDecl>();
1017   E->MemberDNLoc = Record.readDeclarationNameLoc(E->MemberDecl->getDeclName());
1018   E->MemberLoc = Record.readSourceLocation();
1019   E->MemberExprBits.IsArrow = Record.readInt();
1020   E->MemberExprBits.HasQualifierOrFoundDecl = HasQualifier || HasFoundDecl;
1021   E->MemberExprBits.HasTemplateKWAndArgsInfo = HasTemplateInfo;
1022   E->MemberExprBits.HadMultipleCandidates = Record.readInt();
1023   E->MemberExprBits.NonOdrUseReason = Record.readInt();
1024   E->MemberExprBits.OperatorLoc = Record.readSourceLocation();
1025 
1026   if (HasQualifier || HasFoundDecl) {
1027     DeclAccessPair FoundDecl;
1028     if (HasFoundDecl) {
1029       auto *FoundD = Record.readDeclAs<NamedDecl>();
1030       auto AS = (AccessSpecifier)Record.readInt();
1031       FoundDecl = DeclAccessPair::make(FoundD, AS);
1032     } else {
1033       FoundDecl = DeclAccessPair::make(E->MemberDecl,
1034                                        E->MemberDecl->getAccess());
1035     }
1036     E->getTrailingObjects<MemberExprNameQualifier>()->FoundDecl = FoundDecl;
1037 
1038     NestedNameSpecifierLoc QualifierLoc;
1039     if (HasQualifier)
1040       QualifierLoc = Record.readNestedNameSpecifierLoc();
1041     E->getTrailingObjects<MemberExprNameQualifier>()->QualifierLoc =
1042         QualifierLoc;
1043   }
1044 
1045   if (HasTemplateInfo)
1046     ReadTemplateKWAndArgsInfo(
1047         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
1048         E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
1049 }
1050 
1051 void ASTStmtReader::VisitObjCIsaExpr(ObjCIsaExpr *E) {
1052   VisitExpr(E);
1053   E->setBase(Record.readSubExpr());
1054   E->setIsaMemberLoc(readSourceLocation());
1055   E->setOpLoc(readSourceLocation());
1056   E->setArrow(Record.readInt());
1057 }
1058 
1059 void ASTStmtReader::
1060 VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
1061   VisitExpr(E);
1062   E->Operand = Record.readSubExpr();
1063   E->setShouldCopy(Record.readInt());
1064 }
1065 
1066 void ASTStmtReader::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
1067   VisitExplicitCastExpr(E);
1068   E->LParenLoc = readSourceLocation();
1069   E->BridgeKeywordLoc = readSourceLocation();
1070   E->Kind = Record.readInt();
1071 }
1072 
1073 void ASTStmtReader::VisitCastExpr(CastExpr *E) {
1074   VisitExpr(E);
1075   unsigned NumBaseSpecs = Record.readInt();
1076   assert(NumBaseSpecs == E->path_size());
1077   unsigned HasFPFeatures = Record.readInt();
1078   assert(E->hasStoredFPFeatures() == HasFPFeatures);
1079   E->setSubExpr(Record.readSubExpr());
1080   E->setCastKind((CastKind)Record.readInt());
1081   CastExpr::path_iterator BaseI = E->path_begin();
1082   while (NumBaseSpecs--) {
1083     auto *BaseSpec = new (Record.getContext()) CXXBaseSpecifier;
1084     *BaseSpec = Record.readCXXBaseSpecifier();
1085     *BaseI++ = BaseSpec;
1086   }
1087   if (HasFPFeatures)
1088     *E->getTrailingFPFeatures() =
1089         FPOptionsOverride::getFromOpaqueInt(Record.readInt());
1090 }
1091 
1092 void ASTStmtReader::VisitBinaryOperator(BinaryOperator *E) {
1093   bool hasFP_Features;
1094   VisitExpr(E);
1095   E->setHasStoredFPFeatures(hasFP_Features = Record.readInt());
1096   E->setOpcode((BinaryOperator::Opcode)Record.readInt());
1097   E->setLHS(Record.readSubExpr());
1098   E->setRHS(Record.readSubExpr());
1099   E->setOperatorLoc(readSourceLocation());
1100   if (hasFP_Features)
1101     E->setStoredFPFeatures(
1102         FPOptionsOverride::getFromOpaqueInt(Record.readInt()));
1103 }
1104 
1105 void ASTStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
1106   VisitBinaryOperator(E);
1107   E->setComputationLHSType(Record.readType());
1108   E->setComputationResultType(Record.readType());
1109 }
1110 
1111 void ASTStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
1112   VisitExpr(E);
1113   E->SubExprs[ConditionalOperator::COND] = Record.readSubExpr();
1114   E->SubExprs[ConditionalOperator::LHS] = Record.readSubExpr();
1115   E->SubExprs[ConditionalOperator::RHS] = Record.readSubExpr();
1116   E->QuestionLoc = readSourceLocation();
1117   E->ColonLoc = readSourceLocation();
1118 }
1119 
1120 void
1121 ASTStmtReader::VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
1122   VisitExpr(E);
1123   E->OpaqueValue = cast<OpaqueValueExpr>(Record.readSubExpr());
1124   E->SubExprs[BinaryConditionalOperator::COMMON] = Record.readSubExpr();
1125   E->SubExprs[BinaryConditionalOperator::COND] = Record.readSubExpr();
1126   E->SubExprs[BinaryConditionalOperator::LHS] = Record.readSubExpr();
1127   E->SubExprs[BinaryConditionalOperator::RHS] = Record.readSubExpr();
1128   E->QuestionLoc = readSourceLocation();
1129   E->ColonLoc = readSourceLocation();
1130 }
1131 
1132 void ASTStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
1133   VisitCastExpr(E);
1134   E->setIsPartOfExplicitCast(Record.readInt());
1135 }
1136 
1137 void ASTStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
1138   VisitCastExpr(E);
1139   E->setTypeInfoAsWritten(readTypeSourceInfo());
1140 }
1141 
1142 void ASTStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
1143   VisitExplicitCastExpr(E);
1144   E->setLParenLoc(readSourceLocation());
1145   E->setRParenLoc(readSourceLocation());
1146 }
1147 
1148 void ASTStmtReader::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
1149   VisitExpr(E);
1150   E->setLParenLoc(readSourceLocation());
1151   E->setTypeSourceInfo(readTypeSourceInfo());
1152   E->setInitializer(Record.readSubExpr());
1153   E->setFileScope(Record.readInt());
1154 }
1155 
1156 void ASTStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
1157   VisitExpr(E);
1158   E->setBase(Record.readSubExpr());
1159   E->setAccessor(Record.readIdentifier());
1160   E->setAccessorLoc(readSourceLocation());
1161 }
1162 
1163 void ASTStmtReader::VisitInitListExpr(InitListExpr *E) {
1164   VisitExpr(E);
1165   if (auto *SyntForm = cast_or_null<InitListExpr>(Record.readSubStmt()))
1166     E->setSyntacticForm(SyntForm);
1167   E->setLBraceLoc(readSourceLocation());
1168   E->setRBraceLoc(readSourceLocation());
1169   bool isArrayFiller = Record.readInt();
1170   Expr *filler = nullptr;
1171   if (isArrayFiller) {
1172     filler = Record.readSubExpr();
1173     E->ArrayFillerOrUnionFieldInit = filler;
1174   } else
1175     E->ArrayFillerOrUnionFieldInit = readDeclAs<FieldDecl>();
1176   E->sawArrayRangeDesignator(Record.readInt());
1177   unsigned NumInits = Record.readInt();
1178   E->reserveInits(Record.getContext(), NumInits);
1179   if (isArrayFiller) {
1180     for (unsigned I = 0; I != NumInits; ++I) {
1181       Expr *init = Record.readSubExpr();
1182       E->updateInit(Record.getContext(), I, init ? init : filler);
1183     }
1184   } else {
1185     for (unsigned I = 0; I != NumInits; ++I)
1186       E->updateInit(Record.getContext(), I, Record.readSubExpr());
1187   }
1188 }
1189 
1190 void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
1191   using Designator = DesignatedInitExpr::Designator;
1192 
1193   VisitExpr(E);
1194   unsigned NumSubExprs = Record.readInt();
1195   assert(NumSubExprs == E->getNumSubExprs() && "Wrong number of subexprs");
1196   for (unsigned I = 0; I != NumSubExprs; ++I)
1197     E->setSubExpr(I, Record.readSubExpr());
1198   E->setEqualOrColonLoc(readSourceLocation());
1199   E->setGNUSyntax(Record.readInt());
1200 
1201   SmallVector<Designator, 4> Designators;
1202   while (Record.getIdx() < Record.size()) {
1203     switch ((DesignatorTypes)Record.readInt()) {
1204     case DESIG_FIELD_DECL: {
1205       auto *Field = readDeclAs<FieldDecl>();
1206       SourceLocation DotLoc = readSourceLocation();
1207       SourceLocation FieldLoc = readSourceLocation();
1208       Designators.push_back(Designator(Field->getIdentifier(), DotLoc,
1209                                        FieldLoc));
1210       Designators.back().setField(Field);
1211       break;
1212     }
1213 
1214     case DESIG_FIELD_NAME: {
1215       const IdentifierInfo *Name = Record.readIdentifier();
1216       SourceLocation DotLoc = readSourceLocation();
1217       SourceLocation FieldLoc = readSourceLocation();
1218       Designators.push_back(Designator(Name, DotLoc, FieldLoc));
1219       break;
1220     }
1221 
1222     case DESIG_ARRAY: {
1223       unsigned Index = Record.readInt();
1224       SourceLocation LBracketLoc = readSourceLocation();
1225       SourceLocation RBracketLoc = readSourceLocation();
1226       Designators.push_back(Designator(Index, LBracketLoc, RBracketLoc));
1227       break;
1228     }
1229 
1230     case DESIG_ARRAY_RANGE: {
1231       unsigned Index = Record.readInt();
1232       SourceLocation LBracketLoc = readSourceLocation();
1233       SourceLocation EllipsisLoc = readSourceLocation();
1234       SourceLocation RBracketLoc = readSourceLocation();
1235       Designators.push_back(Designator(Index, LBracketLoc, EllipsisLoc,
1236                                        RBracketLoc));
1237       break;
1238     }
1239     }
1240   }
1241   E->setDesignators(Record.getContext(),
1242                     Designators.data(), Designators.size());
1243 }
1244 
1245 void ASTStmtReader::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) {
1246   VisitExpr(E);
1247   E->setBase(Record.readSubExpr());
1248   E->setUpdater(Record.readSubExpr());
1249 }
1250 
1251 void ASTStmtReader::VisitNoInitExpr(NoInitExpr *E) {
1252   VisitExpr(E);
1253 }
1254 
1255 void ASTStmtReader::VisitArrayInitLoopExpr(ArrayInitLoopExpr *E) {
1256   VisitExpr(E);
1257   E->SubExprs[0] = Record.readSubExpr();
1258   E->SubExprs[1] = Record.readSubExpr();
1259 }
1260 
1261 void ASTStmtReader::VisitArrayInitIndexExpr(ArrayInitIndexExpr *E) {
1262   VisitExpr(E);
1263 }
1264 
1265 void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
1266   VisitExpr(E);
1267 }
1268 
1269 void ASTStmtReader::VisitVAArgExpr(VAArgExpr *E) {
1270   VisitExpr(E);
1271   E->setSubExpr(Record.readSubExpr());
1272   E->setWrittenTypeInfo(readTypeSourceInfo());
1273   E->setBuiltinLoc(readSourceLocation());
1274   E->setRParenLoc(readSourceLocation());
1275   E->setIsMicrosoftABI(Record.readInt());
1276 }
1277 
1278 void ASTStmtReader::VisitSourceLocExpr(SourceLocExpr *E) {
1279   VisitExpr(E);
1280   E->ParentContext = readDeclAs<DeclContext>();
1281   E->BuiltinLoc = readSourceLocation();
1282   E->RParenLoc = readSourceLocation();
1283   E->SourceLocExprBits.Kind =
1284       static_cast<SourceLocExpr::IdentKind>(Record.readInt());
1285 }
1286 
1287 void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
1288   VisitExpr(E);
1289   E->setAmpAmpLoc(readSourceLocation());
1290   E->setLabelLoc(readSourceLocation());
1291   E->setLabel(readDeclAs<LabelDecl>());
1292 }
1293 
1294 void ASTStmtReader::VisitStmtExpr(StmtExpr *E) {
1295   VisitExpr(E);
1296   E->setLParenLoc(readSourceLocation());
1297   E->setRParenLoc(readSourceLocation());
1298   E->setSubStmt(cast_or_null<CompoundStmt>(Record.readSubStmt()));
1299   E->StmtExprBits.TemplateDepth = Record.readInt();
1300 }
1301 
1302 void ASTStmtReader::VisitChooseExpr(ChooseExpr *E) {
1303   VisitExpr(E);
1304   E->setCond(Record.readSubExpr());
1305   E->setLHS(Record.readSubExpr());
1306   E->setRHS(Record.readSubExpr());
1307   E->setBuiltinLoc(readSourceLocation());
1308   E->setRParenLoc(readSourceLocation());
1309   E->setIsConditionTrue(Record.readInt());
1310 }
1311 
1312 void ASTStmtReader::VisitGNUNullExpr(GNUNullExpr *E) {
1313   VisitExpr(E);
1314   E->setTokenLocation(readSourceLocation());
1315 }
1316 
1317 void ASTStmtReader::VisitShuffleVectorExpr(ShuffleVectorExpr *E) {
1318   VisitExpr(E);
1319   SmallVector<Expr *, 16> Exprs;
1320   unsigned NumExprs = Record.readInt();
1321   while (NumExprs--)
1322     Exprs.push_back(Record.readSubExpr());
1323   E->setExprs(Record.getContext(), Exprs);
1324   E->setBuiltinLoc(readSourceLocation());
1325   E->setRParenLoc(readSourceLocation());
1326 }
1327 
1328 void ASTStmtReader::VisitConvertVectorExpr(ConvertVectorExpr *E) {
1329   VisitExpr(E);
1330   E->BuiltinLoc = readSourceLocation();
1331   E->RParenLoc = readSourceLocation();
1332   E->TInfo = readTypeSourceInfo();
1333   E->SrcExpr = Record.readSubExpr();
1334 }
1335 
1336 void ASTStmtReader::VisitBlockExpr(BlockExpr *E) {
1337   VisitExpr(E);
1338   E->setBlockDecl(readDeclAs<BlockDecl>());
1339 }
1340 
1341 void ASTStmtReader::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
1342   VisitExpr(E);
1343 
1344   unsigned NumAssocs = Record.readInt();
1345   assert(NumAssocs == E->getNumAssocs() && "Wrong NumAssocs!");
1346   E->ResultIndex = Record.readInt();
1347   E->GenericSelectionExprBits.GenericLoc = readSourceLocation();
1348   E->DefaultLoc = readSourceLocation();
1349   E->RParenLoc = readSourceLocation();
1350 
1351   Stmt **Stmts = E->getTrailingObjects<Stmt *>();
1352   // Add 1 to account for the controlling expression which is the first
1353   // expression in the trailing array of Stmt *. This is not needed for
1354   // the trailing array of TypeSourceInfo *.
1355   for (unsigned I = 0, N = NumAssocs + 1; I < N; ++I)
1356     Stmts[I] = Record.readSubExpr();
1357 
1358   TypeSourceInfo **TSIs = E->getTrailingObjects<TypeSourceInfo *>();
1359   for (unsigned I = 0, N = NumAssocs; I < N; ++I)
1360     TSIs[I] = readTypeSourceInfo();
1361 }
1362 
1363 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
1364   VisitExpr(E);
1365   unsigned numSemanticExprs = Record.readInt();
1366   assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
1367   E->PseudoObjectExprBits.ResultIndex = Record.readInt();
1368 
1369   // Read the syntactic expression.
1370   E->getSubExprsBuffer()[0] = Record.readSubExpr();
1371 
1372   // Read all the semantic expressions.
1373   for (unsigned i = 0; i != numSemanticExprs; ++i) {
1374     Expr *subExpr = Record.readSubExpr();
1375     E->getSubExprsBuffer()[i+1] = subExpr;
1376   }
1377 }
1378 
1379 void ASTStmtReader::VisitAtomicExpr(AtomicExpr *E) {
1380   VisitExpr(E);
1381   E->Op = AtomicExpr::AtomicOp(Record.readInt());
1382   E->NumSubExprs = AtomicExpr::getNumSubExprs(E->Op);
1383   for (unsigned I = 0; I != E->NumSubExprs; ++I)
1384     E->SubExprs[I] = Record.readSubExpr();
1385   E->BuiltinLoc = readSourceLocation();
1386   E->RParenLoc = readSourceLocation();
1387 }
1388 
1389 //===----------------------------------------------------------------------===//
1390 // Objective-C Expressions and Statements
1391 
1392 void ASTStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
1393   VisitExpr(E);
1394   E->setString(cast<StringLiteral>(Record.readSubStmt()));
1395   E->setAtLoc(readSourceLocation());
1396 }
1397 
1398 void ASTStmtReader::VisitObjCBoxedExpr(ObjCBoxedExpr *E) {
1399   VisitExpr(E);
1400   // could be one of several IntegerLiteral, FloatLiteral, etc.
1401   E->SubExpr = Record.readSubStmt();
1402   E->BoxingMethod = readDeclAs<ObjCMethodDecl>();
1403   E->Range = readSourceRange();
1404 }
1405 
1406 void ASTStmtReader::VisitObjCArrayLiteral(ObjCArrayLiteral *E) {
1407   VisitExpr(E);
1408   unsigned NumElements = Record.readInt();
1409   assert(NumElements == E->getNumElements() && "Wrong number of elements");
1410   Expr **Elements = E->getElements();
1411   for (unsigned I = 0, N = NumElements; I != N; ++I)
1412     Elements[I] = Record.readSubExpr();
1413   E->ArrayWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
1414   E->Range = readSourceRange();
1415 }
1416 
1417 void ASTStmtReader::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
1418   VisitExpr(E);
1419   unsigned NumElements = Record.readInt();
1420   assert(NumElements == E->getNumElements() && "Wrong number of elements");
1421   bool HasPackExpansions = Record.readInt();
1422   assert(HasPackExpansions == E->HasPackExpansions &&"Pack expansion mismatch");
1423   auto *KeyValues =
1424       E->getTrailingObjects<ObjCDictionaryLiteral::KeyValuePair>();
1425   auto *Expansions =
1426       E->getTrailingObjects<ObjCDictionaryLiteral::ExpansionData>();
1427   for (unsigned I = 0; I != NumElements; ++I) {
1428     KeyValues[I].Key = Record.readSubExpr();
1429     KeyValues[I].Value = Record.readSubExpr();
1430     if (HasPackExpansions) {
1431       Expansions[I].EllipsisLoc = readSourceLocation();
1432       Expansions[I].NumExpansionsPlusOne = Record.readInt();
1433     }
1434   }
1435   E->DictWithObjectsMethod = readDeclAs<ObjCMethodDecl>();
1436   E->Range = readSourceRange();
1437 }
1438 
1439 void ASTStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
1440   VisitExpr(E);
1441   E->setEncodedTypeSourceInfo(readTypeSourceInfo());
1442   E->setAtLoc(readSourceLocation());
1443   E->setRParenLoc(readSourceLocation());
1444 }
1445 
1446 void ASTStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
1447   VisitExpr(E);
1448   E->setSelector(Record.readSelector());
1449   E->setAtLoc(readSourceLocation());
1450   E->setRParenLoc(readSourceLocation());
1451 }
1452 
1453 void ASTStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
1454   VisitExpr(E);
1455   E->setProtocol(readDeclAs<ObjCProtocolDecl>());
1456   E->setAtLoc(readSourceLocation());
1457   E->ProtoLoc = readSourceLocation();
1458   E->setRParenLoc(readSourceLocation());
1459 }
1460 
1461 void ASTStmtReader::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
1462   VisitExpr(E);
1463   E->setDecl(readDeclAs<ObjCIvarDecl>());
1464   E->setLocation(readSourceLocation());
1465   E->setOpLoc(readSourceLocation());
1466   E->setBase(Record.readSubExpr());
1467   E->setIsArrow(Record.readInt());
1468   E->setIsFreeIvar(Record.readInt());
1469 }
1470 
1471 void ASTStmtReader::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
1472   VisitExpr(E);
1473   unsigned MethodRefFlags = Record.readInt();
1474   bool Implicit = Record.readInt() != 0;
1475   if (Implicit) {
1476     auto *Getter = readDeclAs<ObjCMethodDecl>();
1477     auto *Setter = readDeclAs<ObjCMethodDecl>();
1478     E->setImplicitProperty(Getter, Setter, MethodRefFlags);
1479   } else {
1480     E->setExplicitProperty(readDeclAs<ObjCPropertyDecl>(), MethodRefFlags);
1481   }
1482   E->setLocation(readSourceLocation());
1483   E->setReceiverLocation(readSourceLocation());
1484   switch (Record.readInt()) {
1485   case 0:
1486     E->setBase(Record.readSubExpr());
1487     break;
1488   case 1:
1489     E->setSuperReceiver(Record.readType());
1490     break;
1491   case 2:
1492     E->setClassReceiver(readDeclAs<ObjCInterfaceDecl>());
1493     break;
1494   }
1495 }
1496 
1497 void ASTStmtReader::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
1498   VisitExpr(E);
1499   E->setRBracket(readSourceLocation());
1500   E->setBaseExpr(Record.readSubExpr());
1501   E->setKeyExpr(Record.readSubExpr());
1502   E->GetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
1503   E->SetAtIndexMethodDecl = readDeclAs<ObjCMethodDecl>();
1504 }
1505 
1506 void ASTStmtReader::VisitObjCMessageExpr(ObjCMessageExpr *E) {
1507   VisitExpr(E);
1508   assert(Record.peekInt() == E->getNumArgs());
1509   Record.skipInts(1);
1510   unsigned NumStoredSelLocs = Record.readInt();
1511   E->SelLocsKind = Record.readInt();
1512   E->setDelegateInitCall(Record.readInt());
1513   E->IsImplicit = Record.readInt();
1514   auto Kind = static_cast<ObjCMessageExpr::ReceiverKind>(Record.readInt());
1515   switch (Kind) {
1516   case ObjCMessageExpr::Instance:
1517     E->setInstanceReceiver(Record.readSubExpr());
1518     break;
1519 
1520   case ObjCMessageExpr::Class:
1521     E->setClassReceiver(readTypeSourceInfo());
1522     break;
1523 
1524   case ObjCMessageExpr::SuperClass:
1525   case ObjCMessageExpr::SuperInstance: {
1526     QualType T = Record.readType();
1527     SourceLocation SuperLoc = readSourceLocation();
1528     E->setSuper(SuperLoc, T, Kind == ObjCMessageExpr::SuperInstance);
1529     break;
1530   }
1531   }
1532 
1533   assert(Kind == E->getReceiverKind());
1534 
1535   if (Record.readInt())
1536     E->setMethodDecl(readDeclAs<ObjCMethodDecl>());
1537   else
1538     E->setSelector(Record.readSelector());
1539 
1540   E->LBracLoc = readSourceLocation();
1541   E->RBracLoc = readSourceLocation();
1542 
1543   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1544     E->setArg(I, Record.readSubExpr());
1545 
1546   SourceLocation *Locs = E->getStoredSelLocs();
1547   for (unsigned I = 0; I != NumStoredSelLocs; ++I)
1548     Locs[I] = readSourceLocation();
1549 }
1550 
1551 void ASTStmtReader::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) {
1552   VisitStmt(S);
1553   S->setElement(Record.readSubStmt());
1554   S->setCollection(Record.readSubExpr());
1555   S->setBody(Record.readSubStmt());
1556   S->setForLoc(readSourceLocation());
1557   S->setRParenLoc(readSourceLocation());
1558 }
1559 
1560 void ASTStmtReader::VisitObjCAtCatchStmt(ObjCAtCatchStmt *S) {
1561   VisitStmt(S);
1562   S->setCatchBody(Record.readSubStmt());
1563   S->setCatchParamDecl(readDeclAs<VarDecl>());
1564   S->setAtCatchLoc(readSourceLocation());
1565   S->setRParenLoc(readSourceLocation());
1566 }
1567 
1568 void ASTStmtReader::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
1569   VisitStmt(S);
1570   S->setFinallyBody(Record.readSubStmt());
1571   S->setAtFinallyLoc(readSourceLocation());
1572 }
1573 
1574 void ASTStmtReader::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) {
1575   VisitStmt(S); // FIXME: no test coverage.
1576   S->setSubStmt(Record.readSubStmt());
1577   S->setAtLoc(readSourceLocation());
1578 }
1579 
1580 void ASTStmtReader::VisitObjCAtTryStmt(ObjCAtTryStmt *S) {
1581   VisitStmt(S);
1582   assert(Record.peekInt() == S->getNumCatchStmts());
1583   Record.skipInts(1);
1584   bool HasFinally = Record.readInt();
1585   S->setTryBody(Record.readSubStmt());
1586   for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I)
1587     S->setCatchStmt(I, cast_or_null<ObjCAtCatchStmt>(Record.readSubStmt()));
1588 
1589   if (HasFinally)
1590     S->setFinallyStmt(Record.readSubStmt());
1591   S->setAtTryLoc(readSourceLocation());
1592 }
1593 
1594 void ASTStmtReader::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) {
1595   VisitStmt(S); // FIXME: no test coverage.
1596   S->setSynchExpr(Record.readSubStmt());
1597   S->setSynchBody(Record.readSubStmt());
1598   S->setAtSynchronizedLoc(readSourceLocation());
1599 }
1600 
1601 void ASTStmtReader::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) {
1602   VisitStmt(S); // FIXME: no test coverage.
1603   S->setThrowExpr(Record.readSubStmt());
1604   S->setThrowLoc(readSourceLocation());
1605 }
1606 
1607 void ASTStmtReader::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
1608   VisitExpr(E);
1609   E->setValue(Record.readInt());
1610   E->setLocation(readSourceLocation());
1611 }
1612 
1613 void ASTStmtReader::VisitObjCAvailabilityCheckExpr(ObjCAvailabilityCheckExpr *E) {
1614   VisitExpr(E);
1615   SourceRange R = Record.readSourceRange();
1616   E->AtLoc = R.getBegin();
1617   E->RParen = R.getEnd();
1618   E->VersionToCheck = Record.readVersionTuple();
1619 }
1620 
1621 //===----------------------------------------------------------------------===//
1622 // C++ Expressions and Statements
1623 //===----------------------------------------------------------------------===//
1624 
1625 void ASTStmtReader::VisitCXXCatchStmt(CXXCatchStmt *S) {
1626   VisitStmt(S);
1627   S->CatchLoc = readSourceLocation();
1628   S->ExceptionDecl = readDeclAs<VarDecl>();
1629   S->HandlerBlock = Record.readSubStmt();
1630 }
1631 
1632 void ASTStmtReader::VisitCXXTryStmt(CXXTryStmt *S) {
1633   VisitStmt(S);
1634   assert(Record.peekInt() == S->getNumHandlers() && "NumStmtFields is wrong ?");
1635   Record.skipInts(1);
1636   S->TryLoc = readSourceLocation();
1637   S->getStmts()[0] = Record.readSubStmt();
1638   for (unsigned i = 0, e = S->getNumHandlers(); i != e; ++i)
1639     S->getStmts()[i + 1] = Record.readSubStmt();
1640 }
1641 
1642 void ASTStmtReader::VisitCXXForRangeStmt(CXXForRangeStmt *S) {
1643   VisitStmt(S);
1644   S->ForLoc = readSourceLocation();
1645   S->CoawaitLoc = readSourceLocation();
1646   S->ColonLoc = readSourceLocation();
1647   S->RParenLoc = readSourceLocation();
1648   S->setInit(Record.readSubStmt());
1649   S->setRangeStmt(Record.readSubStmt());
1650   S->setBeginStmt(Record.readSubStmt());
1651   S->setEndStmt(Record.readSubStmt());
1652   S->setCond(Record.readSubExpr());
1653   S->setInc(Record.readSubExpr());
1654   S->setLoopVarStmt(Record.readSubStmt());
1655   S->setBody(Record.readSubStmt());
1656 }
1657 
1658 void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
1659   VisitStmt(S);
1660   S->KeywordLoc = readSourceLocation();
1661   S->IsIfExists = Record.readInt();
1662   S->QualifierLoc = Record.readNestedNameSpecifierLoc();
1663   S->NameInfo = Record.readDeclarationNameInfo();
1664   S->SubStmt = Record.readSubStmt();
1665 }
1666 
1667 void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
1668   VisitCallExpr(E);
1669   E->CXXOperatorCallExprBits.OperatorKind = Record.readInt();
1670   E->Range = Record.readSourceRange();
1671 }
1672 
1673 void ASTStmtReader::VisitCXXRewrittenBinaryOperator(
1674     CXXRewrittenBinaryOperator *E) {
1675   VisitExpr(E);
1676   E->CXXRewrittenBinaryOperatorBits.IsReversed = Record.readInt();
1677   E->SemanticForm = Record.readSubExpr();
1678 }
1679 
1680 void ASTStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
1681   VisitExpr(E);
1682 
1683   unsigned NumArgs = Record.readInt();
1684   assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
1685 
1686   E->CXXConstructExprBits.Elidable = Record.readInt();
1687   E->CXXConstructExprBits.HadMultipleCandidates = Record.readInt();
1688   E->CXXConstructExprBits.ListInitialization = Record.readInt();
1689   E->CXXConstructExprBits.StdInitListInitialization = Record.readInt();
1690   E->CXXConstructExprBits.ZeroInitialization = Record.readInt();
1691   E->CXXConstructExprBits.ConstructionKind = Record.readInt();
1692   E->CXXConstructExprBits.Loc = readSourceLocation();
1693   E->Constructor = readDeclAs<CXXConstructorDecl>();
1694   E->ParenOrBraceRange = readSourceRange();
1695 
1696   for (unsigned I = 0; I != NumArgs; ++I)
1697     E->setArg(I, Record.readSubExpr());
1698 }
1699 
1700 void ASTStmtReader::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) {
1701   VisitExpr(E);
1702   E->Constructor = readDeclAs<CXXConstructorDecl>();
1703   E->Loc = readSourceLocation();
1704   E->ConstructsVirtualBase = Record.readInt();
1705   E->InheritedFromVirtualBase = Record.readInt();
1706 }
1707 
1708 void ASTStmtReader::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E) {
1709   VisitCXXConstructExpr(E);
1710   E->TSI = readTypeSourceInfo();
1711 }
1712 
1713 void ASTStmtReader::VisitLambdaExpr(LambdaExpr *E) {
1714   VisitExpr(E);
1715   unsigned NumCaptures = Record.readInt();
1716   (void)NumCaptures;
1717   assert(NumCaptures == E->LambdaExprBits.NumCaptures);
1718   E->IntroducerRange = readSourceRange();
1719   E->LambdaExprBits.CaptureDefault = Record.readInt();
1720   E->CaptureDefaultLoc = readSourceLocation();
1721   E->LambdaExprBits.ExplicitParams = Record.readInt();
1722   E->LambdaExprBits.ExplicitResultType = Record.readInt();
1723   E->ClosingBrace = readSourceLocation();
1724 
1725   // Read capture initializers.
1726   for (LambdaExpr::capture_init_iterator C = E->capture_init_begin(),
1727                                          CEnd = E->capture_init_end();
1728        C != CEnd; ++C)
1729     *C = Record.readSubExpr();
1730 
1731   // The body will be lazily deserialized when needed from the call operator
1732   // declaration.
1733 }
1734 
1735 void
1736 ASTStmtReader::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
1737   VisitExpr(E);
1738   E->SubExpr = Record.readSubExpr();
1739 }
1740 
1741 void ASTStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
1742   VisitExplicitCastExpr(E);
1743   SourceRange R = readSourceRange();
1744   E->Loc = R.getBegin();
1745   E->RParenLoc = R.getEnd();
1746   R = readSourceRange();
1747   E->AngleBrackets = R;
1748 }
1749 
1750 void ASTStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
1751   return VisitCXXNamedCastExpr(E);
1752 }
1753 
1754 void ASTStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
1755   return VisitCXXNamedCastExpr(E);
1756 }
1757 
1758 void ASTStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
1759   return VisitCXXNamedCastExpr(E);
1760 }
1761 
1762 void ASTStmtReader::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
1763   return VisitCXXNamedCastExpr(E);
1764 }
1765 
1766 void ASTStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
1767   return VisitCXXNamedCastExpr(E);
1768 }
1769 
1770 void ASTStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
1771   VisitExplicitCastExpr(E);
1772   E->setLParenLoc(readSourceLocation());
1773   E->setRParenLoc(readSourceLocation());
1774 }
1775 
1776 void ASTStmtReader::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *E) {
1777   VisitExplicitCastExpr(E);
1778   E->KWLoc = readSourceLocation();
1779   E->RParenLoc = readSourceLocation();
1780 }
1781 
1782 void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) {
1783   VisitCallExpr(E);
1784   E->UDSuffixLoc = readSourceLocation();
1785 }
1786 
1787 void ASTStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
1788   VisitExpr(E);
1789   E->setValue(Record.readInt());
1790   E->setLocation(readSourceLocation());
1791 }
1792 
1793 void ASTStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) {
1794   VisitExpr(E);
1795   E->setLocation(readSourceLocation());
1796 }
1797 
1798 void ASTStmtReader::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
1799   VisitExpr(E);
1800   E->setSourceRange(readSourceRange());
1801   if (E->isTypeOperand())
1802     E->Operand = readTypeSourceInfo();
1803   else
1804     E->Operand = Record.readSubExpr();
1805 }
1806 
1807 void ASTStmtReader::VisitCXXThisExpr(CXXThisExpr *E) {
1808   VisitExpr(E);
1809   E->setLocation(readSourceLocation());
1810   E->setImplicit(Record.readInt());
1811 }
1812 
1813 void ASTStmtReader::VisitCXXThrowExpr(CXXThrowExpr *E) {
1814   VisitExpr(E);
1815   E->CXXThrowExprBits.ThrowLoc = readSourceLocation();
1816   E->Operand = Record.readSubExpr();
1817   E->CXXThrowExprBits.IsThrownVariableInScope = Record.readInt();
1818 }
1819 
1820 void ASTStmtReader::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
1821   VisitExpr(E);
1822   E->Param = readDeclAs<ParmVarDecl>();
1823   E->UsedContext = readDeclAs<DeclContext>();
1824   E->CXXDefaultArgExprBits.Loc = readSourceLocation();
1825 }
1826 
1827 void ASTStmtReader::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
1828   VisitExpr(E);
1829   E->Field = readDeclAs<FieldDecl>();
1830   E->UsedContext = readDeclAs<DeclContext>();
1831   E->CXXDefaultInitExprBits.Loc = readSourceLocation();
1832 }
1833 
1834 void ASTStmtReader::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
1835   VisitExpr(E);
1836   E->setTemporary(Record.readCXXTemporary());
1837   E->setSubExpr(Record.readSubExpr());
1838 }
1839 
1840 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
1841   VisitExpr(E);
1842   E->TypeInfo = readTypeSourceInfo();
1843   E->CXXScalarValueInitExprBits.RParenLoc = readSourceLocation();
1844 }
1845 
1846 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {
1847   VisitExpr(E);
1848 
1849   bool IsArray = Record.readInt();
1850   bool HasInit = Record.readInt();
1851   unsigned NumPlacementArgs = Record.readInt();
1852   bool IsParenTypeId = Record.readInt();
1853 
1854   E->CXXNewExprBits.IsGlobalNew = Record.readInt();
1855   E->CXXNewExprBits.ShouldPassAlignment = Record.readInt();
1856   E->CXXNewExprBits.UsualArrayDeleteWantsSize = Record.readInt();
1857   E->CXXNewExprBits.StoredInitializationStyle = Record.readInt();
1858 
1859   assert((IsArray == E->isArray()) && "Wrong IsArray!");
1860   assert((HasInit == E->hasInitializer()) && "Wrong HasInit!");
1861   assert((NumPlacementArgs == E->getNumPlacementArgs()) &&
1862          "Wrong NumPlacementArgs!");
1863   assert((IsParenTypeId == E->isParenTypeId()) && "Wrong IsParenTypeId!");
1864   (void)IsArray;
1865   (void)HasInit;
1866   (void)NumPlacementArgs;
1867 
1868   E->setOperatorNew(readDeclAs<FunctionDecl>());
1869   E->setOperatorDelete(readDeclAs<FunctionDecl>());
1870   E->AllocatedTypeInfo = readTypeSourceInfo();
1871   if (IsParenTypeId)
1872     E->getTrailingObjects<SourceRange>()[0] = readSourceRange();
1873   E->Range = readSourceRange();
1874   E->DirectInitRange = readSourceRange();
1875 
1876   // Install all the subexpressions.
1877   for (CXXNewExpr::raw_arg_iterator I = E->raw_arg_begin(),
1878                                     N = E->raw_arg_end();
1879        I != N; ++I)
1880     *I = Record.readSubStmt();
1881 }
1882 
1883 void ASTStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) {
1884   VisitExpr(E);
1885   E->CXXDeleteExprBits.GlobalDelete = Record.readInt();
1886   E->CXXDeleteExprBits.ArrayForm = Record.readInt();
1887   E->CXXDeleteExprBits.ArrayFormAsWritten = Record.readInt();
1888   E->CXXDeleteExprBits.UsualArrayDeleteWantsSize = Record.readInt();
1889   E->OperatorDelete = readDeclAs<FunctionDecl>();
1890   E->Argument = Record.readSubExpr();
1891   E->CXXDeleteExprBits.Loc = readSourceLocation();
1892 }
1893 
1894 void ASTStmtReader::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) {
1895   VisitExpr(E);
1896 
1897   E->Base = Record.readSubExpr();
1898   E->IsArrow = Record.readInt();
1899   E->OperatorLoc = readSourceLocation();
1900   E->QualifierLoc = Record.readNestedNameSpecifierLoc();
1901   E->ScopeType = readTypeSourceInfo();
1902   E->ColonColonLoc = readSourceLocation();
1903   E->TildeLoc = readSourceLocation();
1904 
1905   IdentifierInfo *II = Record.readIdentifier();
1906   if (II)
1907     E->setDestroyedType(II, readSourceLocation());
1908   else
1909     E->setDestroyedType(readTypeSourceInfo());
1910 }
1911 
1912 void ASTStmtReader::VisitExprWithCleanups(ExprWithCleanups *E) {
1913   VisitExpr(E);
1914 
1915   unsigned NumObjects = Record.readInt();
1916   assert(NumObjects == E->getNumObjects());
1917   for (unsigned i = 0; i != NumObjects; ++i) {
1918     unsigned CleanupKind = Record.readInt();
1919     ExprWithCleanups::CleanupObject Obj;
1920     if (CleanupKind == COK_Block)
1921       Obj = readDeclAs<BlockDecl>();
1922     else if (CleanupKind == COK_CompoundLiteral)
1923       Obj = cast<CompoundLiteralExpr>(Record.readSubExpr());
1924     else
1925       llvm_unreachable("unexpected cleanup object type");
1926     E->getTrailingObjects<ExprWithCleanups::CleanupObject>()[i] = Obj;
1927   }
1928 
1929   E->ExprWithCleanupsBits.CleanupsHaveSideEffects = Record.readInt();
1930   E->SubExpr = Record.readSubExpr();
1931 }
1932 
1933 void ASTStmtReader::VisitCXXDependentScopeMemberExpr(
1934     CXXDependentScopeMemberExpr *E) {
1935   VisitExpr(E);
1936 
1937   bool HasTemplateKWAndArgsInfo = Record.readInt();
1938   unsigned NumTemplateArgs = Record.readInt();
1939   bool HasFirstQualifierFoundInScope = Record.readInt();
1940 
1941   assert((HasTemplateKWAndArgsInfo == E->hasTemplateKWAndArgsInfo()) &&
1942          "Wrong HasTemplateKWAndArgsInfo!");
1943   assert(
1944       (HasFirstQualifierFoundInScope == E->hasFirstQualifierFoundInScope()) &&
1945       "Wrong HasFirstQualifierFoundInScope!");
1946 
1947   if (HasTemplateKWAndArgsInfo)
1948     ReadTemplateKWAndArgsInfo(
1949         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
1950         E->getTrailingObjects<TemplateArgumentLoc>(), NumTemplateArgs);
1951 
1952   assert((NumTemplateArgs == E->getNumTemplateArgs()) &&
1953          "Wrong NumTemplateArgs!");
1954 
1955   E->CXXDependentScopeMemberExprBits.IsArrow = Record.readInt();
1956   E->CXXDependentScopeMemberExprBits.OperatorLoc = readSourceLocation();
1957   E->BaseType = Record.readType();
1958   E->QualifierLoc = Record.readNestedNameSpecifierLoc();
1959   E->Base = Record.readSubExpr();
1960 
1961   if (HasFirstQualifierFoundInScope)
1962     *E->getTrailingObjects<NamedDecl *>() = readDeclAs<NamedDecl>();
1963 
1964   E->MemberNameInfo = Record.readDeclarationNameInfo();
1965 }
1966 
1967 void
1968 ASTStmtReader::VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
1969   VisitExpr(E);
1970 
1971   if (Record.readInt()) // HasTemplateKWAndArgsInfo
1972     ReadTemplateKWAndArgsInfo(
1973         *E->getTrailingObjects<ASTTemplateKWAndArgsInfo>(),
1974         E->getTrailingObjects<TemplateArgumentLoc>(),
1975         /*NumTemplateArgs=*/Record.readInt());
1976 
1977   E->QualifierLoc = Record.readNestedNameSpecifierLoc();
1978   E->NameInfo = Record.readDeclarationNameInfo();
1979 }
1980 
1981 void
1982 ASTStmtReader::VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E) {
1983   VisitExpr(E);
1984   assert(Record.peekInt() == E->getNumArgs() &&
1985          "Read wrong record during creation ?");
1986   Record.skipInts(1);
1987   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
1988     E->setArg(I, Record.readSubExpr());
1989   E->TSI = readTypeSourceInfo();
1990   E->setLParenLoc(readSourceLocation());
1991   E->setRParenLoc(readSourceLocation());
1992 }
1993 
1994 void ASTStmtReader::VisitOverloadExpr(OverloadExpr *E) {
1995   VisitExpr(E);
1996 
1997   unsigned NumResults = Record.readInt();
1998   bool HasTemplateKWAndArgsInfo = Record.readInt();
1999   assert((E->getNumDecls() == NumResults) && "Wrong NumResults!");
2000   assert((E->hasTemplateKWAndArgsInfo() == HasTemplateKWAndArgsInfo) &&
2001          "Wrong HasTemplateKWAndArgsInfo!");
2002 
2003   if (HasTemplateKWAndArgsInfo) {
2004     unsigned NumTemplateArgs = Record.readInt();
2005     ReadTemplateKWAndArgsInfo(*E->getTrailingASTTemplateKWAndArgsInfo(),
2006                               E->getTrailingTemplateArgumentLoc(),
2007                               NumTemplateArgs);
2008     assert((E->getNumTemplateArgs() == NumTemplateArgs) &&
2009            "Wrong NumTemplateArgs!");
2010   }
2011 
2012   UnresolvedSet<8> Decls;
2013   for (unsigned I = 0; I != NumResults; ++I) {
2014     auto *D = readDeclAs<NamedDecl>();
2015     auto AS = (AccessSpecifier)Record.readInt();
2016     Decls.addDecl(D, AS);
2017   }
2018 
2019   DeclAccessPair *Results = E->getTrailingResults();
2020   UnresolvedSetIterator Iter = Decls.begin();
2021   for (unsigned I = 0; I != NumResults; ++I) {
2022     Results[I] = (Iter + I).getPair();
2023   }
2024 
2025   E->NameInfo = Record.readDeclarationNameInfo();
2026   E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2027 }
2028 
2029 void ASTStmtReader::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E) {
2030   VisitOverloadExpr(E);
2031   E->UnresolvedMemberExprBits.IsArrow = Record.readInt();
2032   E->UnresolvedMemberExprBits.HasUnresolvedUsing = Record.readInt();
2033   E->Base = Record.readSubExpr();
2034   E->BaseType = Record.readType();
2035   E->OperatorLoc = readSourceLocation();
2036 }
2037 
2038 void ASTStmtReader::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
2039   VisitOverloadExpr(E);
2040   E->UnresolvedLookupExprBits.RequiresADL = Record.readInt();
2041   E->UnresolvedLookupExprBits.Overloaded = Record.readInt();
2042   E->NamingClass = readDeclAs<CXXRecordDecl>();
2043 }
2044 
2045 void ASTStmtReader::VisitTypeTraitExpr(TypeTraitExpr *E) {
2046   VisitExpr(E);
2047   E->TypeTraitExprBits.NumArgs = Record.readInt();
2048   E->TypeTraitExprBits.Kind = Record.readInt();
2049   E->TypeTraitExprBits.Value = Record.readInt();
2050   SourceRange Range = readSourceRange();
2051   E->Loc = Range.getBegin();
2052   E->RParenLoc = Range.getEnd();
2053 
2054   auto **Args = E->getTrailingObjects<TypeSourceInfo *>();
2055   for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I)
2056     Args[I] = readTypeSourceInfo();
2057 }
2058 
2059 void ASTStmtReader::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
2060   VisitExpr(E);
2061   E->ATT = (ArrayTypeTrait)Record.readInt();
2062   E->Value = (unsigned int)Record.readInt();
2063   SourceRange Range = readSourceRange();
2064   E->Loc = Range.getBegin();
2065   E->RParen = Range.getEnd();
2066   E->QueriedType = readTypeSourceInfo();
2067   E->Dimension = Record.readSubExpr();
2068 }
2069 
2070 void ASTStmtReader::VisitExpressionTraitExpr(ExpressionTraitExpr *E) {
2071   VisitExpr(E);
2072   E->ET = (ExpressionTrait)Record.readInt();
2073   E->Value = (bool)Record.readInt();
2074   SourceRange Range = readSourceRange();
2075   E->QueriedExpression = Record.readSubExpr();
2076   E->Loc = Range.getBegin();
2077   E->RParen = Range.getEnd();
2078 }
2079 
2080 void ASTStmtReader::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
2081   VisitExpr(E);
2082   E->CXXNoexceptExprBits.Value = Record.readInt();
2083   E->Range = readSourceRange();
2084   E->Operand = Record.readSubExpr();
2085 }
2086 
2087 void ASTStmtReader::VisitPackExpansionExpr(PackExpansionExpr *E) {
2088   VisitExpr(E);
2089   E->EllipsisLoc = readSourceLocation();
2090   E->NumExpansions = Record.readInt();
2091   E->Pattern = Record.readSubExpr();
2092 }
2093 
2094 void ASTStmtReader::VisitSizeOfPackExpr(SizeOfPackExpr *E) {
2095   VisitExpr(E);
2096   unsigned NumPartialArgs = Record.readInt();
2097   E->OperatorLoc = readSourceLocation();
2098   E->PackLoc = readSourceLocation();
2099   E->RParenLoc = readSourceLocation();
2100   E->Pack = Record.readDeclAs<NamedDecl>();
2101   if (E->isPartiallySubstituted()) {
2102     assert(E->Length == NumPartialArgs);
2103     for (auto *I = E->getTrailingObjects<TemplateArgument>(),
2104               *E = I + NumPartialArgs;
2105          I != E; ++I)
2106       new (I) TemplateArgument(Record.readTemplateArgument());
2107   } else if (!E->isValueDependent()) {
2108     E->Length = Record.readInt();
2109   }
2110 }
2111 
2112 void ASTStmtReader::VisitSubstNonTypeTemplateParmExpr(
2113                                               SubstNonTypeTemplateParmExpr *E) {
2114   VisitExpr(E);
2115   E->ParamAndRef.setPointer(readDeclAs<NonTypeTemplateParmDecl>());
2116   E->ParamAndRef.setInt(Record.readInt());
2117   E->SubstNonTypeTemplateParmExprBits.NameLoc = readSourceLocation();
2118   E->Replacement = Record.readSubExpr();
2119 }
2120 
2121 void ASTStmtReader::VisitSubstNonTypeTemplateParmPackExpr(
2122                                           SubstNonTypeTemplateParmPackExpr *E) {
2123   VisitExpr(E);
2124   E->Param = readDeclAs<NonTypeTemplateParmDecl>();
2125   TemplateArgument ArgPack = Record.readTemplateArgument();
2126   if (ArgPack.getKind() != TemplateArgument::Pack)
2127     return;
2128 
2129   E->Arguments = ArgPack.pack_begin();
2130   E->NumArguments = ArgPack.pack_size();
2131   E->NameLoc = readSourceLocation();
2132 }
2133 
2134 void ASTStmtReader::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) {
2135   VisitExpr(E);
2136   E->NumParameters = Record.readInt();
2137   E->ParamPack = readDeclAs<ParmVarDecl>();
2138   E->NameLoc = readSourceLocation();
2139   auto **Parms = E->getTrailingObjects<VarDecl *>();
2140   for (unsigned i = 0, n = E->NumParameters; i != n; ++i)
2141     Parms[i] = readDeclAs<VarDecl>();
2142 }
2143 
2144 void ASTStmtReader::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
2145   VisitExpr(E);
2146   bool HasMaterialzedDecl = Record.readInt();
2147   if (HasMaterialzedDecl)
2148     E->State = cast<LifetimeExtendedTemporaryDecl>(Record.readDecl());
2149   else
2150     E->State = Record.readSubExpr();
2151 }
2152 
2153 void ASTStmtReader::VisitCXXFoldExpr(CXXFoldExpr *E) {
2154   VisitExpr(E);
2155   E->LParenLoc = readSourceLocation();
2156   E->EllipsisLoc = readSourceLocation();
2157   E->RParenLoc = readSourceLocation();
2158   E->NumExpansions = Record.readInt();
2159   E->SubExprs[0] = Record.readSubExpr();
2160   E->SubExprs[1] = Record.readSubExpr();
2161   E->SubExprs[2] = Record.readSubExpr();
2162   E->Opcode = (BinaryOperatorKind)Record.readInt();
2163 }
2164 
2165 void ASTStmtReader::VisitOpaqueValueExpr(OpaqueValueExpr *E) {
2166   VisitExpr(E);
2167   E->SourceExpr = Record.readSubExpr();
2168   E->OpaqueValueExprBits.Loc = readSourceLocation();
2169   E->setIsUnique(Record.readInt());
2170 }
2171 
2172 void ASTStmtReader::VisitTypoExpr(TypoExpr *E) {
2173   llvm_unreachable("Cannot read TypoExpr nodes");
2174 }
2175 
2176 void ASTStmtReader::VisitRecoveryExpr(RecoveryExpr *E) {
2177   VisitExpr(E);
2178   unsigned NumArgs = Record.readInt();
2179   E->BeginLoc = readSourceLocation();
2180   E->EndLoc = readSourceLocation();
2181   assert((NumArgs + 0LL ==
2182           std::distance(E->children().begin(), E->children().end())) &&
2183          "Wrong NumArgs!");
2184   (void)NumArgs;
2185   for (Stmt *&Child : E->children())
2186     Child = Record.readSubStmt();
2187 }
2188 
2189 //===----------------------------------------------------------------------===//
2190 // Microsoft Expressions and Statements
2191 //===----------------------------------------------------------------------===//
2192 void ASTStmtReader::VisitMSPropertyRefExpr(MSPropertyRefExpr *E) {
2193   VisitExpr(E);
2194   E->IsArrow = (Record.readInt() != 0);
2195   E->BaseExpr = Record.readSubExpr();
2196   E->QualifierLoc = Record.readNestedNameSpecifierLoc();
2197   E->MemberLoc = readSourceLocation();
2198   E->TheDecl = readDeclAs<MSPropertyDecl>();
2199 }
2200 
2201 void ASTStmtReader::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *E) {
2202   VisitExpr(E);
2203   E->setBase(Record.readSubExpr());
2204   E->setIdx(Record.readSubExpr());
2205   E->setRBracketLoc(readSourceLocation());
2206 }
2207 
2208 void ASTStmtReader::VisitCXXUuidofExpr(CXXUuidofExpr *E) {
2209   VisitExpr(E);
2210   E->setSourceRange(readSourceRange());
2211   E->Guid = readDeclAs<MSGuidDecl>();
2212   if (E->isTypeOperand())
2213     E->Operand = readTypeSourceInfo();
2214   else
2215     E->Operand = Record.readSubExpr();
2216 }
2217 
2218 void ASTStmtReader::VisitSEHLeaveStmt(SEHLeaveStmt *S) {
2219   VisitStmt(S);
2220   S->setLeaveLoc(readSourceLocation());
2221 }
2222 
2223 void ASTStmtReader::VisitSEHExceptStmt(SEHExceptStmt *S) {
2224   VisitStmt(S);
2225   S->Loc = readSourceLocation();
2226   S->Children[SEHExceptStmt::FILTER_EXPR] = Record.readSubStmt();
2227   S->Children[SEHExceptStmt::BLOCK] = Record.readSubStmt();
2228 }
2229 
2230 void ASTStmtReader::VisitSEHFinallyStmt(SEHFinallyStmt *S) {
2231   VisitStmt(S);
2232   S->Loc = readSourceLocation();
2233   S->Block = Record.readSubStmt();
2234 }
2235 
2236 void ASTStmtReader::VisitSEHTryStmt(SEHTryStmt *S) {
2237   VisitStmt(S);
2238   S->IsCXXTry = Record.readInt();
2239   S->TryLoc = readSourceLocation();
2240   S->Children[SEHTryStmt::TRY] = Record.readSubStmt();
2241   S->Children[SEHTryStmt::HANDLER] = Record.readSubStmt();
2242 }
2243 
2244 //===----------------------------------------------------------------------===//
2245 // CUDA Expressions and Statements
2246 //===----------------------------------------------------------------------===//
2247 
2248 void ASTStmtReader::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
2249   VisitCallExpr(E);
2250   E->setPreArg(CUDAKernelCallExpr::CONFIG, Record.readSubExpr());
2251 }
2252 
2253 //===----------------------------------------------------------------------===//
2254 // OpenCL Expressions and Statements.
2255 //===----------------------------------------------------------------------===//
2256 void ASTStmtReader::VisitAsTypeExpr(AsTypeExpr *E) {
2257   VisitExpr(E);
2258   E->BuiltinLoc = readSourceLocation();
2259   E->RParenLoc = readSourceLocation();
2260   E->SrcExpr = Record.readSubExpr();
2261 }
2262 
2263 //===----------------------------------------------------------------------===//
2264 // OpenMP Directives.
2265 //===----------------------------------------------------------------------===//
2266 
2267 void ASTStmtReader::VisitOMPCanonicalLoop(OMPCanonicalLoop *S) {
2268   VisitStmt(S);
2269   for (Stmt *&SubStmt : S->SubStmts)
2270     SubStmt = Record.readSubStmt();
2271 }
2272 
2273 void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) {
2274   Record.readOMPChildren(E->Data);
2275   E->setLocStart(readSourceLocation());
2276   E->setLocEnd(readSourceLocation());
2277 }
2278 
2279 void ASTStmtReader::VisitOMPLoopBasedDirective(OMPLoopBasedDirective *D) {
2280   VisitStmt(D);
2281   // Field CollapsedNum was read in ReadStmtFromStream.
2282   Record.skipInts(1);
2283   VisitOMPExecutableDirective(D);
2284 }
2285 
2286 void ASTStmtReader::VisitOMPLoopDirective(OMPLoopDirective *D) {
2287   VisitOMPLoopBasedDirective(D);
2288 }
2289 
2290 void ASTStmtReader::VisitOMPMetaDirective(OMPMetaDirective *D) {
2291   VisitStmt(D);
2292   // The NumClauses field was read in ReadStmtFromStream.
2293   Record.skipInts(1);
2294   VisitOMPExecutableDirective(D);
2295 }
2296 
2297 void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) {
2298   VisitStmt(D);
2299   VisitOMPExecutableDirective(D);
2300   D->setHasCancel(Record.readBool());
2301 }
2302 
2303 void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) {
2304   VisitOMPLoopDirective(D);
2305 }
2306 
2307 void ASTStmtReader::VisitOMPLoopTransformationDirective(
2308     OMPLoopTransformationDirective *D) {
2309   VisitOMPLoopBasedDirective(D);
2310   D->setNumGeneratedLoops(Record.readUInt32());
2311 }
2312 
2313 void ASTStmtReader::VisitOMPTileDirective(OMPTileDirective *D) {
2314   VisitOMPLoopTransformationDirective(D);
2315 }
2316 
2317 void ASTStmtReader::VisitOMPUnrollDirective(OMPUnrollDirective *D) {
2318   VisitOMPLoopTransformationDirective(D);
2319 }
2320 
2321 void ASTStmtReader::VisitOMPForDirective(OMPForDirective *D) {
2322   VisitOMPLoopDirective(D);
2323   D->setHasCancel(Record.readBool());
2324 }
2325 
2326 void ASTStmtReader::VisitOMPForSimdDirective(OMPForSimdDirective *D) {
2327   VisitOMPLoopDirective(D);
2328 }
2329 
2330 void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) {
2331   VisitStmt(D);
2332   VisitOMPExecutableDirective(D);
2333   D->setHasCancel(Record.readBool());
2334 }
2335 
2336 void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) {
2337   VisitStmt(D);
2338   VisitOMPExecutableDirective(D);
2339   D->setHasCancel(Record.readBool());
2340 }
2341 
2342 void ASTStmtReader::VisitOMPSingleDirective(OMPSingleDirective *D) {
2343   VisitStmt(D);
2344   VisitOMPExecutableDirective(D);
2345 }
2346 
2347 void ASTStmtReader::VisitOMPMasterDirective(OMPMasterDirective *D) {
2348   VisitStmt(D);
2349   VisitOMPExecutableDirective(D);
2350 }
2351 
2352 void ASTStmtReader::VisitOMPCriticalDirective(OMPCriticalDirective *D) {
2353   VisitStmt(D);
2354   VisitOMPExecutableDirective(D);
2355   D->DirName = Record.readDeclarationNameInfo();
2356 }
2357 
2358 void ASTStmtReader::VisitOMPParallelForDirective(OMPParallelForDirective *D) {
2359   VisitOMPLoopDirective(D);
2360   D->setHasCancel(Record.readBool());
2361 }
2362 
2363 void ASTStmtReader::VisitOMPParallelForSimdDirective(
2364     OMPParallelForSimdDirective *D) {
2365   VisitOMPLoopDirective(D);
2366 }
2367 
2368 void ASTStmtReader::VisitOMPParallelMasterDirective(
2369     OMPParallelMasterDirective *D) {
2370   VisitStmt(D);
2371   VisitOMPExecutableDirective(D);
2372 }
2373 
2374 void ASTStmtReader::VisitOMPParallelSectionsDirective(
2375     OMPParallelSectionsDirective *D) {
2376   VisitStmt(D);
2377   VisitOMPExecutableDirective(D);
2378   D->setHasCancel(Record.readBool());
2379 }
2380 
2381 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
2382   VisitStmt(D);
2383   VisitOMPExecutableDirective(D);
2384   D->setHasCancel(Record.readBool());
2385 }
2386 
2387 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2388   VisitStmt(D);
2389   VisitOMPExecutableDirective(D);
2390 }
2391 
2392 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2393   VisitStmt(D);
2394   VisitOMPExecutableDirective(D);
2395 }
2396 
2397 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2398   VisitStmt(D);
2399   // The NumClauses field was read in ReadStmtFromStream.
2400   Record.skipInts(1);
2401   VisitOMPExecutableDirective(D);
2402 }
2403 
2404 void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2405   VisitStmt(D);
2406   VisitOMPExecutableDirective(D);
2407 }
2408 
2409 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
2410   VisitStmt(D);
2411   VisitOMPExecutableDirective(D);
2412 }
2413 
2414 void ASTStmtReader::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2415   VisitStmt(D);
2416   VisitOMPExecutableDirective(D);
2417 }
2418 
2419 void ASTStmtReader::VisitOMPScanDirective(OMPScanDirective *D) {
2420   VisitStmt(D);
2421   VisitOMPExecutableDirective(D);
2422 }
2423 
2424 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2425   VisitStmt(D);
2426   VisitOMPExecutableDirective(D);
2427 }
2428 
2429 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2430   VisitStmt(D);
2431   VisitOMPExecutableDirective(D);
2432   D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
2433   D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
2434 }
2435 
2436 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
2437   VisitStmt(D);
2438   VisitOMPExecutableDirective(D);
2439 }
2440 
2441 void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2442   VisitStmt(D);
2443   VisitOMPExecutableDirective(D);
2444 }
2445 
2446 void ASTStmtReader::VisitOMPTargetEnterDataDirective(
2447     OMPTargetEnterDataDirective *D) {
2448   VisitStmt(D);
2449   VisitOMPExecutableDirective(D);
2450 }
2451 
2452 void ASTStmtReader::VisitOMPTargetExitDataDirective(
2453     OMPTargetExitDataDirective *D) {
2454   VisitStmt(D);
2455   VisitOMPExecutableDirective(D);
2456 }
2457 
2458 void ASTStmtReader::VisitOMPTargetParallelDirective(
2459     OMPTargetParallelDirective *D) {
2460   VisitStmt(D);
2461   VisitOMPExecutableDirective(D);
2462   D->setHasCancel(Record.readBool());
2463 }
2464 
2465 void ASTStmtReader::VisitOMPTargetParallelForDirective(
2466     OMPTargetParallelForDirective *D) {
2467   VisitOMPLoopDirective(D);
2468   D->setHasCancel(Record.readBool());
2469 }
2470 
2471 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2472   VisitStmt(D);
2473   VisitOMPExecutableDirective(D);
2474 }
2475 
2476 void ASTStmtReader::VisitOMPCancellationPointDirective(
2477     OMPCancellationPointDirective *D) {
2478   VisitStmt(D);
2479   VisitOMPExecutableDirective(D);
2480   D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2481 }
2482 
2483 void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) {
2484   VisitStmt(D);
2485   VisitOMPExecutableDirective(D);
2486   D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2487 }
2488 
2489 void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2490   VisitOMPLoopDirective(D);
2491   D->setHasCancel(Record.readBool());
2492 }
2493 
2494 void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2495   VisitOMPLoopDirective(D);
2496 }
2497 
2498 void ASTStmtReader::VisitOMPMasterTaskLoopDirective(
2499     OMPMasterTaskLoopDirective *D) {
2500   VisitOMPLoopDirective(D);
2501   D->setHasCancel(Record.readBool());
2502 }
2503 
2504 void ASTStmtReader::VisitOMPMasterTaskLoopSimdDirective(
2505     OMPMasterTaskLoopSimdDirective *D) {
2506   VisitOMPLoopDirective(D);
2507 }
2508 
2509 void ASTStmtReader::VisitOMPParallelMasterTaskLoopDirective(
2510     OMPParallelMasterTaskLoopDirective *D) {
2511   VisitOMPLoopDirective(D);
2512   D->setHasCancel(Record.readBool());
2513 }
2514 
2515 void ASTStmtReader::VisitOMPParallelMasterTaskLoopSimdDirective(
2516     OMPParallelMasterTaskLoopSimdDirective *D) {
2517   VisitOMPLoopDirective(D);
2518 }
2519 
2520 void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2521   VisitOMPLoopDirective(D);
2522 }
2523 
2524 void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2525   VisitStmt(D);
2526   VisitOMPExecutableDirective(D);
2527 }
2528 
2529 void ASTStmtReader::VisitOMPDistributeParallelForDirective(
2530     OMPDistributeParallelForDirective *D) {
2531   VisitOMPLoopDirective(D);
2532   D->setHasCancel(Record.readBool());
2533 }
2534 
2535 void ASTStmtReader::VisitOMPDistributeParallelForSimdDirective(
2536     OMPDistributeParallelForSimdDirective *D) {
2537   VisitOMPLoopDirective(D);
2538 }
2539 
2540 void ASTStmtReader::VisitOMPDistributeSimdDirective(
2541     OMPDistributeSimdDirective *D) {
2542   VisitOMPLoopDirective(D);
2543 }
2544 
2545 void ASTStmtReader::VisitOMPTargetParallelForSimdDirective(
2546     OMPTargetParallelForSimdDirective *D) {
2547   VisitOMPLoopDirective(D);
2548 }
2549 
2550 void ASTStmtReader::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2551   VisitOMPLoopDirective(D);
2552 }
2553 
2554 void ASTStmtReader::VisitOMPTeamsDistributeDirective(
2555     OMPTeamsDistributeDirective *D) {
2556   VisitOMPLoopDirective(D);
2557 }
2558 
2559 void ASTStmtReader::VisitOMPTeamsDistributeSimdDirective(
2560     OMPTeamsDistributeSimdDirective *D) {
2561   VisitOMPLoopDirective(D);
2562 }
2563 
2564 void ASTStmtReader::VisitOMPTeamsDistributeParallelForSimdDirective(
2565     OMPTeamsDistributeParallelForSimdDirective *D) {
2566   VisitOMPLoopDirective(D);
2567 }
2568 
2569 void ASTStmtReader::VisitOMPTeamsDistributeParallelForDirective(
2570     OMPTeamsDistributeParallelForDirective *D) {
2571   VisitOMPLoopDirective(D);
2572   D->setHasCancel(Record.readBool());
2573 }
2574 
2575 void ASTStmtReader::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2576   VisitStmt(D);
2577   VisitOMPExecutableDirective(D);
2578 }
2579 
2580 void ASTStmtReader::VisitOMPTargetTeamsDistributeDirective(
2581     OMPTargetTeamsDistributeDirective *D) {
2582   VisitOMPLoopDirective(D);
2583 }
2584 
2585 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForDirective(
2586     OMPTargetTeamsDistributeParallelForDirective *D) {
2587   VisitOMPLoopDirective(D);
2588   D->setHasCancel(Record.readBool());
2589 }
2590 
2591 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2592     OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2593   VisitOMPLoopDirective(D);
2594 }
2595 
2596 void ASTStmtReader::VisitOMPTargetTeamsDistributeSimdDirective(
2597     OMPTargetTeamsDistributeSimdDirective *D) {
2598   VisitOMPLoopDirective(D);
2599 }
2600 
2601 void ASTStmtReader::VisitOMPInteropDirective(OMPInteropDirective *D) {
2602   VisitStmt(D);
2603   VisitOMPExecutableDirective(D);
2604 }
2605 
2606 void ASTStmtReader::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2607   VisitStmt(D);
2608   VisitOMPExecutableDirective(D);
2609   D->setTargetCallLoc(Record.readSourceLocation());
2610 }
2611 
2612 void ASTStmtReader::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2613   VisitStmt(D);
2614   VisitOMPExecutableDirective(D);
2615 }
2616 
2617 void ASTStmtReader::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2618   VisitOMPLoopDirective(D);
2619 }
2620 
2621 void ASTStmtReader::VisitOMPTeamsGenericLoopDirective(
2622     OMPTeamsGenericLoopDirective *D) {
2623   VisitOMPLoopDirective(D);
2624 }
2625 
2626 void ASTStmtReader::VisitOMPTargetTeamsGenericLoopDirective(
2627     OMPTargetTeamsGenericLoopDirective *D) {
2628   VisitOMPLoopDirective(D);
2629 }
2630 
2631 void ASTStmtReader::VisitOMPParallelGenericLoopDirective(
2632     OMPParallelGenericLoopDirective *D) {
2633   VisitOMPLoopDirective(D);
2634 }
2635 
2636 void ASTStmtReader::VisitOMPTargetParallelGenericLoopDirective(
2637     OMPTargetParallelGenericLoopDirective *D) {
2638   VisitOMPLoopDirective(D);
2639 }
2640 
2641 //===----------------------------------------------------------------------===//
2642 // ASTReader Implementation
2643 //===----------------------------------------------------------------------===//
2644 
2645 Stmt *ASTReader::ReadStmt(ModuleFile &F) {
2646   switch (ReadingKind) {
2647   case Read_None:
2648     llvm_unreachable("should not call this when not reading anything");
2649   case Read_Decl:
2650   case Read_Type:
2651     return ReadStmtFromStream(F);
2652   case Read_Stmt:
2653     return ReadSubStmt();
2654   }
2655 
2656   llvm_unreachable("ReadingKind not set ?");
2657 }
2658 
2659 Expr *ASTReader::ReadExpr(ModuleFile &F) {
2660   return cast_or_null<Expr>(ReadStmt(F));
2661 }
2662 
2663 Expr *ASTReader::ReadSubExpr() {
2664   return cast_or_null<Expr>(ReadSubStmt());
2665 }
2666 
2667 // Within the bitstream, expressions are stored in Reverse Polish
2668 // Notation, with each of the subexpressions preceding the
2669 // expression they are stored in. Subexpressions are stored from last to first.
2670 // To evaluate expressions, we continue reading expressions and placing them on
2671 // the stack, with expressions having operands removing those operands from the
2672 // stack. Evaluation terminates when we see a STMT_STOP record, and
2673 // the single remaining expression on the stack is our result.
2674 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
2675   ReadingKindTracker ReadingKind(Read_Stmt, *this);
2676   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
2677 
2678   // Map of offset to previously deserialized stmt. The offset points
2679   // just after the stmt record.
2680   llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
2681 
2682 #ifndef NDEBUG
2683   unsigned PrevNumStmts = StmtStack.size();
2684 #endif
2685 
2686   ASTRecordReader Record(*this, F);
2687   ASTStmtReader Reader(Record, Cursor);
2688   Stmt::EmptyShell Empty;
2689 
2690   while (true) {
2691     llvm::Expected<llvm::BitstreamEntry> MaybeEntry =
2692         Cursor.advanceSkippingSubblocks();
2693     if (!MaybeEntry) {
2694       Error(toString(MaybeEntry.takeError()));
2695       return nullptr;
2696     }
2697     llvm::BitstreamEntry Entry = MaybeEntry.get();
2698 
2699     switch (Entry.Kind) {
2700     case llvm::BitstreamEntry::SubBlock: // Handled for us already.
2701     case llvm::BitstreamEntry::Error:
2702       Error("malformed block record in AST file");
2703       return nullptr;
2704     case llvm::BitstreamEntry::EndBlock:
2705       goto Done;
2706     case llvm::BitstreamEntry::Record:
2707       // The interesting case.
2708       break;
2709     }
2710 
2711     ASTContext &Context = getContext();
2712     Stmt *S = nullptr;
2713     bool Finished = false;
2714     bool IsStmtReference = false;
2715     Expected<unsigned> MaybeStmtCode = Record.readRecord(Cursor, Entry.ID);
2716     if (!MaybeStmtCode) {
2717       Error(toString(MaybeStmtCode.takeError()));
2718       return nullptr;
2719     }
2720     switch ((StmtCode)MaybeStmtCode.get()) {
2721     case STMT_STOP:
2722       Finished = true;
2723       break;
2724 
2725     case STMT_REF_PTR:
2726       IsStmtReference = true;
2727       assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
2728              "No stmt was recorded for this offset reference!");
2729       S = StmtEntries[Record.readInt()];
2730       break;
2731 
2732     case STMT_NULL_PTR:
2733       S = nullptr;
2734       break;
2735 
2736     case STMT_NULL:
2737       S = new (Context) NullStmt(Empty);
2738       break;
2739 
2740     case STMT_COMPOUND:
2741       S = CompoundStmt::CreateEmpty(
2742           Context, /*NumStmts=*/Record[ASTStmtReader::NumStmtFields]);
2743       break;
2744 
2745     case STMT_CASE:
2746       S = CaseStmt::CreateEmpty(
2747           Context,
2748           /*CaseStmtIsGNURange*/ Record[ASTStmtReader::NumStmtFields + 3]);
2749       break;
2750 
2751     case STMT_DEFAULT:
2752       S = new (Context) DefaultStmt(Empty);
2753       break;
2754 
2755     case STMT_LABEL:
2756       S = new (Context) LabelStmt(Empty);
2757       break;
2758 
2759     case STMT_ATTRIBUTED:
2760       S = AttributedStmt::CreateEmpty(
2761         Context,
2762         /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
2763       break;
2764 
2765     case STMT_IF:
2766       S = IfStmt::CreateEmpty(
2767           Context,
2768           /* HasElse=*/Record[ASTStmtReader::NumStmtFields],
2769           /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1],
2770           /* HasInit=*/Record[ASTStmtReader::NumStmtFields + 2]);
2771       break;
2772 
2773     case STMT_SWITCH:
2774       S = SwitchStmt::CreateEmpty(
2775           Context,
2776           /* HasInit=*/Record[ASTStmtReader::NumStmtFields],
2777           /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1]);
2778       break;
2779 
2780     case STMT_WHILE:
2781       S = WhileStmt::CreateEmpty(
2782           Context,
2783           /* HasVar=*/Record[ASTStmtReader::NumStmtFields]);
2784       break;
2785 
2786     case STMT_DO:
2787       S = new (Context) DoStmt(Empty);
2788       break;
2789 
2790     case STMT_FOR:
2791       S = new (Context) ForStmt(Empty);
2792       break;
2793 
2794     case STMT_GOTO:
2795       S = new (Context) GotoStmt(Empty);
2796       break;
2797 
2798     case STMT_INDIRECT_GOTO:
2799       S = new (Context) IndirectGotoStmt(Empty);
2800       break;
2801 
2802     case STMT_CONTINUE:
2803       S = new (Context) ContinueStmt(Empty);
2804       break;
2805 
2806     case STMT_BREAK:
2807       S = new (Context) BreakStmt(Empty);
2808       break;
2809 
2810     case STMT_RETURN:
2811       S = ReturnStmt::CreateEmpty(
2812           Context, /* HasNRVOCandidate=*/Record[ASTStmtReader::NumStmtFields]);
2813       break;
2814 
2815     case STMT_DECL:
2816       S = new (Context) DeclStmt(Empty);
2817       break;
2818 
2819     case STMT_GCCASM:
2820       S = new (Context) GCCAsmStmt(Empty);
2821       break;
2822 
2823     case STMT_MSASM:
2824       S = new (Context) MSAsmStmt(Empty);
2825       break;
2826 
2827     case STMT_CAPTURED:
2828       S = CapturedStmt::CreateDeserialized(
2829           Context, Record[ASTStmtReader::NumStmtFields]);
2830       break;
2831 
2832     case EXPR_CONSTANT:
2833       S = ConstantExpr::CreateEmpty(
2834           Context, static_cast<ConstantExpr::ResultStorageKind>(
2835                        /*StorageKind=*/Record[ASTStmtReader::NumExprFields]));
2836       break;
2837 
2838     case EXPR_SYCL_UNIQUE_STABLE_NAME:
2839       S = SYCLUniqueStableNameExpr::CreateEmpty(Context);
2840       break;
2841 
2842     case EXPR_PREDEFINED:
2843       S = PredefinedExpr::CreateEmpty(
2844           Context,
2845           /*HasFunctionName*/ Record[ASTStmtReader::NumExprFields]);
2846       break;
2847 
2848     case EXPR_DECL_REF:
2849       S = DeclRefExpr::CreateEmpty(
2850         Context,
2851         /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
2852         /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
2853         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
2854         /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
2855           Record[ASTStmtReader::NumExprFields + 6] : 0);
2856       break;
2857 
2858     case EXPR_INTEGER_LITERAL:
2859       S = IntegerLiteral::Create(Context, Empty);
2860       break;
2861 
2862     case EXPR_FIXEDPOINT_LITERAL:
2863       S = FixedPointLiteral::Create(Context, Empty);
2864       break;
2865 
2866     case EXPR_FLOATING_LITERAL:
2867       S = FloatingLiteral::Create(Context, Empty);
2868       break;
2869 
2870     case EXPR_IMAGINARY_LITERAL:
2871       S = new (Context) ImaginaryLiteral(Empty);
2872       break;
2873 
2874     case EXPR_STRING_LITERAL:
2875       S = StringLiteral::CreateEmpty(
2876           Context,
2877           /* NumConcatenated=*/Record[ASTStmtReader::NumExprFields],
2878           /* Length=*/Record[ASTStmtReader::NumExprFields + 1],
2879           /* CharByteWidth=*/Record[ASTStmtReader::NumExprFields + 2]);
2880       break;
2881 
2882     case EXPR_CHARACTER_LITERAL:
2883       S = new (Context) CharacterLiteral(Empty);
2884       break;
2885 
2886     case EXPR_PAREN:
2887       S = new (Context) ParenExpr(Empty);
2888       break;
2889 
2890     case EXPR_PAREN_LIST:
2891       S = ParenListExpr::CreateEmpty(
2892           Context,
2893           /* NumExprs=*/Record[ASTStmtReader::NumExprFields]);
2894       break;
2895 
2896     case EXPR_UNARY_OPERATOR:
2897       S = UnaryOperator::CreateEmpty(Context,
2898                                      Record[ASTStmtReader::NumExprFields]);
2899       break;
2900 
2901     case EXPR_OFFSETOF:
2902       S = OffsetOfExpr::CreateEmpty(Context,
2903                                     Record[ASTStmtReader::NumExprFields],
2904                                     Record[ASTStmtReader::NumExprFields + 1]);
2905       break;
2906 
2907     case EXPR_SIZEOF_ALIGN_OF:
2908       S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
2909       break;
2910 
2911     case EXPR_ARRAY_SUBSCRIPT:
2912       S = new (Context) ArraySubscriptExpr(Empty);
2913       break;
2914 
2915     case EXPR_MATRIX_SUBSCRIPT:
2916       S = new (Context) MatrixSubscriptExpr(Empty);
2917       break;
2918 
2919     case EXPR_OMP_ARRAY_SECTION:
2920       S = new (Context) OMPArraySectionExpr(Empty);
2921       break;
2922 
2923     case EXPR_OMP_ARRAY_SHAPING:
2924       S = OMPArrayShapingExpr::CreateEmpty(
2925           Context, Record[ASTStmtReader::NumExprFields]);
2926       break;
2927 
2928     case EXPR_OMP_ITERATOR:
2929       S = OMPIteratorExpr::CreateEmpty(Context,
2930                                        Record[ASTStmtReader::NumExprFields]);
2931       break;
2932 
2933     case EXPR_CALL:
2934       S = CallExpr::CreateEmpty(
2935           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
2936           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
2937       break;
2938 
2939     case EXPR_RECOVERY:
2940       S = RecoveryExpr::CreateEmpty(
2941           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
2942       break;
2943 
2944     case EXPR_MEMBER:
2945       S = MemberExpr::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields],
2946                                   Record[ASTStmtReader::NumExprFields + 1],
2947                                   Record[ASTStmtReader::NumExprFields + 2],
2948                                   Record[ASTStmtReader::NumExprFields + 3]);
2949       break;
2950 
2951     case EXPR_BINARY_OPERATOR:
2952       S = BinaryOperator::CreateEmpty(Context,
2953                                       Record[ASTStmtReader::NumExprFields]);
2954       break;
2955 
2956     case EXPR_COMPOUND_ASSIGN_OPERATOR:
2957       S = CompoundAssignOperator::CreateEmpty(
2958           Context, Record[ASTStmtReader::NumExprFields]);
2959       break;
2960 
2961     case EXPR_CONDITIONAL_OPERATOR:
2962       S = new (Context) ConditionalOperator(Empty);
2963       break;
2964 
2965     case EXPR_BINARY_CONDITIONAL_OPERATOR:
2966       S = new (Context) BinaryConditionalOperator(Empty);
2967       break;
2968 
2969     case EXPR_IMPLICIT_CAST:
2970       S = ImplicitCastExpr::CreateEmpty(
2971           Context,
2972           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
2973           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
2974       break;
2975 
2976     case EXPR_CSTYLE_CAST:
2977       S = CStyleCastExpr::CreateEmpty(
2978           Context,
2979           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
2980           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
2981       break;
2982 
2983     case EXPR_COMPOUND_LITERAL:
2984       S = new (Context) CompoundLiteralExpr(Empty);
2985       break;
2986 
2987     case EXPR_EXT_VECTOR_ELEMENT:
2988       S = new (Context) ExtVectorElementExpr(Empty);
2989       break;
2990 
2991     case EXPR_INIT_LIST:
2992       S = new (Context) InitListExpr(Empty);
2993       break;
2994 
2995     case EXPR_DESIGNATED_INIT:
2996       S = DesignatedInitExpr::CreateEmpty(Context,
2997                                      Record[ASTStmtReader::NumExprFields] - 1);
2998 
2999       break;
3000 
3001     case EXPR_DESIGNATED_INIT_UPDATE:
3002       S = new (Context) DesignatedInitUpdateExpr(Empty);
3003       break;
3004 
3005     case EXPR_IMPLICIT_VALUE_INIT:
3006       S = new (Context) ImplicitValueInitExpr(Empty);
3007       break;
3008 
3009     case EXPR_NO_INIT:
3010       S = new (Context) NoInitExpr(Empty);
3011       break;
3012 
3013     case EXPR_ARRAY_INIT_LOOP:
3014       S = new (Context) ArrayInitLoopExpr(Empty);
3015       break;
3016 
3017     case EXPR_ARRAY_INIT_INDEX:
3018       S = new (Context) ArrayInitIndexExpr(Empty);
3019       break;
3020 
3021     case EXPR_VA_ARG:
3022       S = new (Context) VAArgExpr(Empty);
3023       break;
3024 
3025     case EXPR_SOURCE_LOC:
3026       S = new (Context) SourceLocExpr(Empty);
3027       break;
3028 
3029     case EXPR_ADDR_LABEL:
3030       S = new (Context) AddrLabelExpr(Empty);
3031       break;
3032 
3033     case EXPR_STMT:
3034       S = new (Context) StmtExpr(Empty);
3035       break;
3036 
3037     case EXPR_CHOOSE:
3038       S = new (Context) ChooseExpr(Empty);
3039       break;
3040 
3041     case EXPR_GNU_NULL:
3042       S = new (Context) GNUNullExpr(Empty);
3043       break;
3044 
3045     case EXPR_SHUFFLE_VECTOR:
3046       S = new (Context) ShuffleVectorExpr(Empty);
3047       break;
3048 
3049     case EXPR_CONVERT_VECTOR:
3050       S = new (Context) ConvertVectorExpr(Empty);
3051       break;
3052 
3053     case EXPR_BLOCK:
3054       S = new (Context) BlockExpr(Empty);
3055       break;
3056 
3057     case EXPR_GENERIC_SELECTION:
3058       S = GenericSelectionExpr::CreateEmpty(
3059           Context,
3060           /*NumAssocs=*/Record[ASTStmtReader::NumExprFields]);
3061       break;
3062 
3063     case EXPR_OBJC_STRING_LITERAL:
3064       S = new (Context) ObjCStringLiteral(Empty);
3065       break;
3066 
3067     case EXPR_OBJC_BOXED_EXPRESSION:
3068       S = new (Context) ObjCBoxedExpr(Empty);
3069       break;
3070 
3071     case EXPR_OBJC_ARRAY_LITERAL:
3072       S = ObjCArrayLiteral::CreateEmpty(Context,
3073                                         Record[ASTStmtReader::NumExprFields]);
3074       break;
3075 
3076     case EXPR_OBJC_DICTIONARY_LITERAL:
3077       S = ObjCDictionaryLiteral::CreateEmpty(Context,
3078             Record[ASTStmtReader::NumExprFields],
3079             Record[ASTStmtReader::NumExprFields + 1]);
3080       break;
3081 
3082     case EXPR_OBJC_ENCODE:
3083       S = new (Context) ObjCEncodeExpr(Empty);
3084       break;
3085 
3086     case EXPR_OBJC_SELECTOR_EXPR:
3087       S = new (Context) ObjCSelectorExpr(Empty);
3088       break;
3089 
3090     case EXPR_OBJC_PROTOCOL_EXPR:
3091       S = new (Context) ObjCProtocolExpr(Empty);
3092       break;
3093 
3094     case EXPR_OBJC_IVAR_REF_EXPR:
3095       S = new (Context) ObjCIvarRefExpr(Empty);
3096       break;
3097 
3098     case EXPR_OBJC_PROPERTY_REF_EXPR:
3099       S = new (Context) ObjCPropertyRefExpr(Empty);
3100       break;
3101 
3102     case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
3103       S = new (Context) ObjCSubscriptRefExpr(Empty);
3104       break;
3105 
3106     case EXPR_OBJC_KVC_REF_EXPR:
3107       llvm_unreachable("mismatching AST file");
3108 
3109     case EXPR_OBJC_MESSAGE_EXPR:
3110       S = ObjCMessageExpr::CreateEmpty(Context,
3111                                      Record[ASTStmtReader::NumExprFields],
3112                                      Record[ASTStmtReader::NumExprFields + 1]);
3113       break;
3114 
3115     case EXPR_OBJC_ISA:
3116       S = new (Context) ObjCIsaExpr(Empty);
3117       break;
3118 
3119     case EXPR_OBJC_INDIRECT_COPY_RESTORE:
3120       S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
3121       break;
3122 
3123     case EXPR_OBJC_BRIDGED_CAST:
3124       S = new (Context) ObjCBridgedCastExpr(Empty);
3125       break;
3126 
3127     case STMT_OBJC_FOR_COLLECTION:
3128       S = new (Context) ObjCForCollectionStmt(Empty);
3129       break;
3130 
3131     case STMT_OBJC_CATCH:
3132       S = new (Context) ObjCAtCatchStmt(Empty);
3133       break;
3134 
3135     case STMT_OBJC_FINALLY:
3136       S = new (Context) ObjCAtFinallyStmt(Empty);
3137       break;
3138 
3139     case STMT_OBJC_AT_TRY:
3140       S = ObjCAtTryStmt::CreateEmpty(Context,
3141                                      Record[ASTStmtReader::NumStmtFields],
3142                                      Record[ASTStmtReader::NumStmtFields + 1]);
3143       break;
3144 
3145     case STMT_OBJC_AT_SYNCHRONIZED:
3146       S = new (Context) ObjCAtSynchronizedStmt(Empty);
3147       break;
3148 
3149     case STMT_OBJC_AT_THROW:
3150       S = new (Context) ObjCAtThrowStmt(Empty);
3151       break;
3152 
3153     case STMT_OBJC_AUTORELEASE_POOL:
3154       S = new (Context) ObjCAutoreleasePoolStmt(Empty);
3155       break;
3156 
3157     case EXPR_OBJC_BOOL_LITERAL:
3158       S = new (Context) ObjCBoolLiteralExpr(Empty);
3159       break;
3160 
3161     case EXPR_OBJC_AVAILABILITY_CHECK:
3162       S = new (Context) ObjCAvailabilityCheckExpr(Empty);
3163       break;
3164 
3165     case STMT_SEH_LEAVE:
3166       S = new (Context) SEHLeaveStmt(Empty);
3167       break;
3168 
3169     case STMT_SEH_EXCEPT:
3170       S = new (Context) SEHExceptStmt(Empty);
3171       break;
3172 
3173     case STMT_SEH_FINALLY:
3174       S = new (Context) SEHFinallyStmt(Empty);
3175       break;
3176 
3177     case STMT_SEH_TRY:
3178       S = new (Context) SEHTryStmt(Empty);
3179       break;
3180 
3181     case STMT_CXX_CATCH:
3182       S = new (Context) CXXCatchStmt(Empty);
3183       break;
3184 
3185     case STMT_CXX_TRY:
3186       S = CXXTryStmt::Create(Context, Empty,
3187              /*numHandlers=*/Record[ASTStmtReader::NumStmtFields]);
3188       break;
3189 
3190     case STMT_CXX_FOR_RANGE:
3191       S = new (Context) CXXForRangeStmt(Empty);
3192       break;
3193 
3194     case STMT_MS_DEPENDENT_EXISTS:
3195       S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
3196                                               NestedNameSpecifierLoc(),
3197                                               DeclarationNameInfo(),
3198                                               nullptr);
3199       break;
3200 
3201     case STMT_OMP_CANONICAL_LOOP:
3202       S = OMPCanonicalLoop::createEmpty(Context);
3203       break;
3204 
3205     case STMT_OMP_META_DIRECTIVE:
3206       S = OMPMetaDirective::CreateEmpty(
3207           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3208       break;
3209 
3210     case STMT_OMP_PARALLEL_DIRECTIVE:
3211       S =
3212         OMPParallelDirective::CreateEmpty(Context,
3213                                           Record[ASTStmtReader::NumStmtFields],
3214                                           Empty);
3215       break;
3216 
3217     case STMT_OMP_SIMD_DIRECTIVE: {
3218       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3219       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3220       S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
3221                                         CollapsedNum, Empty);
3222       break;
3223     }
3224 
3225     case STMT_OMP_TILE_DIRECTIVE: {
3226       unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
3227       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3228       S = OMPTileDirective::CreateEmpty(Context, NumClauses, NumLoops);
3229       break;
3230     }
3231 
3232     case STMT_OMP_UNROLL_DIRECTIVE: {
3233       assert(Record[ASTStmtReader::NumStmtFields] == 1 && "Unroll directive accepts only a single loop");
3234       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3235       S = OMPUnrollDirective::CreateEmpty(Context, NumClauses);
3236       break;
3237     }
3238 
3239     case STMT_OMP_FOR_DIRECTIVE: {
3240       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3241       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3242       S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3243                                        Empty);
3244       break;
3245     }
3246 
3247     case STMT_OMP_FOR_SIMD_DIRECTIVE: {
3248       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3249       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3250       S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3251                                            Empty);
3252       break;
3253     }
3254 
3255     case STMT_OMP_SECTIONS_DIRECTIVE:
3256       S = OMPSectionsDirective::CreateEmpty(
3257           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3258       break;
3259 
3260     case STMT_OMP_SECTION_DIRECTIVE:
3261       S = OMPSectionDirective::CreateEmpty(Context, Empty);
3262       break;
3263 
3264     case STMT_OMP_SINGLE_DIRECTIVE:
3265       S = OMPSingleDirective::CreateEmpty(
3266           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3267       break;
3268 
3269     case STMT_OMP_MASTER_DIRECTIVE:
3270       S = OMPMasterDirective::CreateEmpty(Context, Empty);
3271       break;
3272 
3273     case STMT_OMP_CRITICAL_DIRECTIVE:
3274       S = OMPCriticalDirective::CreateEmpty(
3275           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3276       break;
3277 
3278     case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
3279       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3280       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3281       S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
3282                                                CollapsedNum, Empty);
3283       break;
3284     }
3285 
3286     case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
3287       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3288       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3289       S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3290                                                    CollapsedNum, Empty);
3291       break;
3292     }
3293 
3294     case STMT_OMP_PARALLEL_MASTER_DIRECTIVE:
3295       S = OMPParallelMasterDirective::CreateEmpty(
3296           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3297       break;
3298 
3299     case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
3300       S = OMPParallelSectionsDirective::CreateEmpty(
3301           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3302       break;
3303 
3304     case STMT_OMP_TASK_DIRECTIVE:
3305       S = OMPTaskDirective::CreateEmpty(
3306           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3307       break;
3308 
3309     case STMT_OMP_TASKYIELD_DIRECTIVE:
3310       S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
3311       break;
3312 
3313     case STMT_OMP_BARRIER_DIRECTIVE:
3314       S = OMPBarrierDirective::CreateEmpty(Context, Empty);
3315       break;
3316 
3317     case STMT_OMP_TASKWAIT_DIRECTIVE:
3318       S = OMPTaskwaitDirective::CreateEmpty(
3319           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3320       break;
3321 
3322     case STMT_OMP_TASKGROUP_DIRECTIVE:
3323       S = OMPTaskgroupDirective::CreateEmpty(
3324           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3325       break;
3326 
3327     case STMT_OMP_FLUSH_DIRECTIVE:
3328       S = OMPFlushDirective::CreateEmpty(
3329           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3330       break;
3331 
3332     case STMT_OMP_DEPOBJ_DIRECTIVE:
3333       S = OMPDepobjDirective::CreateEmpty(
3334           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3335       break;
3336 
3337     case STMT_OMP_SCAN_DIRECTIVE:
3338       S = OMPScanDirective::CreateEmpty(
3339           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3340       break;
3341 
3342     case STMT_OMP_ORDERED_DIRECTIVE: {
3343       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
3344       bool HasAssociatedStmt = Record[ASTStmtReader::NumStmtFields + 2];
3345       S = OMPOrderedDirective::CreateEmpty(Context, NumClauses,
3346                                            !HasAssociatedStmt, Empty);
3347       break;
3348     }
3349 
3350     case STMT_OMP_ATOMIC_DIRECTIVE:
3351       S = OMPAtomicDirective::CreateEmpty(
3352           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3353       break;
3354 
3355     case STMT_OMP_TARGET_DIRECTIVE:
3356       S = OMPTargetDirective::CreateEmpty(
3357           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3358       break;
3359 
3360     case STMT_OMP_TARGET_DATA_DIRECTIVE:
3361       S = OMPTargetDataDirective::CreateEmpty(
3362           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3363       break;
3364 
3365     case STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE:
3366       S = OMPTargetEnterDataDirective::CreateEmpty(
3367           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3368       break;
3369 
3370     case STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE:
3371       S = OMPTargetExitDataDirective::CreateEmpty(
3372           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3373       break;
3374 
3375     case STMT_OMP_TARGET_PARALLEL_DIRECTIVE:
3376       S = OMPTargetParallelDirective::CreateEmpty(
3377           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3378       break;
3379 
3380     case STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE: {
3381       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3382       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3383       S = OMPTargetParallelForDirective::CreateEmpty(Context, NumClauses,
3384                                                      CollapsedNum, Empty);
3385       break;
3386     }
3387 
3388     case STMT_OMP_TARGET_UPDATE_DIRECTIVE:
3389       S = OMPTargetUpdateDirective::CreateEmpty(
3390           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3391       break;
3392 
3393     case STMT_OMP_TEAMS_DIRECTIVE:
3394       S = OMPTeamsDirective::CreateEmpty(
3395           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3396       break;
3397 
3398     case STMT_OMP_CANCELLATION_POINT_DIRECTIVE:
3399       S = OMPCancellationPointDirective::CreateEmpty(Context, Empty);
3400       break;
3401 
3402     case STMT_OMP_CANCEL_DIRECTIVE:
3403       S = OMPCancelDirective::CreateEmpty(
3404           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3405       break;
3406 
3407     case STMT_OMP_TASKLOOP_DIRECTIVE: {
3408       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3409       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3410       S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3411                                             Empty);
3412       break;
3413     }
3414 
3415     case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: {
3416       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3417       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3418       S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3419                                                 CollapsedNum, Empty);
3420       break;
3421     }
3422 
3423     case STMT_OMP_MASTER_TASKLOOP_DIRECTIVE: {
3424       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3425       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3426       S = OMPMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3427                                                   CollapsedNum, Empty);
3428       break;
3429     }
3430 
3431     case STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3432       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3433       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3434       S = OMPMasterTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3435                                                       CollapsedNum, Empty);
3436       break;
3437     }
3438 
3439     case STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE: {
3440       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3441       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3442       S = OMPParallelMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3443                                                           CollapsedNum, Empty);
3444       break;
3445     }
3446 
3447     case STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3448       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3449       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3450       S = OMPParallelMasterTaskLoopSimdDirective::CreateEmpty(
3451           Context, NumClauses, CollapsedNum, Empty);
3452       break;
3453     }
3454 
3455     case STMT_OMP_DISTRIBUTE_DIRECTIVE: {
3456       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3457       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3458       S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3459                                               Empty);
3460       break;
3461     }
3462 
3463     case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3464       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3465       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3466       S = OMPDistributeParallelForDirective::CreateEmpty(Context, NumClauses,
3467                                                          CollapsedNum, Empty);
3468       break;
3469     }
3470 
3471     case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3472       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3473       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3474       S = OMPDistributeParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3475                                                              CollapsedNum,
3476                                                              Empty);
3477       break;
3478     }
3479 
3480     case STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE: {
3481       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3482       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3483       S = OMPDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3484                                                   CollapsedNum, Empty);
3485       break;
3486     }
3487 
3488     case STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE: {
3489       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3490       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3491       S = OMPTargetParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3492                                                          CollapsedNum, Empty);
3493       break;
3494     }
3495 
3496     case STMT_OMP_TARGET_SIMD_DIRECTIVE: {
3497       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3498       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3499       S = OMPTargetSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3500                                               Empty);
3501       break;
3502     }
3503 
3504      case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: {
3505        unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3506        unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3507        S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3508                                                     CollapsedNum, Empty);
3509        break;
3510     }
3511 
3512     case STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3513       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3514       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3515       S = OMPTeamsDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3516                                                        CollapsedNum, Empty);
3517       break;
3518     }
3519 
3520     case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3521       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3522       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3523       S = OMPTeamsDistributeParallelForSimdDirective::CreateEmpty(
3524           Context, NumClauses, CollapsedNum, Empty);
3525       break;
3526     }
3527 
3528     case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3529       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3530       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3531       S = OMPTeamsDistributeParallelForDirective::CreateEmpty(
3532           Context, NumClauses, CollapsedNum, Empty);
3533       break;
3534     }
3535 
3536     case STMT_OMP_TARGET_TEAMS_DIRECTIVE:
3537       S = OMPTargetTeamsDirective::CreateEmpty(
3538           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3539       break;
3540 
3541     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: {
3542       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3543       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3544       S = OMPTargetTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3545                                                          CollapsedNum, Empty);
3546       break;
3547     }
3548 
3549     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3550       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3551       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3552       S = OMPTargetTeamsDistributeParallelForDirective::CreateEmpty(
3553           Context, NumClauses, CollapsedNum, Empty);
3554       break;
3555     }
3556 
3557     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3558       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3559       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3560       S = OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty(
3561           Context, NumClauses, CollapsedNum, Empty);
3562       break;
3563     }
3564 
3565     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3566       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3567       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3568       S = OMPTargetTeamsDistributeSimdDirective::CreateEmpty(
3569           Context, NumClauses, CollapsedNum, Empty);
3570       break;
3571     }
3572 
3573     case STMT_OMP_INTEROP_DIRECTIVE:
3574       S = OMPInteropDirective::CreateEmpty(
3575           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3576       break;
3577 
3578     case STMT_OMP_DISPATCH_DIRECTIVE:
3579       S = OMPDispatchDirective::CreateEmpty(
3580           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3581       break;
3582 
3583     case STMT_OMP_MASKED_DIRECTIVE:
3584       S = OMPMaskedDirective::CreateEmpty(
3585           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3586       break;
3587 
3588     case STMT_OMP_GENERIC_LOOP_DIRECTIVE: {
3589       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3590       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3591       S = OMPGenericLoopDirective::CreateEmpty(Context, NumClauses,
3592                                                CollapsedNum, Empty);
3593       break;
3594     }
3595 
3596     case STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3597       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3598       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3599       S = OMPTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3600                                                     CollapsedNum, Empty);
3601       break;
3602     }
3603 
3604     case STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3605       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3606       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3607       S = OMPTargetTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3608                                                           CollapsedNum, Empty);
3609       break;
3610     }
3611 
3612     case STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3613       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3614       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3615       S = OMPParallelGenericLoopDirective::CreateEmpty(Context, NumClauses,
3616                                                        CollapsedNum, Empty);
3617       break;
3618     }
3619 
3620     case STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3621       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3622       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3623       S = OMPTargetParallelGenericLoopDirective::CreateEmpty(
3624           Context, NumClauses, CollapsedNum, Empty);
3625       break;
3626     }
3627 
3628     case EXPR_CXX_OPERATOR_CALL:
3629       S = CXXOperatorCallExpr::CreateEmpty(
3630           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3631           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3632       break;
3633 
3634     case EXPR_CXX_MEMBER_CALL:
3635       S = CXXMemberCallExpr::CreateEmpty(
3636           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3637           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3638       break;
3639 
3640     case EXPR_CXX_REWRITTEN_BINARY_OPERATOR:
3641       S = new (Context) CXXRewrittenBinaryOperator(Empty);
3642       break;
3643 
3644     case EXPR_CXX_CONSTRUCT:
3645       S = CXXConstructExpr::CreateEmpty(
3646           Context,
3647           /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3648       break;
3649 
3650     case EXPR_CXX_INHERITED_CTOR_INIT:
3651       S = new (Context) CXXInheritedCtorInitExpr(Empty);
3652       break;
3653 
3654     case EXPR_CXX_TEMPORARY_OBJECT:
3655       S = CXXTemporaryObjectExpr::CreateEmpty(
3656           Context,
3657           /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3658       break;
3659 
3660     case EXPR_CXX_STATIC_CAST:
3661       S = CXXStaticCastExpr::CreateEmpty(
3662           Context,
3663           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
3664           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
3665       break;
3666 
3667     case EXPR_CXX_DYNAMIC_CAST:
3668       S = CXXDynamicCastExpr::CreateEmpty(Context,
3669                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
3670       break;
3671 
3672     case EXPR_CXX_REINTERPRET_CAST:
3673       S = CXXReinterpretCastExpr::CreateEmpty(Context,
3674                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
3675       break;
3676 
3677     case EXPR_CXX_CONST_CAST:
3678       S = CXXConstCastExpr::CreateEmpty(Context);
3679       break;
3680 
3681     case EXPR_CXX_ADDRSPACE_CAST:
3682       S = CXXAddrspaceCastExpr::CreateEmpty(Context);
3683       break;
3684 
3685     case EXPR_CXX_FUNCTIONAL_CAST:
3686       S = CXXFunctionalCastExpr::CreateEmpty(
3687           Context,
3688           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
3689           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
3690       break;
3691 
3692     case EXPR_BUILTIN_BIT_CAST:
3693       assert(Record[ASTStmtReader::NumExprFields] == 0 && "Wrong PathSize!");
3694       S = new (Context) BuiltinBitCastExpr(Empty);
3695       break;
3696 
3697     case EXPR_USER_DEFINED_LITERAL:
3698       S = UserDefinedLiteral::CreateEmpty(
3699           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3700           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3701       break;
3702 
3703     case EXPR_CXX_STD_INITIALIZER_LIST:
3704       S = new (Context) CXXStdInitializerListExpr(Empty);
3705       break;
3706 
3707     case EXPR_CXX_BOOL_LITERAL:
3708       S = new (Context) CXXBoolLiteralExpr(Empty);
3709       break;
3710 
3711     case EXPR_CXX_NULL_PTR_LITERAL:
3712       S = new (Context) CXXNullPtrLiteralExpr(Empty);
3713       break;
3714 
3715     case EXPR_CXX_TYPEID_EXPR:
3716       S = new (Context) CXXTypeidExpr(Empty, true);
3717       break;
3718 
3719     case EXPR_CXX_TYPEID_TYPE:
3720       S = new (Context) CXXTypeidExpr(Empty, false);
3721       break;
3722 
3723     case EXPR_CXX_UUIDOF_EXPR:
3724       S = new (Context) CXXUuidofExpr(Empty, true);
3725       break;
3726 
3727     case EXPR_CXX_PROPERTY_REF_EXPR:
3728       S = new (Context) MSPropertyRefExpr(Empty);
3729       break;
3730 
3731     case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR:
3732       S = new (Context) MSPropertySubscriptExpr(Empty);
3733       break;
3734 
3735     case EXPR_CXX_UUIDOF_TYPE:
3736       S = new (Context) CXXUuidofExpr(Empty, false);
3737       break;
3738 
3739     case EXPR_CXX_THIS:
3740       S = new (Context) CXXThisExpr(Empty);
3741       break;
3742 
3743     case EXPR_CXX_THROW:
3744       S = new (Context) CXXThrowExpr(Empty);
3745       break;
3746 
3747     case EXPR_CXX_DEFAULT_ARG:
3748       S = new (Context) CXXDefaultArgExpr(Empty);
3749       break;
3750 
3751     case EXPR_CXX_DEFAULT_INIT:
3752       S = new (Context) CXXDefaultInitExpr(Empty);
3753       break;
3754 
3755     case EXPR_CXX_BIND_TEMPORARY:
3756       S = new (Context) CXXBindTemporaryExpr(Empty);
3757       break;
3758 
3759     case EXPR_CXX_SCALAR_VALUE_INIT:
3760       S = new (Context) CXXScalarValueInitExpr(Empty);
3761       break;
3762 
3763     case EXPR_CXX_NEW:
3764       S = CXXNewExpr::CreateEmpty(
3765           Context,
3766           /*IsArray=*/Record[ASTStmtReader::NumExprFields],
3767           /*HasInit=*/Record[ASTStmtReader::NumExprFields + 1],
3768           /*NumPlacementArgs=*/Record[ASTStmtReader::NumExprFields + 2],
3769           /*IsParenTypeId=*/Record[ASTStmtReader::NumExprFields + 3]);
3770       break;
3771 
3772     case EXPR_CXX_DELETE:
3773       S = new (Context) CXXDeleteExpr(Empty);
3774       break;
3775 
3776     case EXPR_CXX_PSEUDO_DESTRUCTOR:
3777       S = new (Context) CXXPseudoDestructorExpr(Empty);
3778       break;
3779 
3780     case EXPR_EXPR_WITH_CLEANUPS:
3781       S = ExprWithCleanups::Create(Context, Empty,
3782                                    Record[ASTStmtReader::NumExprFields]);
3783       break;
3784 
3785     case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
3786       S = CXXDependentScopeMemberExpr::CreateEmpty(
3787           Context,
3788           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
3789           /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 1],
3790           /*HasFirstQualifierFoundInScope=*/
3791           Record[ASTStmtReader::NumExprFields + 2]);
3792       break;
3793 
3794     case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
3795       S = DependentScopeDeclRefExpr::CreateEmpty(Context,
3796          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
3797                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
3798                                    ? Record[ASTStmtReader::NumExprFields + 1]
3799                                    : 0);
3800       break;
3801 
3802     case EXPR_CXX_UNRESOLVED_CONSTRUCT:
3803       S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
3804                               /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3805       break;
3806 
3807     case EXPR_CXX_UNRESOLVED_MEMBER:
3808       S = UnresolvedMemberExpr::CreateEmpty(
3809           Context,
3810           /*NumResults=*/Record[ASTStmtReader::NumExprFields],
3811           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
3812           /*NumTemplateArgs=*/
3813           Record[ASTStmtReader::NumExprFields + 1]
3814               ? Record[ASTStmtReader::NumExprFields + 2]
3815               : 0);
3816       break;
3817 
3818     case EXPR_CXX_UNRESOLVED_LOOKUP:
3819       S = UnresolvedLookupExpr::CreateEmpty(
3820           Context,
3821           /*NumResults=*/Record[ASTStmtReader::NumExprFields],
3822           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
3823           /*NumTemplateArgs=*/
3824           Record[ASTStmtReader::NumExprFields + 1]
3825               ? Record[ASTStmtReader::NumExprFields + 2]
3826               : 0);
3827       break;
3828 
3829     case EXPR_TYPE_TRAIT:
3830       S = TypeTraitExpr::CreateDeserialized(Context,
3831             Record[ASTStmtReader::NumExprFields]);
3832       break;
3833 
3834     case EXPR_ARRAY_TYPE_TRAIT:
3835       S = new (Context) ArrayTypeTraitExpr(Empty);
3836       break;
3837 
3838     case EXPR_CXX_EXPRESSION_TRAIT:
3839       S = new (Context) ExpressionTraitExpr(Empty);
3840       break;
3841 
3842     case EXPR_CXX_NOEXCEPT:
3843       S = new (Context) CXXNoexceptExpr(Empty);
3844       break;
3845 
3846     case EXPR_PACK_EXPANSION:
3847       S = new (Context) PackExpansionExpr(Empty);
3848       break;
3849 
3850     case EXPR_SIZEOF_PACK:
3851       S = SizeOfPackExpr::CreateDeserialized(
3852               Context,
3853               /*NumPartialArgs=*/Record[ASTStmtReader::NumExprFields]);
3854       break;
3855 
3856     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
3857       S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
3858       break;
3859 
3860     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
3861       S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
3862       break;
3863 
3864     case EXPR_FUNCTION_PARM_PACK:
3865       S = FunctionParmPackExpr::CreateEmpty(Context,
3866                                           Record[ASTStmtReader::NumExprFields]);
3867       break;
3868 
3869     case EXPR_MATERIALIZE_TEMPORARY:
3870       S = new (Context) MaterializeTemporaryExpr(Empty);
3871       break;
3872 
3873     case EXPR_CXX_FOLD:
3874       S = new (Context) CXXFoldExpr(Empty);
3875       break;
3876 
3877     case EXPR_OPAQUE_VALUE:
3878       S = new (Context) OpaqueValueExpr(Empty);
3879       break;
3880 
3881     case EXPR_CUDA_KERNEL_CALL:
3882       S = CUDAKernelCallExpr::CreateEmpty(
3883           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3884           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3885       break;
3886 
3887     case EXPR_ASTYPE:
3888       S = new (Context) AsTypeExpr(Empty);
3889       break;
3890 
3891     case EXPR_PSEUDO_OBJECT: {
3892       unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
3893       S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
3894       break;
3895     }
3896 
3897     case EXPR_ATOMIC:
3898       S = new (Context) AtomicExpr(Empty);
3899       break;
3900 
3901     case EXPR_LAMBDA: {
3902       unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
3903       S = LambdaExpr::CreateDeserialized(Context, NumCaptures);
3904       break;
3905     }
3906 
3907     case STMT_COROUTINE_BODY: {
3908       unsigned NumParams = Record[ASTStmtReader::NumStmtFields];
3909       S = CoroutineBodyStmt::Create(Context, Empty, NumParams);
3910       break;
3911     }
3912 
3913     case STMT_CORETURN:
3914       S = new (Context) CoreturnStmt(Empty);
3915       break;
3916 
3917     case EXPR_COAWAIT:
3918       S = new (Context) CoawaitExpr(Empty);
3919       break;
3920 
3921     case EXPR_COYIELD:
3922       S = new (Context) CoyieldExpr(Empty);
3923       break;
3924 
3925     case EXPR_DEPENDENT_COAWAIT:
3926       S = new (Context) DependentCoawaitExpr(Empty);
3927       break;
3928 
3929     case EXPR_CONCEPT_SPECIALIZATION: {
3930       unsigned numTemplateArgs = Record[ASTStmtReader::NumExprFields];
3931       S = ConceptSpecializationExpr::Create(Context, Empty, numTemplateArgs);
3932       break;
3933     }
3934 
3935     case EXPR_REQUIRES:
3936       unsigned numLocalParameters = Record[ASTStmtReader::NumExprFields];
3937       unsigned numRequirement = Record[ASTStmtReader::NumExprFields + 1];
3938       S = RequiresExpr::Create(Context, Empty, numLocalParameters,
3939                                numRequirement);
3940       break;
3941     }
3942 
3943     // We hit a STMT_STOP, so we're done with this expression.
3944     if (Finished)
3945       break;
3946 
3947     ++NumStatementsRead;
3948 
3949     if (S && !IsStmtReference) {
3950       Reader.Visit(S);
3951       StmtEntries[Cursor.GetCurrentBitNo()] = S;
3952     }
3953 
3954     assert(Record.getIdx() == Record.size() &&
3955            "Invalid deserialization of statement");
3956     StmtStack.push_back(S);
3957   }
3958 Done:
3959   assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
3960   assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
3961   return StmtStack.pop_back_val();
3962 }
3963