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