clang API Documentation

Stmt.cpp
Go to the documentation of this file.
00001 //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the Stmt class and statement subclasses.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/AST/ASTContext.h"
00015 #include "clang/AST/ASTDiagnostic.h"
00016 #include "clang/AST/ExprCXX.h"
00017 #include "clang/AST/ExprObjC.h"
00018 #include "clang/AST/Stmt.h"
00019 #include "clang/AST/StmtCXX.h"
00020 #include "clang/AST/StmtObjC.h"
00021 #include "clang/AST/StmtOpenMP.h"
00022 #include "clang/AST/Type.h"
00023 #include "clang/Basic/CharInfo.h"
00024 #include "clang/Basic/TargetInfo.h"
00025 #include "clang/Lex/Token.h"
00026 #include "llvm/ADT/StringExtras.h"
00027 #include "llvm/Support/raw_ostream.h"
00028 using namespace clang;
00029 
00030 static struct StmtClassNameTable {
00031   const char *Name;
00032   unsigned Counter;
00033   unsigned Size;
00034 } StmtClassInfo[Stmt::lastStmtConstant+1];
00035 
00036 static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
00037   static bool Initialized = false;
00038   if (Initialized)
00039     return StmtClassInfo[E];
00040 
00041   // Intialize the table on the first use.
00042   Initialized = true;
00043 #define ABSTRACT_STMT(STMT)
00044 #define STMT(CLASS, PARENT) \
00045   StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS;    \
00046   StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
00047 #include "clang/AST/StmtNodes.inc"
00048 
00049   return StmtClassInfo[E];
00050 }
00051 
00052 void *Stmt::operator new(size_t bytes, const ASTContext& C,
00053                          unsigned alignment) {
00054   return ::operator new(bytes, C, alignment);
00055 }
00056 
00057 const char *Stmt::getStmtClassName() const {
00058   return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
00059 }
00060 
00061 void Stmt::PrintStats() {
00062   // Ensure the table is primed.
00063   getStmtInfoTableEntry(Stmt::NullStmtClass);
00064 
00065   unsigned sum = 0;
00066   llvm::errs() << "\n*** Stmt/Expr Stats:\n";
00067   for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
00068     if (StmtClassInfo[i].Name == nullptr) continue;
00069     sum += StmtClassInfo[i].Counter;
00070   }
00071   llvm::errs() << "  " << sum << " stmts/exprs total.\n";
00072   sum = 0;
00073   for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
00074     if (StmtClassInfo[i].Name == nullptr) continue;
00075     if (StmtClassInfo[i].Counter == 0) continue;
00076     llvm::errs() << "    " << StmtClassInfo[i].Counter << " "
00077                  << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
00078                  << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
00079                  << " bytes)\n";
00080     sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
00081   }
00082 
00083   llvm::errs() << "Total bytes = " << sum << "\n";
00084 }
00085 
00086 void Stmt::addStmtClass(StmtClass s) {
00087   ++getStmtInfoTableEntry(s).Counter;
00088 }
00089 
00090 bool Stmt::StatisticsEnabled = false;
00091 void Stmt::EnableStatistics() {
00092   StatisticsEnabled = true;
00093 }
00094 
00095 Stmt *Stmt::IgnoreImplicit() {
00096   Stmt *s = this;
00097 
00098   if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s))
00099     s = ewc->getSubExpr();
00100 
00101   while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s))
00102     s = ice->getSubExpr();
00103 
00104   return s;
00105 }
00106 
00107 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
00108 /// stmt at the top, if \a IgnoreCaptured is true.
00109 Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
00110   Stmt *S = this;
00111   if (IgnoreCaptured)
00112     if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
00113       S = CapS->getCapturedStmt();
00114   while (true) {
00115     if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
00116       S = AS->getSubStmt();
00117     else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
00118       if (CS->size() != 1)
00119         break;
00120       S = CS->body_back();
00121     } else
00122       break;
00123   }
00124   return S;
00125 }
00126 
00127 /// \brief Strip off all label-like statements.
00128 ///
00129 /// This will strip off label statements, case statements, attributed
00130 /// statements and default statements recursively.
00131 const Stmt *Stmt::stripLabelLikeStatements() const {
00132   const Stmt *S = this;
00133   while (true) {
00134     if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
00135       S = LS->getSubStmt();
00136     else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
00137       S = SC->getSubStmt();
00138     else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
00139       S = AS->getSubStmt();
00140     else
00141       return S;
00142   }
00143 }
00144 
00145 namespace {
00146   struct good {};
00147   struct bad {};
00148 
00149   // These silly little functions have to be static inline to suppress
00150   // unused warnings, and they have to be defined to suppress other
00151   // warnings.
00152   static inline good is_good(good) { return good(); }
00153 
00154   typedef Stmt::child_range children_t();
00155   template <class T> good implements_children(children_t T::*) {
00156     return good();
00157   }
00158   LLVM_ATTRIBUTE_UNUSED
00159   static inline bad implements_children(children_t Stmt::*) {
00160     return bad();
00161   }
00162 
00163   typedef SourceLocation getLocStart_t() const;
00164   template <class T> good implements_getLocStart(getLocStart_t T::*) {
00165     return good();
00166   }
00167   LLVM_ATTRIBUTE_UNUSED
00168   static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
00169     return bad();
00170   }
00171 
00172   typedef SourceLocation getLocEnd_t() const;
00173   template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
00174     return good();
00175   }
00176   LLVM_ATTRIBUTE_UNUSED
00177   static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
00178     return bad();
00179   }
00180 
00181 #define ASSERT_IMPLEMENTS_children(type) \
00182   (void) is_good(implements_children(&type::children))
00183 #define ASSERT_IMPLEMENTS_getLocStart(type) \
00184   (void) is_good(implements_getLocStart(&type::getLocStart))
00185 #define ASSERT_IMPLEMENTS_getLocEnd(type) \
00186   (void) is_good(implements_getLocEnd(&type::getLocEnd))
00187 }
00188 
00189 /// Check whether the various Stmt classes implement their member
00190 /// functions.
00191 LLVM_ATTRIBUTE_UNUSED
00192 static inline void check_implementations() {
00193 #define ABSTRACT_STMT(type)
00194 #define STMT(type, base) \
00195   ASSERT_IMPLEMENTS_children(type); \
00196   ASSERT_IMPLEMENTS_getLocStart(type); \
00197   ASSERT_IMPLEMENTS_getLocEnd(type);
00198 #include "clang/AST/StmtNodes.inc"
00199 }
00200 
00201 Stmt::child_range Stmt::children() {
00202   switch (getStmtClass()) {
00203   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
00204 #define ABSTRACT_STMT(type)
00205 #define STMT(type, base) \
00206   case Stmt::type##Class: \
00207     return static_cast<type*>(this)->children();
00208 #include "clang/AST/StmtNodes.inc"
00209   }
00210   llvm_unreachable("unknown statement kind!");
00211 }
00212 
00213 // Amusing macro metaprogramming hack: check whether a class provides
00214 // a more specific implementation of getSourceRange.
00215 //
00216 // See also Expr.cpp:getExprLoc().
00217 namespace {
00218   /// This implementation is used when a class provides a custom
00219   /// implementation of getSourceRange.
00220   template <class S, class T>
00221   SourceRange getSourceRangeImpl(const Stmt *stmt,
00222                                  SourceRange (T::*v)() const) {
00223     return static_cast<const S*>(stmt)->getSourceRange();
00224   }
00225 
00226   /// This implementation is used when a class doesn't provide a custom
00227   /// implementation of getSourceRange.  Overload resolution should pick it over
00228   /// the implementation above because it's more specialized according to
00229   /// function template partial ordering.
00230   template <class S>
00231   SourceRange getSourceRangeImpl(const Stmt *stmt,
00232                                  SourceRange (Stmt::*v)() const) {
00233     return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
00234                        static_cast<const S*>(stmt)->getLocEnd());
00235   }
00236 }
00237 
00238 SourceRange Stmt::getSourceRange() const {
00239   switch (getStmtClass()) {
00240   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
00241 #define ABSTRACT_STMT(type)
00242 #define STMT(type, base) \
00243   case Stmt::type##Class: \
00244     return getSourceRangeImpl<type>(this, &type::getSourceRange);
00245 #include "clang/AST/StmtNodes.inc"
00246   }
00247   llvm_unreachable("unknown statement kind!");
00248 }
00249 
00250 SourceLocation Stmt::getLocStart() const {
00251 //  llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
00252   switch (getStmtClass()) {
00253   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
00254 #define ABSTRACT_STMT(type)
00255 #define STMT(type, base) \
00256   case Stmt::type##Class: \
00257     return static_cast<const type*>(this)->getLocStart();
00258 #include "clang/AST/StmtNodes.inc"
00259   }
00260   llvm_unreachable("unknown statement kind");
00261 }
00262 
00263 SourceLocation Stmt::getLocEnd() const {
00264   switch (getStmtClass()) {
00265   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
00266 #define ABSTRACT_STMT(type)
00267 #define STMT(type, base) \
00268   case Stmt::type##Class: \
00269     return static_cast<const type*>(this)->getLocEnd();
00270 #include "clang/AST/StmtNodes.inc"
00271   }
00272   llvm_unreachable("unknown statement kind");
00273 }
00274 
00275 CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
00276                            SourceLocation LB, SourceLocation RB)
00277   : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
00278   CompoundStmtBits.NumStmts = Stmts.size();
00279   assert(CompoundStmtBits.NumStmts == Stmts.size() &&
00280          "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
00281 
00282   if (Stmts.size() == 0) {
00283     Body = nullptr;
00284     return;
00285   }
00286 
00287   Body = new (C) Stmt*[Stmts.size()];
00288   std::copy(Stmts.begin(), Stmts.end(), Body);
00289 }
00290 
00291 void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts,
00292                             unsigned NumStmts) {
00293   if (this->Body)
00294     C.Deallocate(Body);
00295   this->CompoundStmtBits.NumStmts = NumStmts;
00296 
00297   Body = new (C) Stmt*[NumStmts];
00298   memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
00299 }
00300 
00301 const char *LabelStmt::getName() const {
00302   return getDecl()->getIdentifier()->getNameStart();
00303 }
00304 
00305 AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
00306                                        ArrayRef<const Attr*> Attrs,
00307                                        Stmt *SubStmt) {
00308   assert(!Attrs.empty() && "Attrs should not be empty");
00309   void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
00310                          llvm::alignOf<AttributedStmt>());
00311   return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
00312 }
00313 
00314 AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
00315                                             unsigned NumAttrs) {
00316   assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
00317   void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
00318                          llvm::alignOf<AttributedStmt>());
00319   return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
00320 }
00321 
00322 std::string AsmStmt::generateAsmString(const ASTContext &C) const {
00323   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00324     return gccAsmStmt->generateAsmString(C);
00325   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00326     return msAsmStmt->generateAsmString(C);
00327   llvm_unreachable("unknown asm statement kind!");
00328 }
00329 
00330 StringRef AsmStmt::getOutputConstraint(unsigned i) const {
00331   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00332     return gccAsmStmt->getOutputConstraint(i);
00333   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00334     return msAsmStmt->getOutputConstraint(i);
00335   llvm_unreachable("unknown asm statement kind!");
00336 }
00337 
00338 const Expr *AsmStmt::getOutputExpr(unsigned i) const {
00339   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00340     return gccAsmStmt->getOutputExpr(i);
00341   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00342     return msAsmStmt->getOutputExpr(i);
00343   llvm_unreachable("unknown asm statement kind!");
00344 }
00345 
00346 StringRef AsmStmt::getInputConstraint(unsigned i) const {
00347   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00348     return gccAsmStmt->getInputConstraint(i);
00349   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00350     return msAsmStmt->getInputConstraint(i);
00351   llvm_unreachable("unknown asm statement kind!");
00352 }
00353 
00354 const Expr *AsmStmt::getInputExpr(unsigned i) const {
00355   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00356     return gccAsmStmt->getInputExpr(i);
00357   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00358     return msAsmStmt->getInputExpr(i);
00359   llvm_unreachable("unknown asm statement kind!");
00360 }
00361 
00362 StringRef AsmStmt::getClobber(unsigned i) const {
00363   if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
00364     return gccAsmStmt->getClobber(i);
00365   if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
00366     return msAsmStmt->getClobber(i);
00367   llvm_unreachable("unknown asm statement kind!");
00368 }
00369 
00370 /// getNumPlusOperands - Return the number of output operands that have a "+"
00371 /// constraint.
00372 unsigned AsmStmt::getNumPlusOperands() const {
00373   unsigned Res = 0;
00374   for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
00375     if (isOutputPlusConstraint(i))
00376       ++Res;
00377   return Res;
00378 }
00379 
00380 char GCCAsmStmt::AsmStringPiece::getModifier() const {
00381   assert(isOperand() && "Only Operands can have modifiers.");
00382   return isLetter(Str[0]) ? Str[0] : '\0';
00383 }
00384 
00385 StringRef GCCAsmStmt::getClobber(unsigned i) const {
00386   return getClobberStringLiteral(i)->getString();
00387 }
00388 
00389 Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
00390   return cast<Expr>(Exprs[i]);
00391 }
00392 
00393 /// getOutputConstraint - Return the constraint string for the specified
00394 /// output operand.  All output constraints are known to be non-empty (either
00395 /// '=' or '+').
00396 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
00397   return getOutputConstraintLiteral(i)->getString();
00398 }
00399 
00400 Expr *GCCAsmStmt::getInputExpr(unsigned i) {
00401   return cast<Expr>(Exprs[i + NumOutputs]);
00402 }
00403 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
00404   Exprs[i + NumOutputs] = E;
00405 }
00406 
00407 /// getInputConstraint - Return the specified input constraint.  Unlike output
00408 /// constraints, these can be empty.
00409 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
00410   return getInputConstraintLiteral(i)->getString();
00411 }
00412 
00413 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
00414                                                 IdentifierInfo **Names,
00415                                                 StringLiteral **Constraints,
00416                                                 Stmt **Exprs,
00417                                                 unsigned NumOutputs,
00418                                                 unsigned NumInputs,
00419                                                 StringLiteral **Clobbers,
00420                                                 unsigned NumClobbers) {
00421   this->NumOutputs = NumOutputs;
00422   this->NumInputs = NumInputs;
00423   this->NumClobbers = NumClobbers;
00424 
00425   unsigned NumExprs = NumOutputs + NumInputs;
00426 
00427   C.Deallocate(this->Names);
00428   this->Names = new (C) IdentifierInfo*[NumExprs];
00429   std::copy(Names, Names + NumExprs, this->Names);
00430 
00431   C.Deallocate(this->Exprs);
00432   this->Exprs = new (C) Stmt*[NumExprs];
00433   std::copy(Exprs, Exprs + NumExprs, this->Exprs);
00434 
00435   C.Deallocate(this->Constraints);
00436   this->Constraints = new (C) StringLiteral*[NumExprs];
00437   std::copy(Constraints, Constraints + NumExprs, this->Constraints);
00438 
00439   C.Deallocate(this->Clobbers);
00440   this->Clobbers = new (C) StringLiteral*[NumClobbers];
00441   std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
00442 }
00443 
00444 /// getNamedOperand - Given a symbolic operand reference like %[foo],
00445 /// translate this into a numeric value needed to reference the same operand.
00446 /// This returns -1 if the operand name is invalid.
00447 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
00448   unsigned NumPlusOperands = 0;
00449 
00450   // Check if this is an output operand.
00451   for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
00452     if (getOutputName(i) == SymbolicName)
00453       return i;
00454   }
00455 
00456   for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
00457     if (getInputName(i) == SymbolicName)
00458       return getNumOutputs() + NumPlusOperands + i;
00459 
00460   // Not found.
00461   return -1;
00462 }
00463 
00464 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
00465 /// it into pieces.  If the asm string is erroneous, emit errors and return
00466 /// true, otherwise return false.
00467 unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
00468                                 const ASTContext &C, unsigned &DiagOffs) const {
00469   StringRef Str = getAsmString()->getString();
00470   const char *StrStart = Str.begin();
00471   const char *StrEnd = Str.end();
00472   const char *CurPtr = StrStart;
00473 
00474   // "Simple" inline asms have no constraints or operands, just convert the asm
00475   // string to escape $'s.
00476   if (isSimple()) {
00477     std::string Result;
00478     for (; CurPtr != StrEnd; ++CurPtr) {
00479       switch (*CurPtr) {
00480       case '$':
00481         Result += "$$";
00482         break;
00483       default:
00484         Result += *CurPtr;
00485         break;
00486       }
00487     }
00488     Pieces.push_back(AsmStringPiece(Result));
00489     return 0;
00490   }
00491 
00492   // CurStringPiece - The current string that we are building up as we scan the
00493   // asm string.
00494   std::string CurStringPiece;
00495 
00496   bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
00497 
00498   while (1) {
00499     // Done with the string?
00500     if (CurPtr == StrEnd) {
00501       if (!CurStringPiece.empty())
00502         Pieces.push_back(AsmStringPiece(CurStringPiece));
00503       return 0;
00504     }
00505 
00506     char CurChar = *CurPtr++;
00507     switch (CurChar) {
00508     case '$': CurStringPiece += "$$"; continue;
00509     case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
00510     case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
00511     case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
00512     case '%':
00513       break;
00514     default:
00515       CurStringPiece += CurChar;
00516       continue;
00517     }
00518 
00519     // Escaped "%" character in asm string.
00520     if (CurPtr == StrEnd) {
00521       // % at end of string is invalid (no escape).
00522       DiagOffs = CurPtr-StrStart-1;
00523       return diag::err_asm_invalid_escape;
00524     }
00525 
00526     char EscapedChar = *CurPtr++;
00527     if (EscapedChar == '%') {  // %% -> %
00528       // Escaped percentage sign.
00529       CurStringPiece += '%';
00530       continue;
00531     }
00532 
00533     if (EscapedChar == '=') {  // %= -> Generate an unique ID.
00534       CurStringPiece += "${:uid}";
00535       continue;
00536     }
00537 
00538     // Otherwise, we have an operand.  If we have accumulated a string so far,
00539     // add it to the Pieces list.
00540     if (!CurStringPiece.empty()) {
00541       Pieces.push_back(AsmStringPiece(CurStringPiece));
00542       CurStringPiece.clear();
00543     }
00544 
00545     // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
00546     // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
00547 
00548     const char *Begin = CurPtr - 1; // Points to the character following '%'.
00549     const char *Percent = Begin - 1; // Points to '%'.
00550 
00551     if (isLetter(EscapedChar)) {
00552       if (CurPtr == StrEnd) { // Premature end.
00553         DiagOffs = CurPtr-StrStart-1;
00554         return diag::err_asm_invalid_escape;
00555       }
00556       EscapedChar = *CurPtr++;
00557     }
00558 
00559     const TargetInfo &TI = C.getTargetInfo();
00560     const SourceManager &SM = C.getSourceManager();
00561     const LangOptions &LO = C.getLangOpts();
00562 
00563     // Handle operands that don't have asmSymbolicName (e.g., %x4).
00564     if (isDigit(EscapedChar)) {
00565       // %n - Assembler operand n
00566       unsigned N = 0;
00567 
00568       --CurPtr;
00569       while (CurPtr != StrEnd && isDigit(*CurPtr))
00570         N = N*10 + ((*CurPtr++)-'0');
00571 
00572       unsigned NumOperands =
00573         getNumOutputs() + getNumPlusOperands() + getNumInputs();
00574       if (N >= NumOperands) {
00575         DiagOffs = CurPtr-StrStart-1;
00576         return diag::err_asm_invalid_operand_number;
00577       }
00578 
00579       // Str contains "x4" (Operand without the leading %).
00580       std::string Str(Begin, CurPtr - Begin);
00581 
00582       // (BeginLoc, EndLoc) represents the range of the operand we are currently
00583       // processing. Unlike Str, the range includes the leading '%'.
00584       SourceLocation BeginLoc =
00585           getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
00586       SourceLocation EndLoc =
00587           getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
00588 
00589       Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc));
00590       continue;
00591     }
00592 
00593     // Handle operands that have asmSymbolicName (e.g., %x[foo]).
00594     if (EscapedChar == '[') {
00595       DiagOffs = CurPtr-StrStart-1;
00596 
00597       // Find the ']'.
00598       const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
00599       if (NameEnd == nullptr)
00600         return diag::err_asm_unterminated_symbolic_operand_name;
00601       if (NameEnd == CurPtr)
00602         return diag::err_asm_empty_symbolic_operand_name;
00603 
00604       StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
00605 
00606       int N = getNamedOperand(SymbolicName);
00607       if (N == -1) {
00608         // Verify that an operand with that name exists.
00609         DiagOffs = CurPtr-StrStart;
00610         return diag::err_asm_unknown_symbolic_operand_name;
00611       }
00612 
00613       // Str contains "x[foo]" (Operand without the leading %).
00614       std::string Str(Begin, NameEnd + 1 - Begin);
00615 
00616       // (BeginLoc, EndLoc) represents the range of the operand we are currently
00617       // processing. Unlike Str, the range includes the leading '%'.
00618       SourceLocation BeginLoc =
00619           getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
00620       SourceLocation EndLoc =
00621           getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
00622 
00623       Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc));
00624 
00625       CurPtr = NameEnd+1;
00626       continue;
00627     }
00628 
00629     DiagOffs = CurPtr-StrStart-1;
00630     return diag::err_asm_invalid_escape;
00631   }
00632 }
00633 
00634 /// Assemble final IR asm string (GCC-style).
00635 std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
00636   // Analyze the asm string to decompose it into its pieces.  We know that Sema
00637   // has already done this, so it is guaranteed to be successful.
00638   SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
00639   unsigned DiagOffs;
00640   AnalyzeAsmString(Pieces, C, DiagOffs);
00641 
00642   std::string AsmString;
00643   for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
00644     if (Pieces[i].isString())
00645       AsmString += Pieces[i].getString();
00646     else if (Pieces[i].getModifier() == '\0')
00647       AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
00648     else
00649       AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
00650                    Pieces[i].getModifier() + '}';
00651   }
00652   return AsmString;
00653 }
00654 
00655 /// Assemble final IR asm string (MS-style).
00656 std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
00657   // FIXME: This needs to be translated into the IR string representation.
00658   return AsmStr;
00659 }
00660 
00661 Expr *MSAsmStmt::getOutputExpr(unsigned i) {
00662   return cast<Expr>(Exprs[i]);
00663 }
00664 
00665 Expr *MSAsmStmt::getInputExpr(unsigned i) {
00666   return cast<Expr>(Exprs[i + NumOutputs]);
00667 }
00668 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
00669   Exprs[i + NumOutputs] = E;
00670 }
00671 
00672 QualType CXXCatchStmt::getCaughtType() const {
00673   if (ExceptionDecl)
00674     return ExceptionDecl->getType();
00675   return QualType();
00676 }
00677 
00678 //===----------------------------------------------------------------------===//
00679 // Constructors
00680 //===----------------------------------------------------------------------===//
00681 
00682 GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
00683                        bool issimple, bool isvolatile, unsigned numoutputs,
00684                        unsigned numinputs, IdentifierInfo **names,
00685                        StringLiteral **constraints, Expr **exprs,
00686                        StringLiteral *asmstr, unsigned numclobbers,
00687                        StringLiteral **clobbers, SourceLocation rparenloc)
00688   : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
00689             numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
00690 
00691   unsigned NumExprs = NumOutputs + NumInputs;
00692 
00693   Names = new (C) IdentifierInfo*[NumExprs];
00694   std::copy(names, names + NumExprs, Names);
00695 
00696   Exprs = new (C) Stmt*[NumExprs];
00697   std::copy(exprs, exprs + NumExprs, Exprs);
00698 
00699   Constraints = new (C) StringLiteral*[NumExprs];
00700   std::copy(constraints, constraints + NumExprs, Constraints);
00701 
00702   Clobbers = new (C) StringLiteral*[NumClobbers];
00703   std::copy(clobbers, clobbers + NumClobbers, Clobbers);
00704 }
00705 
00706 MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
00707                      SourceLocation lbraceloc, bool issimple, bool isvolatile,
00708                      ArrayRef<Token> asmtoks, unsigned numoutputs,
00709                      unsigned numinputs,
00710                      ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
00711                      StringRef asmstr, ArrayRef<StringRef> clobbers,
00712                      SourceLocation endloc)
00713   : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
00714             numinputs, clobbers.size()), LBraceLoc(lbraceloc),
00715             EndLoc(endloc), NumAsmToks(asmtoks.size()) {
00716 
00717   initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
00718 }
00719 
00720 static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
00721   size_t size = str.size();
00722   char *buffer = new (C) char[size];
00723   memcpy(buffer, str.data(), size);
00724   return StringRef(buffer, size);
00725 }
00726 
00727 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
00728                            ArrayRef<Token> asmtoks,
00729                            ArrayRef<StringRef> constraints,
00730                            ArrayRef<Expr*> exprs,
00731                            ArrayRef<StringRef> clobbers) {
00732   assert(NumAsmToks == asmtoks.size());
00733   assert(NumClobbers == clobbers.size());
00734 
00735   unsigned NumExprs = exprs.size();
00736   assert(NumExprs == NumOutputs + NumInputs);
00737   assert(NumExprs == constraints.size());
00738 
00739   AsmStr = copyIntoContext(C, asmstr);
00740 
00741   Exprs = new (C) Stmt*[NumExprs];
00742   for (unsigned i = 0, e = NumExprs; i != e; ++i)
00743     Exprs[i] = exprs[i];
00744 
00745   AsmToks = new (C) Token[NumAsmToks];
00746   for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
00747     AsmToks[i] = asmtoks[i];
00748 
00749   Constraints = new (C) StringRef[NumExprs];
00750   for (unsigned i = 0, e = NumExprs; i != e; ++i) {
00751     Constraints[i] = copyIntoContext(C, constraints[i]);
00752   }
00753 
00754   Clobbers = new (C) StringRef[NumClobbers];
00755   for (unsigned i = 0, e = NumClobbers; i != e; ++i) {
00756     // FIXME: Avoid the allocation/copy if at all possible.
00757     Clobbers[i] = copyIntoContext(C, clobbers[i]);
00758   }
00759 }
00760 
00761 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
00762                                              Stmt *Body,  SourceLocation FCL,
00763                                              SourceLocation RPL)
00764 : Stmt(ObjCForCollectionStmtClass) {
00765   SubExprs[ELEM] = Elem;
00766   SubExprs[COLLECTION] = Collect;
00767   SubExprs[BODY] = Body;
00768   ForLoc = FCL;
00769   RParenLoc = RPL;
00770 }
00771 
00772 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
00773                              Stmt **CatchStmts, unsigned NumCatchStmts,
00774                              Stmt *atFinallyStmt)
00775   : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
00776     NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) {
00777   Stmt **Stmts = getStmts();
00778   Stmts[0] = atTryStmt;
00779   for (unsigned I = 0; I != NumCatchStmts; ++I)
00780     Stmts[I + 1] = CatchStmts[I];
00781 
00782   if (HasFinally)
00783     Stmts[NumCatchStmts + 1] = atFinallyStmt;
00784 }
00785 
00786 ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
00787                                      SourceLocation atTryLoc,
00788                                      Stmt *atTryStmt,
00789                                      Stmt **CatchStmts,
00790                                      unsigned NumCatchStmts,
00791                                      Stmt *atFinallyStmt) {
00792   unsigned Size = sizeof(ObjCAtTryStmt) +
00793     (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
00794   void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
00795   return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
00796                                  atFinallyStmt);
00797 }
00798 
00799 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
00800                                           unsigned NumCatchStmts,
00801                                           bool HasFinally) {
00802   unsigned Size = sizeof(ObjCAtTryStmt) +
00803     (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
00804   void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
00805   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
00806 }
00807 
00808 SourceLocation ObjCAtTryStmt::getLocEnd() const {
00809   if (HasFinally)
00810     return getFinallyStmt()->getLocEnd();
00811   if (NumCatchStmts)
00812     return getCatchStmt(NumCatchStmts - 1)->getLocEnd();
00813   return getTryBody()->getLocEnd();
00814 }
00815 
00816 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
00817                                Stmt *tryBlock, ArrayRef<Stmt*> handlers) {
00818   std::size_t Size = sizeof(CXXTryStmt);
00819   Size += ((handlers.size() + 1) * sizeof(Stmt));
00820 
00821   void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
00822   return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
00823 }
00824 
00825 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
00826                                unsigned numHandlers) {
00827   std::size_t Size = sizeof(CXXTryStmt);
00828   Size += ((numHandlers + 1) * sizeof(Stmt));
00829 
00830   void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
00831   return new (Mem) CXXTryStmt(Empty, numHandlers);
00832 }
00833 
00834 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
00835                        ArrayRef<Stmt*> handlers)
00836   : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
00837   Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
00838   Stmts[0] = tryBlock;
00839   std::copy(handlers.begin(), handlers.end(), Stmts + 1);
00840 }
00841 
00842 CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
00843                                  Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
00844                                  Stmt *Body, SourceLocation FL,
00845                                  SourceLocation CL, SourceLocation RPL)
00846   : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
00847   SubExprs[RANGE] = Range;
00848   SubExprs[BEGINEND] = BeginEndStmt;
00849   SubExprs[COND] = Cond;
00850   SubExprs[INC] = Inc;
00851   SubExprs[LOOPVAR] = LoopVar;
00852   SubExprs[BODY] = Body;
00853 }
00854 
00855 Expr *CXXForRangeStmt::getRangeInit() {
00856   DeclStmt *RangeStmt = getRangeStmt();
00857   VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
00858   assert(RangeDecl && "for-range should have a single var decl");
00859   return RangeDecl->getInit();
00860 }
00861 
00862 const Expr *CXXForRangeStmt::getRangeInit() const {
00863   return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
00864 }
00865 
00866 VarDecl *CXXForRangeStmt::getLoopVariable() {
00867   Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
00868   assert(LV && "No loop variable in CXXForRangeStmt");
00869   return cast<VarDecl>(LV);
00870 }
00871 
00872 const VarDecl *CXXForRangeStmt::getLoopVariable() const {
00873   return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
00874 }
00875 
00876 IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
00877                Stmt *then, SourceLocation EL, Stmt *elsev)
00878   : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
00879 {
00880   setConditionVariable(C, var);
00881   SubExprs[COND] = cond;
00882   SubExprs[THEN] = then;
00883   SubExprs[ELSE] = elsev;
00884 }
00885 
00886 VarDecl *IfStmt::getConditionVariable() const {
00887   if (!SubExprs[VAR])
00888     return nullptr;
00889 
00890   DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
00891   return cast<VarDecl>(DS->getSingleDecl());
00892 }
00893 
00894 void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
00895   if (!V) {
00896     SubExprs[VAR] = nullptr;
00897     return;
00898   }
00899 
00900   SourceRange VarRange = V->getSourceRange();
00901   SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
00902                                    VarRange.getEnd());
00903 }
00904 
00905 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
00906                  Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
00907                  SourceLocation RP)
00908   : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
00909 {
00910   SubExprs[INIT] = Init;
00911   setConditionVariable(C, condVar);
00912   SubExprs[COND] = Cond;
00913   SubExprs[INC] = Inc;
00914   SubExprs[BODY] = Body;
00915 }
00916 
00917 VarDecl *ForStmt::getConditionVariable() const {
00918   if (!SubExprs[CONDVAR])
00919     return nullptr;
00920 
00921   DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
00922   return cast<VarDecl>(DS->getSingleDecl());
00923 }
00924 
00925 void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
00926   if (!V) {
00927     SubExprs[CONDVAR] = nullptr;
00928     return;
00929   }
00930 
00931   SourceRange VarRange = V->getSourceRange();
00932   SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
00933                                        VarRange.getEnd());
00934 }
00935 
00936 SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
00937   : Stmt(SwitchStmtClass), FirstCase(nullptr), AllEnumCasesCovered(0)
00938 {
00939   setConditionVariable(C, Var);
00940   SubExprs[COND] = cond;
00941   SubExprs[BODY] = nullptr;
00942 }
00943 
00944 VarDecl *SwitchStmt::getConditionVariable() const {
00945   if (!SubExprs[VAR])
00946     return nullptr;
00947 
00948   DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
00949   return cast<VarDecl>(DS->getSingleDecl());
00950 }
00951 
00952 void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
00953   if (!V) {
00954     SubExprs[VAR] = nullptr;
00955     return;
00956   }
00957 
00958   SourceRange VarRange = V->getSourceRange();
00959   SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
00960                                    VarRange.getEnd());
00961 }
00962 
00963 Stmt *SwitchCase::getSubStmt() {
00964   if (isa<CaseStmt>(this))
00965     return cast<CaseStmt>(this)->getSubStmt();
00966   return cast<DefaultStmt>(this)->getSubStmt();
00967 }
00968 
00969 WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
00970                      SourceLocation WL)
00971   : Stmt(WhileStmtClass) {
00972   setConditionVariable(C, Var);
00973   SubExprs[COND] = cond;
00974   SubExprs[BODY] = body;
00975   WhileLoc = WL;
00976 }
00977 
00978 VarDecl *WhileStmt::getConditionVariable() const {
00979   if (!SubExprs[VAR])
00980     return nullptr;
00981 
00982   DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
00983   return cast<VarDecl>(DS->getSingleDecl());
00984 }
00985 
00986 void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
00987   if (!V) {
00988     SubExprs[VAR] = nullptr;
00989     return;
00990   }
00991 
00992   SourceRange VarRange = V->getSourceRange();
00993   SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
00994                                    VarRange.getEnd());
00995 }
00996 
00997 // IndirectGotoStmt
00998 LabelDecl *IndirectGotoStmt::getConstantTarget() {
00999   if (AddrLabelExpr *E =
01000         dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
01001     return E->getLabel();
01002   return nullptr;
01003 }
01004 
01005 // ReturnStmt
01006 const Expr* ReturnStmt::getRetValue() const {
01007   return cast_or_null<Expr>(RetExpr);
01008 }
01009 Expr* ReturnStmt::getRetValue() {
01010   return cast_or_null<Expr>(RetExpr);
01011 }
01012 
01013 SEHTryStmt::SEHTryStmt(bool IsCXXTry,
01014                        SourceLocation TryLoc,
01015                        Stmt *TryBlock,
01016                        Stmt *Handler)
01017   : Stmt(SEHTryStmtClass),
01018     IsCXXTry(IsCXXTry),
01019     TryLoc(TryLoc)
01020 {
01021   Children[TRY]     = TryBlock;
01022   Children[HANDLER] = Handler;
01023 }
01024 
01025 SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
01026                                SourceLocation TryLoc, Stmt *TryBlock,
01027                                Stmt *Handler) {
01028   return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
01029 }
01030 
01031 SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
01032   return dyn_cast<SEHExceptStmt>(getHandler());
01033 }
01034 
01035 SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
01036   return dyn_cast<SEHFinallyStmt>(getHandler());
01037 }
01038 
01039 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
01040                              Expr *FilterExpr,
01041                              Stmt *Block)
01042   : Stmt(SEHExceptStmtClass),
01043     Loc(Loc)
01044 {
01045   Children[FILTER_EXPR] = FilterExpr;
01046   Children[BLOCK]       = Block;
01047 }
01048 
01049 SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
01050                                      Expr *FilterExpr, Stmt *Block) {
01051   return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
01052 }
01053 
01054 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
01055                                Stmt *Block)
01056   : Stmt(SEHFinallyStmtClass),
01057     Loc(Loc),
01058     Block(Block)
01059 {}
01060 
01061 SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
01062                                        Stmt *Block) {
01063   return new(C)SEHFinallyStmt(Loc,Block);
01064 }
01065 
01066 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
01067   unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
01068 
01069   // Offset of the first Capture object.
01070   unsigned FirstCaptureOffset =
01071     llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
01072 
01073   return reinterpret_cast<Capture *>(
01074       reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
01075       + FirstCaptureOffset);
01076 }
01077 
01078 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
01079                            ArrayRef<Capture> Captures,
01080                            ArrayRef<Expr *> CaptureInits,
01081                            CapturedDecl *CD,
01082                            RecordDecl *RD)
01083   : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
01084     CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
01085   assert( S && "null captured statement");
01086   assert(CD && "null captured declaration for captured statement");
01087   assert(RD && "null record declaration for captured statement");
01088 
01089   // Copy initialization expressions.
01090   Stmt **Stored = getStoredStmts();
01091   for (unsigned I = 0, N = NumCaptures; I != N; ++I)
01092     *Stored++ = CaptureInits[I];
01093 
01094   // Copy the statement being captured.
01095   *Stored = S;
01096 
01097   // Copy all Capture objects.
01098   Capture *Buffer = getStoredCaptures();
01099   std::copy(Captures.begin(), Captures.end(), Buffer);
01100 }
01101 
01102 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
01103   : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
01104     CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
01105   getStoredStmts()[NumCaptures] = nullptr;
01106 }
01107 
01108 CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
01109                                    CapturedRegionKind Kind,
01110                                    ArrayRef<Capture> Captures,
01111                                    ArrayRef<Expr *> CaptureInits,
01112                                    CapturedDecl *CD,
01113                                    RecordDecl *RD) {
01114   // The layout is
01115   //
01116   // -----------------------------------------------------------
01117   // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
01118   // ----------------^-------------------^----------------------
01119   //                 getStoredStmts()    getStoredCaptures()
01120   //
01121   // where S is the statement being captured.
01122   //
01123   assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
01124 
01125   unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
01126   if (!Captures.empty()) {
01127     // Realign for the following Capture array.
01128     Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
01129     Size += sizeof(Capture) * Captures.size();
01130   }
01131 
01132   void *Mem = Context.Allocate(Size);
01133   return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
01134 }
01135 
01136 CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
01137                                                unsigned NumCaptures) {
01138   unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
01139   if (NumCaptures > 0) {
01140     // Realign for the following Capture array.
01141     Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
01142     Size += sizeof(Capture) * NumCaptures;
01143   }
01144 
01145   void *Mem = Context.Allocate(Size);
01146   return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
01147 }
01148 
01149 Stmt::child_range CapturedStmt::children() {
01150   // Children are captured field initilizers.
01151   return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
01152 }
01153 
01154 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
01155   for (const auto &I : captures()) {
01156     if (!I.capturesVariable())
01157       continue;
01158 
01159     // This does not handle variable redeclarations. This should be
01160     // extended to capture variables with redeclarations, for example
01161     // a thread-private variable in OpenMP.
01162     if (I.getCapturedVar() == Var)
01163       return true;
01164   }
01165 
01166   return false;
01167 }
01168 
01169 StmtRange OMPClause::children() {
01170   switch(getClauseKind()) {
01171   default : break;
01172 #define OPENMP_CLAUSE(Name, Class)                                       \
01173   case OMPC_ ## Name : return static_cast<Class *>(this)->children();
01174 #include "clang/Basic/OpenMPKinds.def"
01175   }
01176   llvm_unreachable("unknown OMPClause");
01177 }
01178 
01179 void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
01180   assert(VL.size() == varlist_size() &&
01181          "Number of private copies is not the same as the preallocated buffer");
01182   std::copy(VL.begin(), VL.end(), varlist_end());
01183 }
01184 
01185 OMPPrivateClause *
01186 OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
01187                          SourceLocation LParenLoc, SourceLocation EndLoc,
01188                          ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
01189   // Allocate space for private variables and initializer expressions.
01190   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
01191                                                   llvm::alignOf<Expr *>()) +
01192                          2 * sizeof(Expr *) * VL.size());
01193   OMPPrivateClause *Clause =
01194       new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
01195   Clause->setVarRefs(VL);
01196   Clause->setPrivateCopies(PrivateVL);
01197   return Clause;
01198 }
01199 
01200 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
01201                                                 unsigned N) {
01202   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
01203                                                   llvm::alignOf<Expr *>()) +
01204                          2 * sizeof(Expr *) * N);
01205   return new (Mem) OMPPrivateClause(N);
01206 }
01207 
01208 void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
01209   assert(VL.size() == varlist_size() &&
01210          "Number of private copies is not the same as the preallocated buffer");
01211   std::copy(VL.begin(), VL.end(), varlist_end());
01212 }
01213 
01214 void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
01215   assert(VL.size() == varlist_size() &&
01216          "Number of inits is not the same as the preallocated buffer");
01217   std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
01218 }
01219 
01220 OMPFirstprivateClause *
01221 OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
01222                               SourceLocation LParenLoc, SourceLocation EndLoc,
01223                               ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
01224                               ArrayRef<Expr *> InitVL) {
01225   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
01226                                                   llvm::alignOf<Expr *>()) +
01227                          3 * sizeof(Expr *) * VL.size());
01228   OMPFirstprivateClause *Clause =
01229       new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
01230   Clause->setVarRefs(VL);
01231   Clause->setPrivateCopies(PrivateVL);
01232   Clause->setInits(InitVL);
01233   return Clause;
01234 }
01235 
01236 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
01237                                                           unsigned N) {
01238   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
01239                                                   llvm::alignOf<Expr *>()) +
01240                          3 * sizeof(Expr *) * N);
01241   return new (Mem) OMPFirstprivateClause(N);
01242 }
01243 
01244 OMPLastprivateClause *OMPLastprivateClause::Create(const ASTContext &C,
01245                                                    SourceLocation StartLoc,
01246                                                    SourceLocation LParenLoc,
01247                                                    SourceLocation EndLoc,
01248                                                    ArrayRef<Expr *> VL) {
01249   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
01250                                                   llvm::alignOf<Expr *>()) +
01251                          sizeof(Expr *) * VL.size());
01252   OMPLastprivateClause *Clause =
01253       new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
01254   Clause->setVarRefs(VL);
01255   return Clause;
01256 }
01257 
01258 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
01259                                                         unsigned N) {
01260   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
01261                                                   llvm::alignOf<Expr *>()) +
01262                          sizeof(Expr *) * N);
01263   return new (Mem) OMPLastprivateClause(N);
01264 }
01265 
01266 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
01267                                          SourceLocation StartLoc,
01268                                          SourceLocation LParenLoc,
01269                                          SourceLocation EndLoc,
01270                                          ArrayRef<Expr *> VL) {
01271   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
01272                                                   llvm::alignOf<Expr *>()) +
01273                          sizeof(Expr *) * VL.size());
01274   OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
01275                                                       EndLoc, VL.size());
01276   Clause->setVarRefs(VL);
01277   return Clause;
01278 }
01279 
01280 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
01281                                               unsigned N) {
01282   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
01283                                                   llvm::alignOf<Expr *>()) +
01284                          sizeof(Expr *) * N);
01285   return new (Mem) OMPSharedClause(N);
01286 }
01287 
01288 OMPLinearClause *OMPLinearClause::Create(const ASTContext &C,
01289                                          SourceLocation StartLoc,
01290                                          SourceLocation LParenLoc,
01291                                          SourceLocation ColonLoc,
01292                                          SourceLocation EndLoc,
01293                                          ArrayRef<Expr *> VL, Expr *Step) {
01294   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
01295                                                   llvm::alignOf<Expr *>()) +
01296                          sizeof(Expr *) * (VL.size() + 1));
01297   OMPLinearClause *Clause = new (Mem)
01298       OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
01299   Clause->setVarRefs(VL);
01300   Clause->setStep(Step);
01301   return Clause;
01302 }
01303 
01304 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
01305                                               unsigned NumVars) {
01306   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
01307                                                   llvm::alignOf<Expr *>()) +
01308                          sizeof(Expr *) * (NumVars + 1));
01309   return new (Mem) OMPLinearClause(NumVars);
01310 }
01311 
01312 OMPAlignedClause *
01313 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
01314                          SourceLocation LParenLoc, SourceLocation ColonLoc,
01315                          SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
01316   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
01317                                                   llvm::alignOf<Expr *>()) +
01318                          sizeof(Expr *) * (VL.size() + 1));
01319   OMPAlignedClause *Clause = new (Mem)
01320       OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
01321   Clause->setVarRefs(VL);
01322   Clause->setAlignment(A);
01323   return Clause;
01324 }
01325 
01326 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
01327                                                 unsigned NumVars) {
01328   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
01329                                                   llvm::alignOf<Expr *>()) +
01330                          sizeof(Expr *) * (NumVars + 1));
01331   return new (Mem) OMPAlignedClause(NumVars);
01332 }
01333 
01334 OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C,
01335                                          SourceLocation StartLoc,
01336                                          SourceLocation LParenLoc,
01337                                          SourceLocation EndLoc,
01338                                          ArrayRef<Expr *> VL) {
01339   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
01340                                                   llvm::alignOf<Expr *>()) +
01341                          sizeof(Expr *) * VL.size());
01342   OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc,
01343                                                       EndLoc, VL.size());
01344   Clause->setVarRefs(VL);
01345   return Clause;
01346 }
01347 
01348 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C,
01349                                               unsigned N) {
01350   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
01351                                                   llvm::alignOf<Expr *>()) +
01352                          sizeof(Expr *) * N);
01353   return new (Mem) OMPCopyinClause(N);
01354 }
01355 
01356 OMPCopyprivateClause *OMPCopyprivateClause::Create(const ASTContext &C,
01357                                                    SourceLocation StartLoc,
01358                                                    SourceLocation LParenLoc,
01359                                                    SourceLocation EndLoc,
01360                                                    ArrayRef<Expr *> VL) {
01361   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
01362                                                   llvm::alignOf<Expr *>()) +
01363                          sizeof(Expr *) * VL.size());
01364   OMPCopyprivateClause *Clause =
01365       new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
01366   Clause->setVarRefs(VL);
01367   return Clause;
01368 }
01369 
01370 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
01371                                                         unsigned N) {
01372   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
01373                                                   llvm::alignOf<Expr *>()) +
01374                          sizeof(Expr *) * N);
01375   return new (Mem) OMPCopyprivateClause(N);
01376 }
01377 
01378 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
01379   assert(Clauses.size() == getNumClauses() &&
01380          "Number of clauses is not the same as the preallocated buffer");
01381   std::copy(Clauses.begin(), Clauses.end(), getClauses().begin());
01382 }
01383 
01384 void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) {
01385   assert(A.size() == getCollapsedNumber() &&
01386          "Number of loop counters is not the same as the collapsed number");
01387   std::copy(A.begin(), A.end(), getCounters().begin());
01388 }
01389 
01390 void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) {
01391   assert(A.size() == getCollapsedNumber() &&
01392          "Number of counter updates is not the same as the collapsed number");
01393   std::copy(A.begin(), A.end(), getUpdates().begin());
01394 }
01395 
01396 void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) {
01397   assert(A.size() == getCollapsedNumber() &&
01398          "Number of counter finals is not the same as the collapsed number");
01399   std::copy(A.begin(), A.end(), getFinals().begin());
01400 }
01401 
01402 OMPReductionClause *OMPReductionClause::Create(
01403     const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
01404     SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
01405     NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo) {
01406   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
01407                                                   llvm::alignOf<Expr *>()) +
01408                          sizeof(Expr *) * VL.size());
01409   OMPReductionClause *Clause = new (Mem) OMPReductionClause(
01410       StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
01411   Clause->setVarRefs(VL);
01412   return Clause;
01413 }
01414 
01415 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
01416                                                     unsigned N) {
01417   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
01418                                                   llvm::alignOf<Expr *>()) +
01419                          sizeof(Expr *) * N);
01420   return new (Mem) OMPReductionClause(N);
01421 }
01422 
01423 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
01424                                        SourceLocation StartLoc,
01425                                        SourceLocation LParenLoc,
01426                                        SourceLocation EndLoc,
01427                                        ArrayRef<Expr *> VL) {
01428   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
01429                                                   llvm::alignOf<Expr *>()) +
01430                          sizeof(Expr *) * VL.size());
01431   OMPFlushClause *Clause =
01432       new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
01433   Clause->setVarRefs(VL);
01434   return Clause;
01435 }
01436 
01437 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
01438   void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
01439                                                   llvm::alignOf<Expr *>()) +
01440                          sizeof(Expr *) * N);
01441   return new (Mem) OMPFlushClause(N);
01442 }
01443 
01444 const OMPClause *
01445 OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const {
01446   auto ClauseFilter =
01447       [=](const OMPClause *C) -> bool { return C->getClauseKind() == K; };
01448   OMPExecutableDirective::filtered_clause_iterator<decltype(ClauseFilter)> I(
01449       clauses(), ClauseFilter);
01450 
01451   if (I) {
01452     auto *Clause = *I;
01453     assert(!++I && "There are at least 2 clauses of the specified kind");
01454     return Clause;
01455   }
01456   return nullptr;
01457 }
01458 
01459 OMPParallelDirective *OMPParallelDirective::Create(
01460                                               const ASTContext &C,
01461                                               SourceLocation StartLoc,
01462                                               SourceLocation EndLoc,
01463                                               ArrayRef<OMPClause *> Clauses,
01464                                               Stmt *AssociatedStmt) {
01465   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
01466                                            llvm::alignOf<OMPClause *>());
01467   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01468                          sizeof(Stmt *));
01469   OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc,
01470                                                              Clauses.size());
01471   Dir->setClauses(Clauses);
01472   Dir->setAssociatedStmt(AssociatedStmt);
01473   return Dir;
01474 }
01475 
01476 OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
01477                                                         unsigned NumClauses,
01478                                                         EmptyShell) {
01479   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
01480                                            llvm::alignOf<OMPClause *>());
01481   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01482                          sizeof(Stmt *));
01483   return new (Mem) OMPParallelDirective(NumClauses);
01484 }
01485 
01486 OMPSimdDirective *
01487 OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
01488                          SourceLocation EndLoc, unsigned CollapsedNum,
01489                          ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
01490                          Expr *IV, Expr *LastIteration, Expr *CalcLastIteration,
01491                          Expr *PreCond, Expr *Cond, Expr *SeparatedCond,
01492                          Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters,
01493                          ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) {
01494   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
01495                                            llvm::alignOf<OMPClause *>());
01496   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01497                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01498   OMPSimdDirective *Dir = new (Mem)
01499       OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
01500   Dir->setClauses(Clauses);
01501   Dir->setAssociatedStmt(AssociatedStmt);
01502   Dir->setIterationVariable(IV);
01503   Dir->setLastIteration(LastIteration);
01504   Dir->setCalcLastIteration(CalcLastIteration);
01505   Dir->setPreCond(PreCond);
01506   Dir->setCond(Cond, SeparatedCond);
01507   Dir->setInit(Init);
01508   Dir->setInc(Inc);
01509   Dir->setCounters(Counters);
01510   Dir->setUpdates(Updates);
01511   Dir->setFinals(Finals);
01512   return Dir;
01513 }
01514 
01515 OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
01516                                                 unsigned NumClauses,
01517                                                 unsigned CollapsedNum,
01518                                                 EmptyShell) {
01519   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
01520                                            llvm::alignOf<OMPClause *>());
01521   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01522                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01523   return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses);
01524 }
01525 
01526 OMPForDirective *
01527 OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc,
01528                         SourceLocation EndLoc, unsigned CollapsedNum,
01529                         ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
01530                         Expr *IV, Expr *LastIteration, Expr *CalcLastIteration,
01531                         Expr *PreCond, Expr *Cond, Expr *SeparatedCond,
01532                         Expr *Init, Expr *Inc, ArrayRef<Expr *> Counters,
01533                         ArrayRef<Expr *> Updates, ArrayRef<Expr *> Finals) {
01534   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
01535                                            llvm::alignOf<OMPClause *>());
01536   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01537                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01538   OMPForDirective *Dir =
01539       new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
01540   Dir->setClauses(Clauses);
01541   Dir->setAssociatedStmt(AssociatedStmt);
01542   Dir->setIterationVariable(IV);
01543   Dir->setLastIteration(LastIteration);
01544   Dir->setCalcLastIteration(CalcLastIteration);
01545   Dir->setPreCond(PreCond);
01546   Dir->setCond(Cond, SeparatedCond);
01547   Dir->setInit(Init);
01548   Dir->setInc(Inc);
01549   Dir->setCounters(Counters);
01550   Dir->setUpdates(Updates);
01551   Dir->setFinals(Finals);
01552   return Dir;
01553 }
01554 
01555 OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
01556                                               unsigned NumClauses,
01557                                               unsigned CollapsedNum,
01558                                               EmptyShell) {
01559   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
01560                                            llvm::alignOf<OMPClause *>());
01561   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01562                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01563   return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
01564 }
01565 
01566 OMPForSimdDirective *OMPForSimdDirective::Create(
01567     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
01568     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
01569     Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
01570     Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
01571     ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
01572     ArrayRef<Expr *> Finals) {
01573   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
01574                                            llvm::alignOf<OMPClause *>());
01575   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01576                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01577   OMPForSimdDirective *Dir = new (Mem)
01578       OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
01579   Dir->setClauses(Clauses);
01580   Dir->setAssociatedStmt(AssociatedStmt);
01581   Dir->setIterationVariable(IV);
01582   Dir->setLastIteration(LastIteration);
01583   Dir->setCalcLastIteration(CalcLastIteration);
01584   Dir->setPreCond(PreCond);
01585   Dir->setCond(Cond, SeparatedCond);
01586   Dir->setInit(Init);
01587   Dir->setInc(Inc);
01588   Dir->setCounters(Counters);
01589   Dir->setUpdates(Updates);
01590   Dir->setFinals(Finals);
01591   return Dir;
01592 }
01593 
01594 OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C,
01595                                                       unsigned NumClauses,
01596                                                       unsigned CollapsedNum,
01597                                                       EmptyShell) {
01598   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
01599                                            llvm::alignOf<OMPClause *>());
01600   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01601                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01602   return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
01603 }
01604 
01605 OMPSectionsDirective *OMPSectionsDirective::Create(
01606     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
01607     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
01608   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
01609                                            llvm::alignOf<OMPClause *>());
01610   void *Mem =
01611       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01612   OMPSectionsDirective *Dir =
01613       new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
01614   Dir->setClauses(Clauses);
01615   Dir->setAssociatedStmt(AssociatedStmt);
01616   return Dir;
01617 }
01618 
01619 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
01620                                                         unsigned NumClauses,
01621                                                         EmptyShell) {
01622   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
01623                                            llvm::alignOf<OMPClause *>());
01624   void *Mem =
01625       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
01626   return new (Mem) OMPSectionsDirective(NumClauses);
01627 }
01628 
01629 OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
01630                                                  SourceLocation StartLoc,
01631                                                  SourceLocation EndLoc,
01632                                                  Stmt *AssociatedStmt) {
01633   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
01634                                            llvm::alignOf<Stmt *>());
01635   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01636   OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
01637   Dir->setAssociatedStmt(AssociatedStmt);
01638   return Dir;
01639 }
01640 
01641 OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
01642                                                       EmptyShell) {
01643   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
01644                                            llvm::alignOf<Stmt *>());
01645   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01646   return new (Mem) OMPSectionDirective();
01647 }
01648 
01649 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
01650                                                SourceLocation StartLoc,
01651                                                SourceLocation EndLoc,
01652                                                ArrayRef<OMPClause *> Clauses,
01653                                                Stmt *AssociatedStmt) {
01654   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
01655                                            llvm::alignOf<OMPClause *>());
01656   void *Mem =
01657       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01658   OMPSingleDirective *Dir =
01659       new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size());
01660   Dir->setClauses(Clauses);
01661   Dir->setAssociatedStmt(AssociatedStmt);
01662   return Dir;
01663 }
01664 
01665 OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C,
01666                                                     unsigned NumClauses,
01667                                                     EmptyShell) {
01668   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
01669                                            llvm::alignOf<OMPClause *>());
01670   void *Mem =
01671       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
01672   return new (Mem) OMPSingleDirective(NumClauses);
01673 }
01674 
01675 OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
01676                                                SourceLocation StartLoc,
01677                                                SourceLocation EndLoc,
01678                                                Stmt *AssociatedStmt) {
01679   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
01680                                            llvm::alignOf<Stmt *>());
01681   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01682   OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc);
01683   Dir->setAssociatedStmt(AssociatedStmt);
01684   return Dir;
01685 }
01686 
01687 OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C,
01688                                                     EmptyShell) {
01689   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
01690                                            llvm::alignOf<Stmt *>());
01691   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01692   return new (Mem) OMPMasterDirective();
01693 }
01694 
01695 OMPCriticalDirective *OMPCriticalDirective::Create(
01696     const ASTContext &C, const DeclarationNameInfo &Name,
01697     SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) {
01698   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
01699                                            llvm::alignOf<Stmt *>());
01700   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01701   OMPCriticalDirective *Dir =
01702       new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc);
01703   Dir->setAssociatedStmt(AssociatedStmt);
01704   return Dir;
01705 }
01706 
01707 OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C,
01708                                                         EmptyShell) {
01709   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
01710                                            llvm::alignOf<Stmt *>());
01711   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01712   return new (Mem) OMPCriticalDirective();
01713 }
01714 
01715 OMPParallelForDirective *OMPParallelForDirective::Create(
01716     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
01717     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
01718     Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
01719     Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
01720     ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
01721     ArrayRef<Expr *> Finals) {
01722   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
01723                                            llvm::alignOf<OMPClause *>());
01724   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01725                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01726   OMPParallelForDirective *Dir = new (Mem)
01727       OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
01728   Dir->setClauses(Clauses);
01729   Dir->setAssociatedStmt(AssociatedStmt);
01730   Dir->setIterationVariable(IV);
01731   Dir->setLastIteration(LastIteration);
01732   Dir->setCalcLastIteration(CalcLastIteration);
01733   Dir->setPreCond(PreCond);
01734   Dir->setCond(Cond, SeparatedCond);
01735   Dir->setInit(Init);
01736   Dir->setInc(Inc);
01737   Dir->setCounters(Counters);
01738   Dir->setUpdates(Updates);
01739   Dir->setFinals(Finals);
01740   return Dir;
01741 }
01742 
01743 OMPParallelForDirective *
01744 OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
01745                                      unsigned CollapsedNum, EmptyShell) {
01746   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
01747                                            llvm::alignOf<OMPClause *>());
01748   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01749                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01750   return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses);
01751 }
01752 
01753 OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create(
01754     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
01755     unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
01756     Expr *IV, Expr *LastIteration, Expr *CalcLastIteration, Expr *PreCond,
01757     Expr *Cond, Expr *SeparatedCond, Expr *Init, Expr *Inc,
01758     ArrayRef<Expr *> Counters, ArrayRef<Expr *> Updates,
01759     ArrayRef<Expr *> Finals) {
01760   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
01761                                            llvm::alignOf<OMPClause *>());
01762   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01763                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01764   OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective(
01765       StartLoc, EndLoc, CollapsedNum, Clauses.size());
01766   Dir->setClauses(Clauses);
01767   Dir->setAssociatedStmt(AssociatedStmt);
01768   Dir->setIterationVariable(IV);
01769   Dir->setLastIteration(LastIteration);
01770   Dir->setCalcLastIteration(CalcLastIteration);
01771   Dir->setPreCond(PreCond);
01772   Dir->setCond(Cond, SeparatedCond);
01773   Dir->setInit(Init);
01774   Dir->setInc(Inc);
01775   Dir->setCounters(Counters);
01776   Dir->setUpdates(Updates);
01777   Dir->setFinals(Finals);
01778   return Dir;
01779 }
01780 
01781 OMPParallelForSimdDirective *
01782 OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C,
01783                                          unsigned NumClauses,
01784                                          unsigned CollapsedNum, EmptyShell) {
01785   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
01786                                            llvm::alignOf<OMPClause *>());
01787   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
01788                          sizeof(Stmt *) * numLoopChildren(CollapsedNum));
01789   return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
01790 }
01791 
01792 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
01793     const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
01794     ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
01795   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
01796                                            llvm::alignOf<OMPClause *>());
01797   void *Mem =
01798       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01799   OMPParallelSectionsDirective *Dir =
01800       new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size());
01801   Dir->setClauses(Clauses);
01802   Dir->setAssociatedStmt(AssociatedStmt);
01803   return Dir;
01804 }
01805 
01806 OMPParallelSectionsDirective *
01807 OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C,
01808                                           unsigned NumClauses, EmptyShell) {
01809   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
01810                                            llvm::alignOf<OMPClause *>());
01811   void *Mem =
01812       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
01813   return new (Mem) OMPParallelSectionsDirective(NumClauses);
01814 }
01815 
01816 OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C,
01817                                            SourceLocation StartLoc,
01818                                            SourceLocation EndLoc,
01819                                            ArrayRef<OMPClause *> Clauses,
01820                                            Stmt *AssociatedStmt) {
01821   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
01822                                            llvm::alignOf<OMPClause *>());
01823   void *Mem =
01824       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01825   OMPTaskDirective *Dir =
01826       new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size());
01827   Dir->setClauses(Clauses);
01828   Dir->setAssociatedStmt(AssociatedStmt);
01829   return Dir;
01830 }
01831 
01832 OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C,
01833                                                 unsigned NumClauses,
01834                                                 EmptyShell) {
01835   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
01836                                            llvm::alignOf<OMPClause *>());
01837   void *Mem =
01838       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
01839   return new (Mem) OMPTaskDirective(NumClauses);
01840 }
01841 
01842 OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C,
01843                                                      SourceLocation StartLoc,
01844                                                      SourceLocation EndLoc) {
01845   void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
01846   OMPTaskyieldDirective *Dir =
01847       new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc);
01848   return Dir;
01849 }
01850 
01851 OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
01852                                                           EmptyShell) {
01853   void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
01854   return new (Mem) OMPTaskyieldDirective();
01855 }
01856 
01857 OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
01858                                                  SourceLocation StartLoc,
01859                                                  SourceLocation EndLoc) {
01860   void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
01861   OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc);
01862   return Dir;
01863 }
01864 
01865 OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C,
01866                                                       EmptyShell) {
01867   void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
01868   return new (Mem) OMPBarrierDirective();
01869 }
01870 
01871 OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C,
01872                                                    SourceLocation StartLoc,
01873                                                    SourceLocation EndLoc) {
01874   void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
01875   OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc);
01876   return Dir;
01877 }
01878 
01879 OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C,
01880                                                         EmptyShell) {
01881   void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
01882   return new (Mem) OMPTaskwaitDirective();
01883 }
01884 
01885 OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C,
01886                                              SourceLocation StartLoc,
01887                                              SourceLocation EndLoc,
01888                                              ArrayRef<OMPClause *> Clauses) {
01889   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
01890                                            llvm::alignOf<OMPClause *>());
01891   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size());
01892   OMPFlushDirective *Dir =
01893       new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size());
01894   Dir->setClauses(Clauses);
01895   return Dir;
01896 }
01897 
01898 OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C,
01899                                                   unsigned NumClauses,
01900                                                   EmptyShell) {
01901   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
01902                                            llvm::alignOf<OMPClause *>());
01903   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses);
01904   return new (Mem) OMPFlushDirective(NumClauses);
01905 }
01906 
01907 OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
01908                                                  SourceLocation StartLoc,
01909                                                  SourceLocation EndLoc,
01910                                                  Stmt *AssociatedStmt) {
01911   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
01912                                            llvm::alignOf<Stmt *>());
01913   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01914   OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc);
01915   Dir->setAssociatedStmt(AssociatedStmt);
01916   return Dir;
01917 }
01918 
01919 OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C,
01920                                                       EmptyShell) {
01921   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
01922                                            llvm::alignOf<Stmt *>());
01923   void *Mem = C.Allocate(Size + sizeof(Stmt *));
01924   return new (Mem) OMPOrderedDirective();
01925 }
01926 
01927 OMPAtomicDirective *
01928 OMPAtomicDirective::Create(const ASTContext &C, SourceLocation StartLoc,
01929                            SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses,
01930                            Stmt *AssociatedStmt, Expr *X, Expr *V, Expr *E) {
01931   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
01932                                            llvm::alignOf<OMPClause *>());
01933   void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
01934                          4 * sizeof(Stmt *));
01935   OMPAtomicDirective *Dir =
01936       new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size());
01937   Dir->setClauses(Clauses);
01938   Dir->setAssociatedStmt(AssociatedStmt);
01939   Dir->setX(X);
01940   Dir->setV(V);
01941   Dir->setExpr(E);
01942   return Dir;
01943 }
01944 
01945 OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C,
01946                                                     unsigned NumClauses,
01947                                                     EmptyShell) {
01948   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
01949                                            llvm::alignOf<OMPClause *>());
01950   void *Mem =
01951       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 4 * sizeof(Stmt *));
01952   return new (Mem) OMPAtomicDirective(NumClauses);
01953 }
01954 
01955 OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C,
01956                                                SourceLocation StartLoc,
01957                                                SourceLocation EndLoc,
01958                                                ArrayRef<OMPClause *> Clauses,
01959                                                Stmt *AssociatedStmt) {
01960   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
01961                                            llvm::alignOf<OMPClause *>());
01962   void *Mem =
01963       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01964   OMPTargetDirective *Dir =
01965       new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size());
01966   Dir->setClauses(Clauses);
01967   Dir->setAssociatedStmt(AssociatedStmt);
01968   return Dir;
01969 }
01970 
01971 OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C,
01972                                                     unsigned NumClauses,
01973                                                     EmptyShell) {
01974   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
01975                                            llvm::alignOf<OMPClause *>());
01976   void *Mem =
01977       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
01978   return new (Mem) OMPTargetDirective(NumClauses);
01979 }
01980 
01981 OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C,
01982                                              SourceLocation StartLoc,
01983                                              SourceLocation EndLoc,
01984                                              ArrayRef<OMPClause *> Clauses,
01985                                              Stmt *AssociatedStmt) {
01986   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
01987                                            llvm::alignOf<OMPClause *>());
01988   void *Mem =
01989       C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
01990   OMPTeamsDirective *Dir =
01991       new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size());
01992   Dir->setClauses(Clauses);
01993   Dir->setAssociatedStmt(AssociatedStmt);
01994   return Dir;
01995 }
01996 
01997 OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C,
01998                                                   unsigned NumClauses,
01999                                                   EmptyShell) {
02000   unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
02001                                            llvm::alignOf<OMPClause *>());
02002   void *Mem =
02003       C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
02004   return new (Mem) OMPTeamsDirective(NumClauses);
02005 }
02006