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