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->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::VisitOMPParallelMaskedDirective(
2375     OMPParallelMaskedDirective *D) {
2376   VisitStmt(D);
2377   VisitOMPExecutableDirective(D);
2378 }
2379 
2380 void ASTStmtReader::VisitOMPParallelSectionsDirective(
2381     OMPParallelSectionsDirective *D) {
2382   VisitStmt(D);
2383   VisitOMPExecutableDirective(D);
2384   D->setHasCancel(Record.readBool());
2385 }
2386 
2387 void ASTStmtReader::VisitOMPTaskDirective(OMPTaskDirective *D) {
2388   VisitStmt(D);
2389   VisitOMPExecutableDirective(D);
2390   D->setHasCancel(Record.readBool());
2391 }
2392 
2393 void ASTStmtReader::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *D) {
2394   VisitStmt(D);
2395   VisitOMPExecutableDirective(D);
2396 }
2397 
2398 void ASTStmtReader::VisitOMPBarrierDirective(OMPBarrierDirective *D) {
2399   VisitStmt(D);
2400   VisitOMPExecutableDirective(D);
2401 }
2402 
2403 void ASTStmtReader::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
2404   VisitStmt(D);
2405   // The NumClauses field was read in ReadStmtFromStream.
2406   Record.skipInts(1);
2407   VisitOMPExecutableDirective(D);
2408 }
2409 
2410 void ASTStmtReader::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *D) {
2411   VisitStmt(D);
2412   VisitOMPExecutableDirective(D);
2413 }
2414 
2415 void ASTStmtReader::VisitOMPFlushDirective(OMPFlushDirective *D) {
2416   VisitStmt(D);
2417   VisitOMPExecutableDirective(D);
2418 }
2419 
2420 void ASTStmtReader::VisitOMPDepobjDirective(OMPDepobjDirective *D) {
2421   VisitStmt(D);
2422   VisitOMPExecutableDirective(D);
2423 }
2424 
2425 void ASTStmtReader::VisitOMPScanDirective(OMPScanDirective *D) {
2426   VisitStmt(D);
2427   VisitOMPExecutableDirective(D);
2428 }
2429 
2430 void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
2431   VisitStmt(D);
2432   VisitOMPExecutableDirective(D);
2433 }
2434 
2435 void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
2436   VisitStmt(D);
2437   VisitOMPExecutableDirective(D);
2438   D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
2439   D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
2440   D->Flags.IsFailOnly = Record.readBool() ? 1 : 0;
2441 }
2442 
2443 void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {
2444   VisitStmt(D);
2445   VisitOMPExecutableDirective(D);
2446 }
2447 
2448 void ASTStmtReader::VisitOMPTargetDataDirective(OMPTargetDataDirective *D) {
2449   VisitStmt(D);
2450   VisitOMPExecutableDirective(D);
2451 }
2452 
2453 void ASTStmtReader::VisitOMPTargetEnterDataDirective(
2454     OMPTargetEnterDataDirective *D) {
2455   VisitStmt(D);
2456   VisitOMPExecutableDirective(D);
2457 }
2458 
2459 void ASTStmtReader::VisitOMPTargetExitDataDirective(
2460     OMPTargetExitDataDirective *D) {
2461   VisitStmt(D);
2462   VisitOMPExecutableDirective(D);
2463 }
2464 
2465 void ASTStmtReader::VisitOMPTargetParallelDirective(
2466     OMPTargetParallelDirective *D) {
2467   VisitStmt(D);
2468   VisitOMPExecutableDirective(D);
2469   D->setHasCancel(Record.readBool());
2470 }
2471 
2472 void ASTStmtReader::VisitOMPTargetParallelForDirective(
2473     OMPTargetParallelForDirective *D) {
2474   VisitOMPLoopDirective(D);
2475   D->setHasCancel(Record.readBool());
2476 }
2477 
2478 void ASTStmtReader::VisitOMPTeamsDirective(OMPTeamsDirective *D) {
2479   VisitStmt(D);
2480   VisitOMPExecutableDirective(D);
2481 }
2482 
2483 void ASTStmtReader::VisitOMPCancellationPointDirective(
2484     OMPCancellationPointDirective *D) {
2485   VisitStmt(D);
2486   VisitOMPExecutableDirective(D);
2487   D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2488 }
2489 
2490 void ASTStmtReader::VisitOMPCancelDirective(OMPCancelDirective *D) {
2491   VisitStmt(D);
2492   VisitOMPExecutableDirective(D);
2493   D->setCancelRegion(Record.readEnum<OpenMPDirectiveKind>());
2494 }
2495 
2496 void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
2497   VisitOMPLoopDirective(D);
2498   D->setHasCancel(Record.readBool());
2499 }
2500 
2501 void ASTStmtReader::VisitOMPTaskLoopSimdDirective(OMPTaskLoopSimdDirective *D) {
2502   VisitOMPLoopDirective(D);
2503 }
2504 
2505 void ASTStmtReader::VisitOMPMasterTaskLoopDirective(
2506     OMPMasterTaskLoopDirective *D) {
2507   VisitOMPLoopDirective(D);
2508   D->setHasCancel(Record.readBool());
2509 }
2510 
2511 void ASTStmtReader::VisitOMPMaskedTaskLoopDirective(
2512     OMPMaskedTaskLoopDirective *D) {
2513   VisitOMPLoopDirective(D);
2514   D->setHasCancel(Record.readBool());
2515 }
2516 
2517 void ASTStmtReader::VisitOMPMasterTaskLoopSimdDirective(
2518     OMPMasterTaskLoopSimdDirective *D) {
2519   VisitOMPLoopDirective(D);
2520 }
2521 
2522 void ASTStmtReader::VisitOMPParallelMasterTaskLoopDirective(
2523     OMPParallelMasterTaskLoopDirective *D) {
2524   VisitOMPLoopDirective(D);
2525   D->setHasCancel(Record.readBool());
2526 }
2527 
2528 void ASTStmtReader::VisitOMPParallelMasterTaskLoopSimdDirective(
2529     OMPParallelMasterTaskLoopSimdDirective *D) {
2530   VisitOMPLoopDirective(D);
2531 }
2532 
2533 void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) {
2534   VisitOMPLoopDirective(D);
2535 }
2536 
2537 void ASTStmtReader::VisitOMPTargetUpdateDirective(OMPTargetUpdateDirective *D) {
2538   VisitStmt(D);
2539   VisitOMPExecutableDirective(D);
2540 }
2541 
2542 void ASTStmtReader::VisitOMPDistributeParallelForDirective(
2543     OMPDistributeParallelForDirective *D) {
2544   VisitOMPLoopDirective(D);
2545   D->setHasCancel(Record.readBool());
2546 }
2547 
2548 void ASTStmtReader::VisitOMPDistributeParallelForSimdDirective(
2549     OMPDistributeParallelForSimdDirective *D) {
2550   VisitOMPLoopDirective(D);
2551 }
2552 
2553 void ASTStmtReader::VisitOMPDistributeSimdDirective(
2554     OMPDistributeSimdDirective *D) {
2555   VisitOMPLoopDirective(D);
2556 }
2557 
2558 void ASTStmtReader::VisitOMPTargetParallelForSimdDirective(
2559     OMPTargetParallelForSimdDirective *D) {
2560   VisitOMPLoopDirective(D);
2561 }
2562 
2563 void ASTStmtReader::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) {
2564   VisitOMPLoopDirective(D);
2565 }
2566 
2567 void ASTStmtReader::VisitOMPTeamsDistributeDirective(
2568     OMPTeamsDistributeDirective *D) {
2569   VisitOMPLoopDirective(D);
2570 }
2571 
2572 void ASTStmtReader::VisitOMPTeamsDistributeSimdDirective(
2573     OMPTeamsDistributeSimdDirective *D) {
2574   VisitOMPLoopDirective(D);
2575 }
2576 
2577 void ASTStmtReader::VisitOMPTeamsDistributeParallelForSimdDirective(
2578     OMPTeamsDistributeParallelForSimdDirective *D) {
2579   VisitOMPLoopDirective(D);
2580 }
2581 
2582 void ASTStmtReader::VisitOMPTeamsDistributeParallelForDirective(
2583     OMPTeamsDistributeParallelForDirective *D) {
2584   VisitOMPLoopDirective(D);
2585   D->setHasCancel(Record.readBool());
2586 }
2587 
2588 void ASTStmtReader::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *D) {
2589   VisitStmt(D);
2590   VisitOMPExecutableDirective(D);
2591 }
2592 
2593 void ASTStmtReader::VisitOMPTargetTeamsDistributeDirective(
2594     OMPTargetTeamsDistributeDirective *D) {
2595   VisitOMPLoopDirective(D);
2596 }
2597 
2598 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForDirective(
2599     OMPTargetTeamsDistributeParallelForDirective *D) {
2600   VisitOMPLoopDirective(D);
2601   D->setHasCancel(Record.readBool());
2602 }
2603 
2604 void ASTStmtReader::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2605     OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2606   VisitOMPLoopDirective(D);
2607 }
2608 
2609 void ASTStmtReader::VisitOMPTargetTeamsDistributeSimdDirective(
2610     OMPTargetTeamsDistributeSimdDirective *D) {
2611   VisitOMPLoopDirective(D);
2612 }
2613 
2614 void ASTStmtReader::VisitOMPInteropDirective(OMPInteropDirective *D) {
2615   VisitStmt(D);
2616   VisitOMPExecutableDirective(D);
2617 }
2618 
2619 void ASTStmtReader::VisitOMPDispatchDirective(OMPDispatchDirective *D) {
2620   VisitStmt(D);
2621   VisitOMPExecutableDirective(D);
2622   D->setTargetCallLoc(Record.readSourceLocation());
2623 }
2624 
2625 void ASTStmtReader::VisitOMPMaskedDirective(OMPMaskedDirective *D) {
2626   VisitStmt(D);
2627   VisitOMPExecutableDirective(D);
2628 }
2629 
2630 void ASTStmtReader::VisitOMPGenericLoopDirective(OMPGenericLoopDirective *D) {
2631   VisitOMPLoopDirective(D);
2632 }
2633 
2634 void ASTStmtReader::VisitOMPTeamsGenericLoopDirective(
2635     OMPTeamsGenericLoopDirective *D) {
2636   VisitOMPLoopDirective(D);
2637 }
2638 
2639 void ASTStmtReader::VisitOMPTargetTeamsGenericLoopDirective(
2640     OMPTargetTeamsGenericLoopDirective *D) {
2641   VisitOMPLoopDirective(D);
2642 }
2643 
2644 void ASTStmtReader::VisitOMPParallelGenericLoopDirective(
2645     OMPParallelGenericLoopDirective *D) {
2646   VisitOMPLoopDirective(D);
2647 }
2648 
2649 void ASTStmtReader::VisitOMPTargetParallelGenericLoopDirective(
2650     OMPTargetParallelGenericLoopDirective *D) {
2651   VisitOMPLoopDirective(D);
2652 }
2653 
2654 //===----------------------------------------------------------------------===//
2655 // ASTReader Implementation
2656 //===----------------------------------------------------------------------===//
2657 
2658 Stmt *ASTReader::ReadStmt(ModuleFile &F) {
2659   switch (ReadingKind) {
2660   case Read_None:
2661     llvm_unreachable("should not call this when not reading anything");
2662   case Read_Decl:
2663   case Read_Type:
2664     return ReadStmtFromStream(F);
2665   case Read_Stmt:
2666     return ReadSubStmt();
2667   }
2668 
2669   llvm_unreachable("ReadingKind not set ?");
2670 }
2671 
2672 Expr *ASTReader::ReadExpr(ModuleFile &F) {
2673   return cast_or_null<Expr>(ReadStmt(F));
2674 }
2675 
2676 Expr *ASTReader::ReadSubExpr() {
2677   return cast_or_null<Expr>(ReadSubStmt());
2678 }
2679 
2680 // Within the bitstream, expressions are stored in Reverse Polish
2681 // Notation, with each of the subexpressions preceding the
2682 // expression they are stored in. Subexpressions are stored from last to first.
2683 // To evaluate expressions, we continue reading expressions and placing them on
2684 // the stack, with expressions having operands removing those operands from the
2685 // stack. Evaluation terminates when we see a STMT_STOP record, and
2686 // the single remaining expression on the stack is our result.
2687 Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) {
2688   ReadingKindTracker ReadingKind(Read_Stmt, *this);
2689   llvm::BitstreamCursor &Cursor = F.DeclsCursor;
2690 
2691   // Map of offset to previously deserialized stmt. The offset points
2692   // just after the stmt record.
2693   llvm::DenseMap<uint64_t, Stmt *> StmtEntries;
2694 
2695 #ifndef NDEBUG
2696   unsigned PrevNumStmts = StmtStack.size();
2697 #endif
2698 
2699   ASTRecordReader Record(*this, F);
2700   ASTStmtReader Reader(Record, Cursor);
2701   Stmt::EmptyShell Empty;
2702 
2703   while (true) {
2704     llvm::Expected<llvm::BitstreamEntry> MaybeEntry =
2705         Cursor.advanceSkippingSubblocks();
2706     if (!MaybeEntry) {
2707       Error(toString(MaybeEntry.takeError()));
2708       return nullptr;
2709     }
2710     llvm::BitstreamEntry Entry = MaybeEntry.get();
2711 
2712     switch (Entry.Kind) {
2713     case llvm::BitstreamEntry::SubBlock: // Handled for us already.
2714     case llvm::BitstreamEntry::Error:
2715       Error("malformed block record in AST file");
2716       return nullptr;
2717     case llvm::BitstreamEntry::EndBlock:
2718       goto Done;
2719     case llvm::BitstreamEntry::Record:
2720       // The interesting case.
2721       break;
2722     }
2723 
2724     ASTContext &Context = getContext();
2725     Stmt *S = nullptr;
2726     bool Finished = false;
2727     bool IsStmtReference = false;
2728     Expected<unsigned> MaybeStmtCode = Record.readRecord(Cursor, Entry.ID);
2729     if (!MaybeStmtCode) {
2730       Error(toString(MaybeStmtCode.takeError()));
2731       return nullptr;
2732     }
2733     switch ((StmtCode)MaybeStmtCode.get()) {
2734     case STMT_STOP:
2735       Finished = true;
2736       break;
2737 
2738     case STMT_REF_PTR:
2739       IsStmtReference = true;
2740       assert(StmtEntries.find(Record[0]) != StmtEntries.end() &&
2741              "No stmt was recorded for this offset reference!");
2742       S = StmtEntries[Record.readInt()];
2743       break;
2744 
2745     case STMT_NULL_PTR:
2746       S = nullptr;
2747       break;
2748 
2749     case STMT_NULL:
2750       S = new (Context) NullStmt(Empty);
2751       break;
2752 
2753     case STMT_COMPOUND:
2754       S = CompoundStmt::CreateEmpty(
2755           Context, /*NumStmts=*/Record[ASTStmtReader::NumStmtFields]);
2756       break;
2757 
2758     case STMT_CASE:
2759       S = CaseStmt::CreateEmpty(
2760           Context,
2761           /*CaseStmtIsGNURange*/ Record[ASTStmtReader::NumStmtFields + 3]);
2762       break;
2763 
2764     case STMT_DEFAULT:
2765       S = new (Context) DefaultStmt(Empty);
2766       break;
2767 
2768     case STMT_LABEL:
2769       S = new (Context) LabelStmt(Empty);
2770       break;
2771 
2772     case STMT_ATTRIBUTED:
2773       S = AttributedStmt::CreateEmpty(
2774         Context,
2775         /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]);
2776       break;
2777 
2778     case STMT_IF:
2779       S = IfStmt::CreateEmpty(
2780           Context,
2781           /* HasElse=*/Record[ASTStmtReader::NumStmtFields],
2782           /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1],
2783           /* HasInit=*/Record[ASTStmtReader::NumStmtFields + 2]);
2784       break;
2785 
2786     case STMT_SWITCH:
2787       S = SwitchStmt::CreateEmpty(
2788           Context,
2789           /* HasInit=*/Record[ASTStmtReader::NumStmtFields],
2790           /* HasVar=*/Record[ASTStmtReader::NumStmtFields + 1]);
2791       break;
2792 
2793     case STMT_WHILE:
2794       S = WhileStmt::CreateEmpty(
2795           Context,
2796           /* HasVar=*/Record[ASTStmtReader::NumStmtFields]);
2797       break;
2798 
2799     case STMT_DO:
2800       S = new (Context) DoStmt(Empty);
2801       break;
2802 
2803     case STMT_FOR:
2804       S = new (Context) ForStmt(Empty);
2805       break;
2806 
2807     case STMT_GOTO:
2808       S = new (Context) GotoStmt(Empty);
2809       break;
2810 
2811     case STMT_INDIRECT_GOTO:
2812       S = new (Context) IndirectGotoStmt(Empty);
2813       break;
2814 
2815     case STMT_CONTINUE:
2816       S = new (Context) ContinueStmt(Empty);
2817       break;
2818 
2819     case STMT_BREAK:
2820       S = new (Context) BreakStmt(Empty);
2821       break;
2822 
2823     case STMT_RETURN:
2824       S = ReturnStmt::CreateEmpty(
2825           Context, /* HasNRVOCandidate=*/Record[ASTStmtReader::NumStmtFields]);
2826       break;
2827 
2828     case STMT_DECL:
2829       S = new (Context) DeclStmt(Empty);
2830       break;
2831 
2832     case STMT_GCCASM:
2833       S = new (Context) GCCAsmStmt(Empty);
2834       break;
2835 
2836     case STMT_MSASM:
2837       S = new (Context) MSAsmStmt(Empty);
2838       break;
2839 
2840     case STMT_CAPTURED:
2841       S = CapturedStmt::CreateDeserialized(
2842           Context, Record[ASTStmtReader::NumStmtFields]);
2843       break;
2844 
2845     case EXPR_CONSTANT:
2846       S = ConstantExpr::CreateEmpty(
2847           Context, static_cast<ConstantExpr::ResultStorageKind>(
2848                        /*StorageKind=*/Record[ASTStmtReader::NumExprFields]));
2849       break;
2850 
2851     case EXPR_SYCL_UNIQUE_STABLE_NAME:
2852       S = SYCLUniqueStableNameExpr::CreateEmpty(Context);
2853       break;
2854 
2855     case EXPR_PREDEFINED:
2856       S = PredefinedExpr::CreateEmpty(
2857           Context,
2858           /*HasFunctionName*/ Record[ASTStmtReader::NumExprFields]);
2859       break;
2860 
2861     case EXPR_DECL_REF:
2862       S = DeclRefExpr::CreateEmpty(
2863         Context,
2864         /*HasQualifier=*/Record[ASTStmtReader::NumExprFields],
2865         /*HasFoundDecl=*/Record[ASTStmtReader::NumExprFields + 1],
2866         /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 2],
2867         /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 2] ?
2868           Record[ASTStmtReader::NumExprFields + 6] : 0);
2869       break;
2870 
2871     case EXPR_INTEGER_LITERAL:
2872       S = IntegerLiteral::Create(Context, Empty);
2873       break;
2874 
2875     case EXPR_FIXEDPOINT_LITERAL:
2876       S = FixedPointLiteral::Create(Context, Empty);
2877       break;
2878 
2879     case EXPR_FLOATING_LITERAL:
2880       S = FloatingLiteral::Create(Context, Empty);
2881       break;
2882 
2883     case EXPR_IMAGINARY_LITERAL:
2884       S = new (Context) ImaginaryLiteral(Empty);
2885       break;
2886 
2887     case EXPR_STRING_LITERAL:
2888       S = StringLiteral::CreateEmpty(
2889           Context,
2890           /* NumConcatenated=*/Record[ASTStmtReader::NumExprFields],
2891           /* Length=*/Record[ASTStmtReader::NumExprFields + 1],
2892           /* CharByteWidth=*/Record[ASTStmtReader::NumExprFields + 2]);
2893       break;
2894 
2895     case EXPR_CHARACTER_LITERAL:
2896       S = new (Context) CharacterLiteral(Empty);
2897       break;
2898 
2899     case EXPR_PAREN:
2900       S = new (Context) ParenExpr(Empty);
2901       break;
2902 
2903     case EXPR_PAREN_LIST:
2904       S = ParenListExpr::CreateEmpty(
2905           Context,
2906           /* NumExprs=*/Record[ASTStmtReader::NumExprFields]);
2907       break;
2908 
2909     case EXPR_UNARY_OPERATOR:
2910       S = UnaryOperator::CreateEmpty(Context,
2911                                      Record[ASTStmtReader::NumExprFields]);
2912       break;
2913 
2914     case EXPR_OFFSETOF:
2915       S = OffsetOfExpr::CreateEmpty(Context,
2916                                     Record[ASTStmtReader::NumExprFields],
2917                                     Record[ASTStmtReader::NumExprFields + 1]);
2918       break;
2919 
2920     case EXPR_SIZEOF_ALIGN_OF:
2921       S = new (Context) UnaryExprOrTypeTraitExpr(Empty);
2922       break;
2923 
2924     case EXPR_ARRAY_SUBSCRIPT:
2925       S = new (Context) ArraySubscriptExpr(Empty);
2926       break;
2927 
2928     case EXPR_MATRIX_SUBSCRIPT:
2929       S = new (Context) MatrixSubscriptExpr(Empty);
2930       break;
2931 
2932     case EXPR_OMP_ARRAY_SECTION:
2933       S = new (Context) OMPArraySectionExpr(Empty);
2934       break;
2935 
2936     case EXPR_OMP_ARRAY_SHAPING:
2937       S = OMPArrayShapingExpr::CreateEmpty(
2938           Context, Record[ASTStmtReader::NumExprFields]);
2939       break;
2940 
2941     case EXPR_OMP_ITERATOR:
2942       S = OMPIteratorExpr::CreateEmpty(Context,
2943                                        Record[ASTStmtReader::NumExprFields]);
2944       break;
2945 
2946     case EXPR_CALL:
2947       S = CallExpr::CreateEmpty(
2948           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
2949           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
2950       break;
2951 
2952     case EXPR_RECOVERY:
2953       S = RecoveryExpr::CreateEmpty(
2954           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
2955       break;
2956 
2957     case EXPR_MEMBER:
2958       S = MemberExpr::CreateEmpty(Context, Record[ASTStmtReader::NumExprFields],
2959                                   Record[ASTStmtReader::NumExprFields + 1],
2960                                   Record[ASTStmtReader::NumExprFields + 2],
2961                                   Record[ASTStmtReader::NumExprFields + 3]);
2962       break;
2963 
2964     case EXPR_BINARY_OPERATOR:
2965       S = BinaryOperator::CreateEmpty(Context,
2966                                       Record[ASTStmtReader::NumExprFields]);
2967       break;
2968 
2969     case EXPR_COMPOUND_ASSIGN_OPERATOR:
2970       S = CompoundAssignOperator::CreateEmpty(
2971           Context, Record[ASTStmtReader::NumExprFields]);
2972       break;
2973 
2974     case EXPR_CONDITIONAL_OPERATOR:
2975       S = new (Context) ConditionalOperator(Empty);
2976       break;
2977 
2978     case EXPR_BINARY_CONDITIONAL_OPERATOR:
2979       S = new (Context) BinaryConditionalOperator(Empty);
2980       break;
2981 
2982     case EXPR_IMPLICIT_CAST:
2983       S = ImplicitCastExpr::CreateEmpty(
2984           Context,
2985           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
2986           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
2987       break;
2988 
2989     case EXPR_CSTYLE_CAST:
2990       S = CStyleCastExpr::CreateEmpty(
2991           Context,
2992           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
2993           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
2994       break;
2995 
2996     case EXPR_COMPOUND_LITERAL:
2997       S = new (Context) CompoundLiteralExpr(Empty);
2998       break;
2999 
3000     case EXPR_EXT_VECTOR_ELEMENT:
3001       S = new (Context) ExtVectorElementExpr(Empty);
3002       break;
3003 
3004     case EXPR_INIT_LIST:
3005       S = new (Context) InitListExpr(Empty);
3006       break;
3007 
3008     case EXPR_DESIGNATED_INIT:
3009       S = DesignatedInitExpr::CreateEmpty(Context,
3010                                      Record[ASTStmtReader::NumExprFields] - 1);
3011 
3012       break;
3013 
3014     case EXPR_DESIGNATED_INIT_UPDATE:
3015       S = new (Context) DesignatedInitUpdateExpr(Empty);
3016       break;
3017 
3018     case EXPR_IMPLICIT_VALUE_INIT:
3019       S = new (Context) ImplicitValueInitExpr(Empty);
3020       break;
3021 
3022     case EXPR_NO_INIT:
3023       S = new (Context) NoInitExpr(Empty);
3024       break;
3025 
3026     case EXPR_ARRAY_INIT_LOOP:
3027       S = new (Context) ArrayInitLoopExpr(Empty);
3028       break;
3029 
3030     case EXPR_ARRAY_INIT_INDEX:
3031       S = new (Context) ArrayInitIndexExpr(Empty);
3032       break;
3033 
3034     case EXPR_VA_ARG:
3035       S = new (Context) VAArgExpr(Empty);
3036       break;
3037 
3038     case EXPR_SOURCE_LOC:
3039       S = new (Context) SourceLocExpr(Empty);
3040       break;
3041 
3042     case EXPR_ADDR_LABEL:
3043       S = new (Context) AddrLabelExpr(Empty);
3044       break;
3045 
3046     case EXPR_STMT:
3047       S = new (Context) StmtExpr(Empty);
3048       break;
3049 
3050     case EXPR_CHOOSE:
3051       S = new (Context) ChooseExpr(Empty);
3052       break;
3053 
3054     case EXPR_GNU_NULL:
3055       S = new (Context) GNUNullExpr(Empty);
3056       break;
3057 
3058     case EXPR_SHUFFLE_VECTOR:
3059       S = new (Context) ShuffleVectorExpr(Empty);
3060       break;
3061 
3062     case EXPR_CONVERT_VECTOR:
3063       S = new (Context) ConvertVectorExpr(Empty);
3064       break;
3065 
3066     case EXPR_BLOCK:
3067       S = new (Context) BlockExpr(Empty);
3068       break;
3069 
3070     case EXPR_GENERIC_SELECTION:
3071       S = GenericSelectionExpr::CreateEmpty(
3072           Context,
3073           /*NumAssocs=*/Record[ASTStmtReader::NumExprFields]);
3074       break;
3075 
3076     case EXPR_OBJC_STRING_LITERAL:
3077       S = new (Context) ObjCStringLiteral(Empty);
3078       break;
3079 
3080     case EXPR_OBJC_BOXED_EXPRESSION:
3081       S = new (Context) ObjCBoxedExpr(Empty);
3082       break;
3083 
3084     case EXPR_OBJC_ARRAY_LITERAL:
3085       S = ObjCArrayLiteral::CreateEmpty(Context,
3086                                         Record[ASTStmtReader::NumExprFields]);
3087       break;
3088 
3089     case EXPR_OBJC_DICTIONARY_LITERAL:
3090       S = ObjCDictionaryLiteral::CreateEmpty(Context,
3091             Record[ASTStmtReader::NumExprFields],
3092             Record[ASTStmtReader::NumExprFields + 1]);
3093       break;
3094 
3095     case EXPR_OBJC_ENCODE:
3096       S = new (Context) ObjCEncodeExpr(Empty);
3097       break;
3098 
3099     case EXPR_OBJC_SELECTOR_EXPR:
3100       S = new (Context) ObjCSelectorExpr(Empty);
3101       break;
3102 
3103     case EXPR_OBJC_PROTOCOL_EXPR:
3104       S = new (Context) ObjCProtocolExpr(Empty);
3105       break;
3106 
3107     case EXPR_OBJC_IVAR_REF_EXPR:
3108       S = new (Context) ObjCIvarRefExpr(Empty);
3109       break;
3110 
3111     case EXPR_OBJC_PROPERTY_REF_EXPR:
3112       S = new (Context) ObjCPropertyRefExpr(Empty);
3113       break;
3114 
3115     case EXPR_OBJC_SUBSCRIPT_REF_EXPR:
3116       S = new (Context) ObjCSubscriptRefExpr(Empty);
3117       break;
3118 
3119     case EXPR_OBJC_KVC_REF_EXPR:
3120       llvm_unreachable("mismatching AST file");
3121 
3122     case EXPR_OBJC_MESSAGE_EXPR:
3123       S = ObjCMessageExpr::CreateEmpty(Context,
3124                                      Record[ASTStmtReader::NumExprFields],
3125                                      Record[ASTStmtReader::NumExprFields + 1]);
3126       break;
3127 
3128     case EXPR_OBJC_ISA:
3129       S = new (Context) ObjCIsaExpr(Empty);
3130       break;
3131 
3132     case EXPR_OBJC_INDIRECT_COPY_RESTORE:
3133       S = new (Context) ObjCIndirectCopyRestoreExpr(Empty);
3134       break;
3135 
3136     case EXPR_OBJC_BRIDGED_CAST:
3137       S = new (Context) ObjCBridgedCastExpr(Empty);
3138       break;
3139 
3140     case STMT_OBJC_FOR_COLLECTION:
3141       S = new (Context) ObjCForCollectionStmt(Empty);
3142       break;
3143 
3144     case STMT_OBJC_CATCH:
3145       S = new (Context) ObjCAtCatchStmt(Empty);
3146       break;
3147 
3148     case STMT_OBJC_FINALLY:
3149       S = new (Context) ObjCAtFinallyStmt(Empty);
3150       break;
3151 
3152     case STMT_OBJC_AT_TRY:
3153       S = ObjCAtTryStmt::CreateEmpty(Context,
3154                                      Record[ASTStmtReader::NumStmtFields],
3155                                      Record[ASTStmtReader::NumStmtFields + 1]);
3156       break;
3157 
3158     case STMT_OBJC_AT_SYNCHRONIZED:
3159       S = new (Context) ObjCAtSynchronizedStmt(Empty);
3160       break;
3161 
3162     case STMT_OBJC_AT_THROW:
3163       S = new (Context) ObjCAtThrowStmt(Empty);
3164       break;
3165 
3166     case STMT_OBJC_AUTORELEASE_POOL:
3167       S = new (Context) ObjCAutoreleasePoolStmt(Empty);
3168       break;
3169 
3170     case EXPR_OBJC_BOOL_LITERAL:
3171       S = new (Context) ObjCBoolLiteralExpr(Empty);
3172       break;
3173 
3174     case EXPR_OBJC_AVAILABILITY_CHECK:
3175       S = new (Context) ObjCAvailabilityCheckExpr(Empty);
3176       break;
3177 
3178     case STMT_SEH_LEAVE:
3179       S = new (Context) SEHLeaveStmt(Empty);
3180       break;
3181 
3182     case STMT_SEH_EXCEPT:
3183       S = new (Context) SEHExceptStmt(Empty);
3184       break;
3185 
3186     case STMT_SEH_FINALLY:
3187       S = new (Context) SEHFinallyStmt(Empty);
3188       break;
3189 
3190     case STMT_SEH_TRY:
3191       S = new (Context) SEHTryStmt(Empty);
3192       break;
3193 
3194     case STMT_CXX_CATCH:
3195       S = new (Context) CXXCatchStmt(Empty);
3196       break;
3197 
3198     case STMT_CXX_TRY:
3199       S = CXXTryStmt::Create(Context, Empty,
3200              /*numHandlers=*/Record[ASTStmtReader::NumStmtFields]);
3201       break;
3202 
3203     case STMT_CXX_FOR_RANGE:
3204       S = new (Context) CXXForRangeStmt(Empty);
3205       break;
3206 
3207     case STMT_MS_DEPENDENT_EXISTS:
3208       S = new (Context) MSDependentExistsStmt(SourceLocation(), true,
3209                                               NestedNameSpecifierLoc(),
3210                                               DeclarationNameInfo(),
3211                                               nullptr);
3212       break;
3213 
3214     case STMT_OMP_CANONICAL_LOOP:
3215       S = OMPCanonicalLoop::createEmpty(Context);
3216       break;
3217 
3218     case STMT_OMP_META_DIRECTIVE:
3219       S = OMPMetaDirective::CreateEmpty(
3220           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3221       break;
3222 
3223     case STMT_OMP_PARALLEL_DIRECTIVE:
3224       S =
3225         OMPParallelDirective::CreateEmpty(Context,
3226                                           Record[ASTStmtReader::NumStmtFields],
3227                                           Empty);
3228       break;
3229 
3230     case STMT_OMP_SIMD_DIRECTIVE: {
3231       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3232       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3233       S = OMPSimdDirective::CreateEmpty(Context, NumClauses,
3234                                         CollapsedNum, Empty);
3235       break;
3236     }
3237 
3238     case STMT_OMP_TILE_DIRECTIVE: {
3239       unsigned NumLoops = Record[ASTStmtReader::NumStmtFields];
3240       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3241       S = OMPTileDirective::CreateEmpty(Context, NumClauses, NumLoops);
3242       break;
3243     }
3244 
3245     case STMT_OMP_UNROLL_DIRECTIVE: {
3246       assert(Record[ASTStmtReader::NumStmtFields] == 1 && "Unroll directive accepts only a single loop");
3247       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3248       S = OMPUnrollDirective::CreateEmpty(Context, NumClauses);
3249       break;
3250     }
3251 
3252     case STMT_OMP_FOR_DIRECTIVE: {
3253       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3254       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3255       S = OMPForDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3256                                        Empty);
3257       break;
3258     }
3259 
3260     case STMT_OMP_FOR_SIMD_DIRECTIVE: {
3261       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3262       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3263       S = OMPForSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3264                                            Empty);
3265       break;
3266     }
3267 
3268     case STMT_OMP_SECTIONS_DIRECTIVE:
3269       S = OMPSectionsDirective::CreateEmpty(
3270           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3271       break;
3272 
3273     case STMT_OMP_SECTION_DIRECTIVE:
3274       S = OMPSectionDirective::CreateEmpty(Context, Empty);
3275       break;
3276 
3277     case STMT_OMP_SINGLE_DIRECTIVE:
3278       S = OMPSingleDirective::CreateEmpty(
3279           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3280       break;
3281 
3282     case STMT_OMP_MASTER_DIRECTIVE:
3283       S = OMPMasterDirective::CreateEmpty(Context, Empty);
3284       break;
3285 
3286     case STMT_OMP_CRITICAL_DIRECTIVE:
3287       S = OMPCriticalDirective::CreateEmpty(
3288           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3289       break;
3290 
3291     case STMT_OMP_PARALLEL_FOR_DIRECTIVE: {
3292       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3293       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3294       S = OMPParallelForDirective::CreateEmpty(Context, NumClauses,
3295                                                CollapsedNum, Empty);
3296       break;
3297     }
3298 
3299     case STMT_OMP_PARALLEL_FOR_SIMD_DIRECTIVE: {
3300       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3301       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3302       S = OMPParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3303                                                    CollapsedNum, Empty);
3304       break;
3305     }
3306 
3307     case STMT_OMP_PARALLEL_MASTER_DIRECTIVE:
3308       S = OMPParallelMasterDirective::CreateEmpty(
3309           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3310       break;
3311 
3312     case STMT_OMP_PARALLEL_MASKED_DIRECTIVE:
3313       S = OMPParallelMaskedDirective::CreateEmpty(
3314           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3315       break;
3316 
3317     case STMT_OMP_PARALLEL_SECTIONS_DIRECTIVE:
3318       S = OMPParallelSectionsDirective::CreateEmpty(
3319           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3320       break;
3321 
3322     case STMT_OMP_TASK_DIRECTIVE:
3323       S = OMPTaskDirective::CreateEmpty(
3324           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3325       break;
3326 
3327     case STMT_OMP_TASKYIELD_DIRECTIVE:
3328       S = OMPTaskyieldDirective::CreateEmpty(Context, Empty);
3329       break;
3330 
3331     case STMT_OMP_BARRIER_DIRECTIVE:
3332       S = OMPBarrierDirective::CreateEmpty(Context, Empty);
3333       break;
3334 
3335     case STMT_OMP_TASKWAIT_DIRECTIVE:
3336       S = OMPTaskwaitDirective::CreateEmpty(
3337           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3338       break;
3339 
3340     case STMT_OMP_TASKGROUP_DIRECTIVE:
3341       S = OMPTaskgroupDirective::CreateEmpty(
3342           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3343       break;
3344 
3345     case STMT_OMP_FLUSH_DIRECTIVE:
3346       S = OMPFlushDirective::CreateEmpty(
3347           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3348       break;
3349 
3350     case STMT_OMP_DEPOBJ_DIRECTIVE:
3351       S = OMPDepobjDirective::CreateEmpty(
3352           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3353       break;
3354 
3355     case STMT_OMP_SCAN_DIRECTIVE:
3356       S = OMPScanDirective::CreateEmpty(
3357           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3358       break;
3359 
3360     case STMT_OMP_ORDERED_DIRECTIVE: {
3361       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields];
3362       bool HasAssociatedStmt = Record[ASTStmtReader::NumStmtFields + 2];
3363       S = OMPOrderedDirective::CreateEmpty(Context, NumClauses,
3364                                            !HasAssociatedStmt, Empty);
3365       break;
3366     }
3367 
3368     case STMT_OMP_ATOMIC_DIRECTIVE:
3369       S = OMPAtomicDirective::CreateEmpty(
3370           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3371       break;
3372 
3373     case STMT_OMP_TARGET_DIRECTIVE:
3374       S = OMPTargetDirective::CreateEmpty(
3375           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3376       break;
3377 
3378     case STMT_OMP_TARGET_DATA_DIRECTIVE:
3379       S = OMPTargetDataDirective::CreateEmpty(
3380           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3381       break;
3382 
3383     case STMT_OMP_TARGET_ENTER_DATA_DIRECTIVE:
3384       S = OMPTargetEnterDataDirective::CreateEmpty(
3385           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3386       break;
3387 
3388     case STMT_OMP_TARGET_EXIT_DATA_DIRECTIVE:
3389       S = OMPTargetExitDataDirective::CreateEmpty(
3390           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3391       break;
3392 
3393     case STMT_OMP_TARGET_PARALLEL_DIRECTIVE:
3394       S = OMPTargetParallelDirective::CreateEmpty(
3395           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3396       break;
3397 
3398     case STMT_OMP_TARGET_PARALLEL_FOR_DIRECTIVE: {
3399       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3400       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3401       S = OMPTargetParallelForDirective::CreateEmpty(Context, NumClauses,
3402                                                      CollapsedNum, Empty);
3403       break;
3404     }
3405 
3406     case STMT_OMP_TARGET_UPDATE_DIRECTIVE:
3407       S = OMPTargetUpdateDirective::CreateEmpty(
3408           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3409       break;
3410 
3411     case STMT_OMP_TEAMS_DIRECTIVE:
3412       S = OMPTeamsDirective::CreateEmpty(
3413           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3414       break;
3415 
3416     case STMT_OMP_CANCELLATION_POINT_DIRECTIVE:
3417       S = OMPCancellationPointDirective::CreateEmpty(Context, Empty);
3418       break;
3419 
3420     case STMT_OMP_CANCEL_DIRECTIVE:
3421       S = OMPCancelDirective::CreateEmpty(
3422           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3423       break;
3424 
3425     case STMT_OMP_TASKLOOP_DIRECTIVE: {
3426       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3427       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3428       S = OMPTaskLoopDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3429                                             Empty);
3430       break;
3431     }
3432 
3433     case STMT_OMP_TASKLOOP_SIMD_DIRECTIVE: {
3434       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3435       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3436       S = OMPTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3437                                                 CollapsedNum, Empty);
3438       break;
3439     }
3440 
3441     case STMT_OMP_MASTER_TASKLOOP_DIRECTIVE: {
3442       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3443       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3444       S = OMPMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3445                                                   CollapsedNum, Empty);
3446       break;
3447     }
3448 
3449     case STMT_OMP_MASKED_TASKLOOP_DIRECTIVE: {
3450       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3451       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3452       S = OMPMaskedTaskLoopDirective::CreateEmpty(Context, NumClauses,
3453                                                   CollapsedNum, Empty);
3454       break;
3455     }
3456 
3457     case STMT_OMP_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3458       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3459       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3460       S = OMPMasterTaskLoopSimdDirective::CreateEmpty(Context, NumClauses,
3461                                                       CollapsedNum, Empty);
3462       break;
3463     }
3464 
3465     case STMT_OMP_PARALLEL_MASTER_TASKLOOP_DIRECTIVE: {
3466       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3467       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3468       S = OMPParallelMasterTaskLoopDirective::CreateEmpty(Context, NumClauses,
3469                                                           CollapsedNum, Empty);
3470       break;
3471     }
3472 
3473     case STMT_OMP_PARALLEL_MASTER_TASKLOOP_SIMD_DIRECTIVE: {
3474       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3475       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3476       S = OMPParallelMasterTaskLoopSimdDirective::CreateEmpty(
3477           Context, NumClauses, CollapsedNum, Empty);
3478       break;
3479     }
3480 
3481     case STMT_OMP_DISTRIBUTE_DIRECTIVE: {
3482       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3483       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3484       S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3485                                               Empty);
3486       break;
3487     }
3488 
3489     case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3490       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3491       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3492       S = OMPDistributeParallelForDirective::CreateEmpty(Context, NumClauses,
3493                                                          CollapsedNum, Empty);
3494       break;
3495     }
3496 
3497     case STMT_OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3498       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3499       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3500       S = OMPDistributeParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3501                                                              CollapsedNum,
3502                                                              Empty);
3503       break;
3504     }
3505 
3506     case STMT_OMP_DISTRIBUTE_SIMD_DIRECTIVE: {
3507       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3508       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3509       S = OMPDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3510                                                   CollapsedNum, Empty);
3511       break;
3512     }
3513 
3514     case STMT_OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE: {
3515       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3516       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3517       S = OMPTargetParallelForSimdDirective::CreateEmpty(Context, NumClauses,
3518                                                          CollapsedNum, Empty);
3519       break;
3520     }
3521 
3522     case STMT_OMP_TARGET_SIMD_DIRECTIVE: {
3523       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3524       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3525       S = OMPTargetSimdDirective::CreateEmpty(Context, NumClauses, CollapsedNum,
3526                                               Empty);
3527       break;
3528     }
3529 
3530      case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: {
3531        unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3532        unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3533        S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3534                                                     CollapsedNum, Empty);
3535        break;
3536     }
3537 
3538     case STMT_OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3539       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3540       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3541       S = OMPTeamsDistributeSimdDirective::CreateEmpty(Context, NumClauses,
3542                                                        CollapsedNum, Empty);
3543       break;
3544     }
3545 
3546     case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3547       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3548       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3549       S = OMPTeamsDistributeParallelForSimdDirective::CreateEmpty(
3550           Context, NumClauses, CollapsedNum, Empty);
3551       break;
3552     }
3553 
3554     case STMT_OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3555       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3556       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3557       S = OMPTeamsDistributeParallelForDirective::CreateEmpty(
3558           Context, NumClauses, CollapsedNum, Empty);
3559       break;
3560     }
3561 
3562     case STMT_OMP_TARGET_TEAMS_DIRECTIVE:
3563       S = OMPTargetTeamsDirective::CreateEmpty(
3564           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3565       break;
3566 
3567     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_DIRECTIVE: {
3568       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3569       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3570       S = OMPTargetTeamsDistributeDirective::CreateEmpty(Context, NumClauses,
3571                                                          CollapsedNum, Empty);
3572       break;
3573     }
3574 
3575     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_DIRECTIVE: {
3576       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3577       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3578       S = OMPTargetTeamsDistributeParallelForDirective::CreateEmpty(
3579           Context, NumClauses, CollapsedNum, Empty);
3580       break;
3581     }
3582 
3583     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE: {
3584       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3585       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3586       S = OMPTargetTeamsDistributeParallelForSimdDirective::CreateEmpty(
3587           Context, NumClauses, CollapsedNum, Empty);
3588       break;
3589     }
3590 
3591     case STMT_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE: {
3592       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3593       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3594       S = OMPTargetTeamsDistributeSimdDirective::CreateEmpty(
3595           Context, NumClauses, CollapsedNum, Empty);
3596       break;
3597     }
3598 
3599     case STMT_OMP_INTEROP_DIRECTIVE:
3600       S = OMPInteropDirective::CreateEmpty(
3601           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3602       break;
3603 
3604     case STMT_OMP_DISPATCH_DIRECTIVE:
3605       S = OMPDispatchDirective::CreateEmpty(
3606           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3607       break;
3608 
3609     case STMT_OMP_MASKED_DIRECTIVE:
3610       S = OMPMaskedDirective::CreateEmpty(
3611           Context, Record[ASTStmtReader::NumStmtFields], Empty);
3612       break;
3613 
3614     case STMT_OMP_GENERIC_LOOP_DIRECTIVE: {
3615       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3616       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3617       S = OMPGenericLoopDirective::CreateEmpty(Context, NumClauses,
3618                                                CollapsedNum, Empty);
3619       break;
3620     }
3621 
3622     case STMT_OMP_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3623       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3624       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3625       S = OMPTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3626                                                     CollapsedNum, Empty);
3627       break;
3628     }
3629 
3630     case STMT_OMP_TARGET_TEAMS_GENERIC_LOOP_DIRECTIVE: {
3631       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3632       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3633       S = OMPTargetTeamsGenericLoopDirective::CreateEmpty(Context, NumClauses,
3634                                                           CollapsedNum, Empty);
3635       break;
3636     }
3637 
3638     case STMT_OMP_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3639       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3640       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3641       S = OMPParallelGenericLoopDirective::CreateEmpty(Context, NumClauses,
3642                                                        CollapsedNum, Empty);
3643       break;
3644     }
3645 
3646     case STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE: {
3647       unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields];
3648       unsigned NumClauses = Record[ASTStmtReader::NumStmtFields + 1];
3649       S = OMPTargetParallelGenericLoopDirective::CreateEmpty(
3650           Context, NumClauses, CollapsedNum, Empty);
3651       break;
3652     }
3653 
3654     case EXPR_CXX_OPERATOR_CALL:
3655       S = CXXOperatorCallExpr::CreateEmpty(
3656           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3657           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3658       break;
3659 
3660     case EXPR_CXX_MEMBER_CALL:
3661       S = CXXMemberCallExpr::CreateEmpty(
3662           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3663           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3664       break;
3665 
3666     case EXPR_CXX_REWRITTEN_BINARY_OPERATOR:
3667       S = new (Context) CXXRewrittenBinaryOperator(Empty);
3668       break;
3669 
3670     case EXPR_CXX_CONSTRUCT:
3671       S = CXXConstructExpr::CreateEmpty(
3672           Context,
3673           /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3674       break;
3675 
3676     case EXPR_CXX_INHERITED_CTOR_INIT:
3677       S = new (Context) CXXInheritedCtorInitExpr(Empty);
3678       break;
3679 
3680     case EXPR_CXX_TEMPORARY_OBJECT:
3681       S = CXXTemporaryObjectExpr::CreateEmpty(
3682           Context,
3683           /* NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3684       break;
3685 
3686     case EXPR_CXX_STATIC_CAST:
3687       S = CXXStaticCastExpr::CreateEmpty(
3688           Context,
3689           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
3690           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
3691       break;
3692 
3693     case EXPR_CXX_DYNAMIC_CAST:
3694       S = CXXDynamicCastExpr::CreateEmpty(Context,
3695                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
3696       break;
3697 
3698     case EXPR_CXX_REINTERPRET_CAST:
3699       S = CXXReinterpretCastExpr::CreateEmpty(Context,
3700                        /*PathSize*/ Record[ASTStmtReader::NumExprFields]);
3701       break;
3702 
3703     case EXPR_CXX_CONST_CAST:
3704       S = CXXConstCastExpr::CreateEmpty(Context);
3705       break;
3706 
3707     case EXPR_CXX_ADDRSPACE_CAST:
3708       S = CXXAddrspaceCastExpr::CreateEmpty(Context);
3709       break;
3710 
3711     case EXPR_CXX_FUNCTIONAL_CAST:
3712       S = CXXFunctionalCastExpr::CreateEmpty(
3713           Context,
3714           /*PathSize*/ Record[ASTStmtReader::NumExprFields],
3715           /*HasFPFeatures*/ Record[ASTStmtReader::NumExprFields + 1]);
3716       break;
3717 
3718     case EXPR_BUILTIN_BIT_CAST:
3719       assert(Record[ASTStmtReader::NumExprFields] == 0 && "Wrong PathSize!");
3720       S = new (Context) BuiltinBitCastExpr(Empty);
3721       break;
3722 
3723     case EXPR_USER_DEFINED_LITERAL:
3724       S = UserDefinedLiteral::CreateEmpty(
3725           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3726           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3727       break;
3728 
3729     case EXPR_CXX_STD_INITIALIZER_LIST:
3730       S = new (Context) CXXStdInitializerListExpr(Empty);
3731       break;
3732 
3733     case EXPR_CXX_BOOL_LITERAL:
3734       S = new (Context) CXXBoolLiteralExpr(Empty);
3735       break;
3736 
3737     case EXPR_CXX_NULL_PTR_LITERAL:
3738       S = new (Context) CXXNullPtrLiteralExpr(Empty);
3739       break;
3740 
3741     case EXPR_CXX_TYPEID_EXPR:
3742       S = new (Context) CXXTypeidExpr(Empty, true);
3743       break;
3744 
3745     case EXPR_CXX_TYPEID_TYPE:
3746       S = new (Context) CXXTypeidExpr(Empty, false);
3747       break;
3748 
3749     case EXPR_CXX_UUIDOF_EXPR:
3750       S = new (Context) CXXUuidofExpr(Empty, true);
3751       break;
3752 
3753     case EXPR_CXX_PROPERTY_REF_EXPR:
3754       S = new (Context) MSPropertyRefExpr(Empty);
3755       break;
3756 
3757     case EXPR_CXX_PROPERTY_SUBSCRIPT_EXPR:
3758       S = new (Context) MSPropertySubscriptExpr(Empty);
3759       break;
3760 
3761     case EXPR_CXX_UUIDOF_TYPE:
3762       S = new (Context) CXXUuidofExpr(Empty, false);
3763       break;
3764 
3765     case EXPR_CXX_THIS:
3766       S = new (Context) CXXThisExpr(Empty);
3767       break;
3768 
3769     case EXPR_CXX_THROW:
3770       S = new (Context) CXXThrowExpr(Empty);
3771       break;
3772 
3773     case EXPR_CXX_DEFAULT_ARG:
3774       S = new (Context) CXXDefaultArgExpr(Empty);
3775       break;
3776 
3777     case EXPR_CXX_DEFAULT_INIT:
3778       S = new (Context) CXXDefaultInitExpr(Empty);
3779       break;
3780 
3781     case EXPR_CXX_BIND_TEMPORARY:
3782       S = new (Context) CXXBindTemporaryExpr(Empty);
3783       break;
3784 
3785     case EXPR_CXX_SCALAR_VALUE_INIT:
3786       S = new (Context) CXXScalarValueInitExpr(Empty);
3787       break;
3788 
3789     case EXPR_CXX_NEW:
3790       S = CXXNewExpr::CreateEmpty(
3791           Context,
3792           /*IsArray=*/Record[ASTStmtReader::NumExprFields],
3793           /*HasInit=*/Record[ASTStmtReader::NumExprFields + 1],
3794           /*NumPlacementArgs=*/Record[ASTStmtReader::NumExprFields + 2],
3795           /*IsParenTypeId=*/Record[ASTStmtReader::NumExprFields + 3]);
3796       break;
3797 
3798     case EXPR_CXX_DELETE:
3799       S = new (Context) CXXDeleteExpr(Empty);
3800       break;
3801 
3802     case EXPR_CXX_PSEUDO_DESTRUCTOR:
3803       S = new (Context) CXXPseudoDestructorExpr(Empty);
3804       break;
3805 
3806     case EXPR_EXPR_WITH_CLEANUPS:
3807       S = ExprWithCleanups::Create(Context, Empty,
3808                                    Record[ASTStmtReader::NumExprFields]);
3809       break;
3810 
3811     case EXPR_CXX_DEPENDENT_SCOPE_MEMBER:
3812       S = CXXDependentScopeMemberExpr::CreateEmpty(
3813           Context,
3814           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
3815           /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields + 1],
3816           /*HasFirstQualifierFoundInScope=*/
3817           Record[ASTStmtReader::NumExprFields + 2]);
3818       break;
3819 
3820     case EXPR_CXX_DEPENDENT_SCOPE_DECL_REF:
3821       S = DependentScopeDeclRefExpr::CreateEmpty(Context,
3822          /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields],
3823                   /*NumTemplateArgs=*/Record[ASTStmtReader::NumExprFields]
3824                                    ? Record[ASTStmtReader::NumExprFields + 1]
3825                                    : 0);
3826       break;
3827 
3828     case EXPR_CXX_UNRESOLVED_CONSTRUCT:
3829       S = CXXUnresolvedConstructExpr::CreateEmpty(Context,
3830                               /*NumArgs=*/Record[ASTStmtReader::NumExprFields]);
3831       break;
3832 
3833     case EXPR_CXX_UNRESOLVED_MEMBER:
3834       S = UnresolvedMemberExpr::CreateEmpty(
3835           Context,
3836           /*NumResults=*/Record[ASTStmtReader::NumExprFields],
3837           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
3838           /*NumTemplateArgs=*/
3839           Record[ASTStmtReader::NumExprFields + 1]
3840               ? Record[ASTStmtReader::NumExprFields + 2]
3841               : 0);
3842       break;
3843 
3844     case EXPR_CXX_UNRESOLVED_LOOKUP:
3845       S = UnresolvedLookupExpr::CreateEmpty(
3846           Context,
3847           /*NumResults=*/Record[ASTStmtReader::NumExprFields],
3848           /*HasTemplateKWAndArgsInfo=*/Record[ASTStmtReader::NumExprFields + 1],
3849           /*NumTemplateArgs=*/
3850           Record[ASTStmtReader::NumExprFields + 1]
3851               ? Record[ASTStmtReader::NumExprFields + 2]
3852               : 0);
3853       break;
3854 
3855     case EXPR_TYPE_TRAIT:
3856       S = TypeTraitExpr::CreateDeserialized(Context,
3857             Record[ASTStmtReader::NumExprFields]);
3858       break;
3859 
3860     case EXPR_ARRAY_TYPE_TRAIT:
3861       S = new (Context) ArrayTypeTraitExpr(Empty);
3862       break;
3863 
3864     case EXPR_CXX_EXPRESSION_TRAIT:
3865       S = new (Context) ExpressionTraitExpr(Empty);
3866       break;
3867 
3868     case EXPR_CXX_NOEXCEPT:
3869       S = new (Context) CXXNoexceptExpr(Empty);
3870       break;
3871 
3872     case EXPR_PACK_EXPANSION:
3873       S = new (Context) PackExpansionExpr(Empty);
3874       break;
3875 
3876     case EXPR_SIZEOF_PACK:
3877       S = SizeOfPackExpr::CreateDeserialized(
3878               Context,
3879               /*NumPartialArgs=*/Record[ASTStmtReader::NumExprFields]);
3880       break;
3881 
3882     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM:
3883       S = new (Context) SubstNonTypeTemplateParmExpr(Empty);
3884       break;
3885 
3886     case EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK:
3887       S = new (Context) SubstNonTypeTemplateParmPackExpr(Empty);
3888       break;
3889 
3890     case EXPR_FUNCTION_PARM_PACK:
3891       S = FunctionParmPackExpr::CreateEmpty(Context,
3892                                           Record[ASTStmtReader::NumExprFields]);
3893       break;
3894 
3895     case EXPR_MATERIALIZE_TEMPORARY:
3896       S = new (Context) MaterializeTemporaryExpr(Empty);
3897       break;
3898 
3899     case EXPR_CXX_FOLD:
3900       S = new (Context) CXXFoldExpr(Empty);
3901       break;
3902 
3903     case EXPR_OPAQUE_VALUE:
3904       S = new (Context) OpaqueValueExpr(Empty);
3905       break;
3906 
3907     case EXPR_CUDA_KERNEL_CALL:
3908       S = CUDAKernelCallExpr::CreateEmpty(
3909           Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields],
3910           /*HasFPFeatures=*/Record[ASTStmtReader::NumExprFields + 1], Empty);
3911       break;
3912 
3913     case EXPR_ASTYPE:
3914       S = new (Context) AsTypeExpr(Empty);
3915       break;
3916 
3917     case EXPR_PSEUDO_OBJECT: {
3918       unsigned numSemanticExprs = Record[ASTStmtReader::NumExprFields];
3919       S = PseudoObjectExpr::Create(Context, Empty, numSemanticExprs);
3920       break;
3921     }
3922 
3923     case EXPR_ATOMIC:
3924       S = new (Context) AtomicExpr(Empty);
3925       break;
3926 
3927     case EXPR_LAMBDA: {
3928       unsigned NumCaptures = Record[ASTStmtReader::NumExprFields];
3929       S = LambdaExpr::CreateDeserialized(Context, NumCaptures);
3930       break;
3931     }
3932 
3933     case STMT_COROUTINE_BODY: {
3934       unsigned NumParams = Record[ASTStmtReader::NumStmtFields];
3935       S = CoroutineBodyStmt::Create(Context, Empty, NumParams);
3936       break;
3937     }
3938 
3939     case STMT_CORETURN:
3940       S = new (Context) CoreturnStmt(Empty);
3941       break;
3942 
3943     case EXPR_COAWAIT:
3944       S = new (Context) CoawaitExpr(Empty);
3945       break;
3946 
3947     case EXPR_COYIELD:
3948       S = new (Context) CoyieldExpr(Empty);
3949       break;
3950 
3951     case EXPR_DEPENDENT_COAWAIT:
3952       S = new (Context) DependentCoawaitExpr(Empty);
3953       break;
3954 
3955     case EXPR_CONCEPT_SPECIALIZATION: {
3956       unsigned numTemplateArgs = Record[ASTStmtReader::NumExprFields];
3957       S = ConceptSpecializationExpr::Create(Context, Empty, numTemplateArgs);
3958       break;
3959     }
3960 
3961     case EXPR_REQUIRES:
3962       unsigned numLocalParameters = Record[ASTStmtReader::NumExprFields];
3963       unsigned numRequirement = Record[ASTStmtReader::NumExprFields + 1];
3964       S = RequiresExpr::Create(Context, Empty, numLocalParameters,
3965                                numRequirement);
3966       break;
3967     }
3968 
3969     // We hit a STMT_STOP, so we're done with this expression.
3970     if (Finished)
3971       break;
3972 
3973     ++NumStatementsRead;
3974 
3975     if (S && !IsStmtReference) {
3976       Reader.Visit(S);
3977       StmtEntries[Cursor.GetCurrentBitNo()] = S;
3978     }
3979 
3980     assert(Record.getIdx() == Record.size() &&
3981            "Invalid deserialization of statement");
3982     StmtStack.push_back(S);
3983   }
3984 Done:
3985   assert(StmtStack.size() > PrevNumStmts && "Read too many sub-stmts!");
3986   assert(StmtStack.size() == PrevNumStmts + 1 && "Extra expressions on stack!");
3987   return StmtStack.pop_back_val();
3988 }
3989