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