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