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