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