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