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