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