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