1 //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the Stmt class and statement subclasses. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/ASTDiagnostic.h" 16 #include "clang/AST/ExprCXX.h" 17 #include "clang/AST/ExprObjC.h" 18 #include "clang/AST/Stmt.h" 19 #include "clang/AST/StmtCXX.h" 20 #include "clang/AST/StmtObjC.h" 21 #include "clang/AST/StmtOpenMP.h" 22 #include "clang/AST/Type.h" 23 #include "clang/Basic/CharInfo.h" 24 #include "clang/Basic/TargetInfo.h" 25 #include "clang/Lex/Token.h" 26 #include "llvm/ADT/StringExtras.h" 27 #include "llvm/Support/raw_ostream.h" 28 using namespace clang; 29 30 static struct StmtClassNameTable { 31 const char *Name; 32 unsigned Counter; 33 unsigned Size; 34 } StmtClassInfo[Stmt::lastStmtConstant+1]; 35 36 static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { 37 static bool Initialized = false; 38 if (Initialized) 39 return StmtClassInfo[E]; 40 41 // Intialize the table on the first use. 42 Initialized = true; 43 #define ABSTRACT_STMT(STMT) 44 #define STMT(CLASS, PARENT) \ 45 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ 46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); 47 #include "clang/AST/StmtNodes.inc" 48 49 return StmtClassInfo[E]; 50 } 51 52 void *Stmt::operator new(size_t bytes, const ASTContext& C, 53 unsigned alignment) { 54 return ::operator new(bytes, C, alignment); 55 } 56 57 const char *Stmt::getStmtClassName() const { 58 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; 59 } 60 61 void Stmt::PrintStats() { 62 // Ensure the table is primed. 63 getStmtInfoTableEntry(Stmt::NullStmtClass); 64 65 unsigned sum = 0; 66 llvm::errs() << "\n*** Stmt/Expr Stats:\n"; 67 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { 68 if (StmtClassInfo[i].Name == nullptr) continue; 69 sum += StmtClassInfo[i].Counter; 70 } 71 llvm::errs() << " " << sum << " stmts/exprs total.\n"; 72 sum = 0; 73 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { 74 if (StmtClassInfo[i].Name == nullptr) continue; 75 if (StmtClassInfo[i].Counter == 0) continue; 76 llvm::errs() << " " << StmtClassInfo[i].Counter << " " 77 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size 78 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size 79 << " bytes)\n"; 80 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; 81 } 82 83 llvm::errs() << "Total bytes = " << sum << "\n"; 84 } 85 86 void Stmt::addStmtClass(StmtClass s) { 87 ++getStmtInfoTableEntry(s).Counter; 88 } 89 90 bool Stmt::StatisticsEnabled = false; 91 void Stmt::EnableStatistics() { 92 StatisticsEnabled = true; 93 } 94 95 Stmt *Stmt::IgnoreImplicit() { 96 Stmt *s = this; 97 98 if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s)) 99 s = ewc->getSubExpr(); 100 101 while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s)) 102 s = ice->getSubExpr(); 103 104 return s; 105 } 106 107 /// \brief Strip off all label-like statements. 108 /// 109 /// This will strip off label statements, case statements, attributed 110 /// statements and default statements recursively. 111 const Stmt *Stmt::stripLabelLikeStatements() const { 112 const Stmt *S = this; 113 while (true) { 114 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) 115 S = LS->getSubStmt(); 116 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) 117 S = SC->getSubStmt(); 118 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) 119 S = AS->getSubStmt(); 120 else 121 return S; 122 } 123 } 124 125 namespace { 126 struct good {}; 127 struct bad {}; 128 129 // These silly little functions have to be static inline to suppress 130 // unused warnings, and they have to be defined to suppress other 131 // warnings. 132 static inline good is_good(good) { return good(); } 133 134 typedef Stmt::child_range children_t(); 135 template <class T> good implements_children(children_t T::*) { 136 return good(); 137 } 138 LLVM_ATTRIBUTE_UNUSED 139 static inline bad implements_children(children_t Stmt::*) { 140 return bad(); 141 } 142 143 typedef SourceLocation getLocStart_t() const; 144 template <class T> good implements_getLocStart(getLocStart_t T::*) { 145 return good(); 146 } 147 LLVM_ATTRIBUTE_UNUSED 148 static inline bad implements_getLocStart(getLocStart_t Stmt::*) { 149 return bad(); 150 } 151 152 typedef SourceLocation getLocEnd_t() const; 153 template <class T> good implements_getLocEnd(getLocEnd_t T::*) { 154 return good(); 155 } 156 LLVM_ATTRIBUTE_UNUSED 157 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { 158 return bad(); 159 } 160 161 #define ASSERT_IMPLEMENTS_children(type) \ 162 (void) is_good(implements_children(&type::children)) 163 #define ASSERT_IMPLEMENTS_getLocStart(type) \ 164 (void) is_good(implements_getLocStart(&type::getLocStart)) 165 #define ASSERT_IMPLEMENTS_getLocEnd(type) \ 166 (void) is_good(implements_getLocEnd(&type::getLocEnd)) 167 } 168 169 /// Check whether the various Stmt classes implement their member 170 /// functions. 171 LLVM_ATTRIBUTE_UNUSED 172 static inline void check_implementations() { 173 #define ABSTRACT_STMT(type) 174 #define STMT(type, base) \ 175 ASSERT_IMPLEMENTS_children(type); \ 176 ASSERT_IMPLEMENTS_getLocStart(type); \ 177 ASSERT_IMPLEMENTS_getLocEnd(type); 178 #include "clang/AST/StmtNodes.inc" 179 } 180 181 Stmt::child_range Stmt::children() { 182 switch (getStmtClass()) { 183 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 184 #define ABSTRACT_STMT(type) 185 #define STMT(type, base) \ 186 case Stmt::type##Class: \ 187 return static_cast<type*>(this)->children(); 188 #include "clang/AST/StmtNodes.inc" 189 } 190 llvm_unreachable("unknown statement kind!"); 191 } 192 193 // Amusing macro metaprogramming hack: check whether a class provides 194 // a more specific implementation of getSourceRange. 195 // 196 // See also Expr.cpp:getExprLoc(). 197 namespace { 198 /// This implementation is used when a class provides a custom 199 /// implementation of getSourceRange. 200 template <class S, class T> 201 SourceRange getSourceRangeImpl(const Stmt *stmt, 202 SourceRange (T::*v)() const) { 203 return static_cast<const S*>(stmt)->getSourceRange(); 204 } 205 206 /// This implementation is used when a class doesn't provide a custom 207 /// implementation of getSourceRange. Overload resolution should pick it over 208 /// the implementation above because it's more specialized according to 209 /// function template partial ordering. 210 template <class S> 211 SourceRange getSourceRangeImpl(const Stmt *stmt, 212 SourceRange (Stmt::*v)() const) { 213 return SourceRange(static_cast<const S*>(stmt)->getLocStart(), 214 static_cast<const S*>(stmt)->getLocEnd()); 215 } 216 } 217 218 SourceRange Stmt::getSourceRange() const { 219 switch (getStmtClass()) { 220 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 221 #define ABSTRACT_STMT(type) 222 #define STMT(type, base) \ 223 case Stmt::type##Class: \ 224 return getSourceRangeImpl<type>(this, &type::getSourceRange); 225 #include "clang/AST/StmtNodes.inc" 226 } 227 llvm_unreachable("unknown statement kind!"); 228 } 229 230 SourceLocation Stmt::getLocStart() const { 231 // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; 232 switch (getStmtClass()) { 233 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 234 #define ABSTRACT_STMT(type) 235 #define STMT(type, base) \ 236 case Stmt::type##Class: \ 237 return static_cast<const type*>(this)->getLocStart(); 238 #include "clang/AST/StmtNodes.inc" 239 } 240 llvm_unreachable("unknown statement kind"); 241 } 242 243 SourceLocation Stmt::getLocEnd() const { 244 switch (getStmtClass()) { 245 case Stmt::NoStmtClass: llvm_unreachable("statement without class"); 246 #define ABSTRACT_STMT(type) 247 #define STMT(type, base) \ 248 case Stmt::type##Class: \ 249 return static_cast<const type*>(this)->getLocEnd(); 250 #include "clang/AST/StmtNodes.inc" 251 } 252 llvm_unreachable("unknown statement kind"); 253 } 254 255 CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, 256 SourceLocation LB, SourceLocation RB) 257 : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) { 258 CompoundStmtBits.NumStmts = Stmts.size(); 259 assert(CompoundStmtBits.NumStmts == Stmts.size() && 260 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); 261 262 if (Stmts.size() == 0) { 263 Body = nullptr; 264 return; 265 } 266 267 Body = new (C) Stmt*[Stmts.size()]; 268 std::copy(Stmts.begin(), Stmts.end(), Body); 269 } 270 271 void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, 272 unsigned NumStmts) { 273 if (this->Body) 274 C.Deallocate(Body); 275 this->CompoundStmtBits.NumStmts = NumStmts; 276 277 Body = new (C) Stmt*[NumStmts]; 278 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); 279 } 280 281 const char *LabelStmt::getName() const { 282 return getDecl()->getIdentifier()->getNameStart(); 283 } 284 285 AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, 286 ArrayRef<const Attr*> Attrs, 287 Stmt *SubStmt) { 288 assert(!Attrs.empty() && "Attrs should not be empty"); 289 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), 290 llvm::alignOf<AttributedStmt>()); 291 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); 292 } 293 294 AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, 295 unsigned NumAttrs) { 296 assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); 297 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, 298 llvm::alignOf<AttributedStmt>()); 299 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); 300 } 301 302 std::string AsmStmt::generateAsmString(const ASTContext &C) const { 303 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 304 return gccAsmStmt->generateAsmString(C); 305 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 306 return msAsmStmt->generateAsmString(C); 307 llvm_unreachable("unknown asm statement kind!"); 308 } 309 310 StringRef AsmStmt::getOutputConstraint(unsigned i) const { 311 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 312 return gccAsmStmt->getOutputConstraint(i); 313 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 314 return msAsmStmt->getOutputConstraint(i); 315 llvm_unreachable("unknown asm statement kind!"); 316 } 317 318 const Expr *AsmStmt::getOutputExpr(unsigned i) const { 319 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 320 return gccAsmStmt->getOutputExpr(i); 321 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 322 return msAsmStmt->getOutputExpr(i); 323 llvm_unreachable("unknown asm statement kind!"); 324 } 325 326 StringRef AsmStmt::getInputConstraint(unsigned i) const { 327 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 328 return gccAsmStmt->getInputConstraint(i); 329 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 330 return msAsmStmt->getInputConstraint(i); 331 llvm_unreachable("unknown asm statement kind!"); 332 } 333 334 const Expr *AsmStmt::getInputExpr(unsigned i) const { 335 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 336 return gccAsmStmt->getInputExpr(i); 337 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 338 return msAsmStmt->getInputExpr(i); 339 llvm_unreachable("unknown asm statement kind!"); 340 } 341 342 StringRef AsmStmt::getClobber(unsigned i) const { 343 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) 344 return gccAsmStmt->getClobber(i); 345 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) 346 return msAsmStmt->getClobber(i); 347 llvm_unreachable("unknown asm statement kind!"); 348 } 349 350 /// getNumPlusOperands - Return the number of output operands that have a "+" 351 /// constraint. 352 unsigned AsmStmt::getNumPlusOperands() const { 353 unsigned Res = 0; 354 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) 355 if (isOutputPlusConstraint(i)) 356 ++Res; 357 return Res; 358 } 359 360 StringRef GCCAsmStmt::getClobber(unsigned i) const { 361 return getClobberStringLiteral(i)->getString(); 362 } 363 364 Expr *GCCAsmStmt::getOutputExpr(unsigned i) { 365 return cast<Expr>(Exprs[i]); 366 } 367 368 /// getOutputConstraint - Return the constraint string for the specified 369 /// output operand. All output constraints are known to be non-empty (either 370 /// '=' or '+'). 371 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { 372 return getOutputConstraintLiteral(i)->getString(); 373 } 374 375 Expr *GCCAsmStmt::getInputExpr(unsigned i) { 376 return cast<Expr>(Exprs[i + NumOutputs]); 377 } 378 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { 379 Exprs[i + NumOutputs] = E; 380 } 381 382 /// getInputConstraint - Return the specified input constraint. Unlike output 383 /// constraints, these can be empty. 384 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { 385 return getInputConstraintLiteral(i)->getString(); 386 } 387 388 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, 389 IdentifierInfo **Names, 390 StringLiteral **Constraints, 391 Stmt **Exprs, 392 unsigned NumOutputs, 393 unsigned NumInputs, 394 StringLiteral **Clobbers, 395 unsigned NumClobbers) { 396 this->NumOutputs = NumOutputs; 397 this->NumInputs = NumInputs; 398 this->NumClobbers = NumClobbers; 399 400 unsigned NumExprs = NumOutputs + NumInputs; 401 402 C.Deallocate(this->Names); 403 this->Names = new (C) IdentifierInfo*[NumExprs]; 404 std::copy(Names, Names + NumExprs, this->Names); 405 406 C.Deallocate(this->Exprs); 407 this->Exprs = new (C) Stmt*[NumExprs]; 408 std::copy(Exprs, Exprs + NumExprs, this->Exprs); 409 410 C.Deallocate(this->Constraints); 411 this->Constraints = new (C) StringLiteral*[NumExprs]; 412 std::copy(Constraints, Constraints + NumExprs, this->Constraints); 413 414 C.Deallocate(this->Clobbers); 415 this->Clobbers = new (C) StringLiteral*[NumClobbers]; 416 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); 417 } 418 419 /// getNamedOperand - Given a symbolic operand reference like %[foo], 420 /// translate this into a numeric value needed to reference the same operand. 421 /// This returns -1 if the operand name is invalid. 422 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { 423 unsigned NumPlusOperands = 0; 424 425 // Check if this is an output operand. 426 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { 427 if (getOutputName(i) == SymbolicName) 428 return i; 429 } 430 431 for (unsigned i = 0, e = getNumInputs(); i != e; ++i) 432 if (getInputName(i) == SymbolicName) 433 return getNumOutputs() + NumPlusOperands + i; 434 435 // Not found. 436 return -1; 437 } 438 439 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 440 /// it into pieces. If the asm string is erroneous, emit errors and return 441 /// true, otherwise return false. 442 unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, 443 const ASTContext &C, unsigned &DiagOffs) const { 444 StringRef Str = getAsmString()->getString(); 445 const char *StrStart = Str.begin(); 446 const char *StrEnd = Str.end(); 447 const char *CurPtr = StrStart; 448 449 // "Simple" inline asms have no constraints or operands, just convert the asm 450 // string to escape $'s. 451 if (isSimple()) { 452 std::string Result; 453 for (; CurPtr != StrEnd; ++CurPtr) { 454 switch (*CurPtr) { 455 case '$': 456 Result += "$$"; 457 break; 458 default: 459 Result += *CurPtr; 460 break; 461 } 462 } 463 Pieces.push_back(AsmStringPiece(Result)); 464 return 0; 465 } 466 467 // CurStringPiece - The current string that we are building up as we scan the 468 // asm string. 469 std::string CurStringPiece; 470 471 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); 472 473 while (1) { 474 // Done with the string? 475 if (CurPtr == StrEnd) { 476 if (!CurStringPiece.empty()) 477 Pieces.push_back(AsmStringPiece(CurStringPiece)); 478 return 0; 479 } 480 481 char CurChar = *CurPtr++; 482 switch (CurChar) { 483 case '$': CurStringPiece += "$$"; continue; 484 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; 485 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; 486 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; 487 case '%': 488 break; 489 default: 490 CurStringPiece += CurChar; 491 continue; 492 } 493 494 // Escaped "%" character in asm string. 495 if (CurPtr == StrEnd) { 496 // % at end of string is invalid (no escape). 497 DiagOffs = CurPtr-StrStart-1; 498 return diag::err_asm_invalid_escape; 499 } 500 501 char EscapedChar = *CurPtr++; 502 if (EscapedChar == '%') { // %% -> % 503 // Escaped percentage sign. 504 CurStringPiece += '%'; 505 continue; 506 } 507 508 if (EscapedChar == '=') { // %= -> Generate an unique ID. 509 CurStringPiece += "${:uid}"; 510 continue; 511 } 512 513 // Otherwise, we have an operand. If we have accumulated a string so far, 514 // add it to the Pieces list. 515 if (!CurStringPiece.empty()) { 516 Pieces.push_back(AsmStringPiece(CurStringPiece)); 517 CurStringPiece.clear(); 518 } 519 520 // Handle %x4 and %x[foo] by capturing x as the modifier character. 521 char Modifier = '\0'; 522 if (isLetter(EscapedChar)) { 523 if (CurPtr == StrEnd) { // Premature end. 524 DiagOffs = CurPtr-StrStart-1; 525 return diag::err_asm_invalid_escape; 526 } 527 Modifier = EscapedChar; 528 EscapedChar = *CurPtr++; 529 } 530 531 if (isDigit(EscapedChar)) { 532 // %n - Assembler operand n 533 unsigned N = 0; 534 535 --CurPtr; 536 while (CurPtr != StrEnd && isDigit(*CurPtr)) 537 N = N*10 + ((*CurPtr++)-'0'); 538 539 unsigned NumOperands = 540 getNumOutputs() + getNumPlusOperands() + getNumInputs(); 541 if (N >= NumOperands) { 542 DiagOffs = CurPtr-StrStart-1; 543 return diag::err_asm_invalid_operand_number; 544 } 545 546 Pieces.push_back(AsmStringPiece(N, Modifier)); 547 continue; 548 } 549 550 // Handle %[foo], a symbolic operand reference. 551 if (EscapedChar == '[') { 552 DiagOffs = CurPtr-StrStart-1; 553 554 // Find the ']'. 555 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); 556 if (NameEnd == nullptr) 557 return diag::err_asm_unterminated_symbolic_operand_name; 558 if (NameEnd == CurPtr) 559 return diag::err_asm_empty_symbolic_operand_name; 560 561 StringRef SymbolicName(CurPtr, NameEnd - CurPtr); 562 563 int N = getNamedOperand(SymbolicName); 564 if (N == -1) { 565 // Verify that an operand with that name exists. 566 DiagOffs = CurPtr-StrStart; 567 return diag::err_asm_unknown_symbolic_operand_name; 568 } 569 Pieces.push_back(AsmStringPiece(N, Modifier)); 570 571 CurPtr = NameEnd+1; 572 continue; 573 } 574 575 DiagOffs = CurPtr-StrStart-1; 576 return diag::err_asm_invalid_escape; 577 } 578 } 579 580 /// Assemble final IR asm string (GCC-style). 581 std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { 582 // Analyze the asm string to decompose it into its pieces. We know that Sema 583 // has already done this, so it is guaranteed to be successful. 584 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; 585 unsigned DiagOffs; 586 AnalyzeAsmString(Pieces, C, DiagOffs); 587 588 std::string AsmString; 589 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { 590 if (Pieces[i].isString()) 591 AsmString += Pieces[i].getString(); 592 else if (Pieces[i].getModifier() == '\0') 593 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); 594 else 595 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + 596 Pieces[i].getModifier() + '}'; 597 } 598 return AsmString; 599 } 600 601 /// Assemble final IR asm string (MS-style). 602 std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { 603 // FIXME: This needs to be translated into the IR string representation. 604 return AsmStr; 605 } 606 607 Expr *MSAsmStmt::getOutputExpr(unsigned i) { 608 return cast<Expr>(Exprs[i]); 609 } 610 611 Expr *MSAsmStmt::getInputExpr(unsigned i) { 612 return cast<Expr>(Exprs[i + NumOutputs]); 613 } 614 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { 615 Exprs[i + NumOutputs] = E; 616 } 617 618 QualType CXXCatchStmt::getCaughtType() const { 619 if (ExceptionDecl) 620 return ExceptionDecl->getType(); 621 return QualType(); 622 } 623 624 //===----------------------------------------------------------------------===// 625 // Constructors 626 //===----------------------------------------------------------------------===// 627 628 GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, 629 bool issimple, bool isvolatile, unsigned numoutputs, 630 unsigned numinputs, IdentifierInfo **names, 631 StringLiteral **constraints, Expr **exprs, 632 StringLiteral *asmstr, unsigned numclobbers, 633 StringLiteral **clobbers, SourceLocation rparenloc) 634 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, 635 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { 636 637 unsigned NumExprs = NumOutputs + NumInputs; 638 639 Names = new (C) IdentifierInfo*[NumExprs]; 640 std::copy(names, names + NumExprs, Names); 641 642 Exprs = new (C) Stmt*[NumExprs]; 643 std::copy(exprs, exprs + NumExprs, Exprs); 644 645 Constraints = new (C) StringLiteral*[NumExprs]; 646 std::copy(constraints, constraints + NumExprs, Constraints); 647 648 Clobbers = new (C) StringLiteral*[NumClobbers]; 649 std::copy(clobbers, clobbers + NumClobbers, Clobbers); 650 } 651 652 MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, 653 SourceLocation lbraceloc, bool issimple, bool isvolatile, 654 ArrayRef<Token> asmtoks, unsigned numoutputs, 655 unsigned numinputs, 656 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, 657 StringRef asmstr, ArrayRef<StringRef> clobbers, 658 SourceLocation endloc) 659 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, 660 numinputs, clobbers.size()), LBraceLoc(lbraceloc), 661 EndLoc(endloc), NumAsmToks(asmtoks.size()) { 662 663 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); 664 } 665 666 static StringRef copyIntoContext(const ASTContext &C, StringRef str) { 667 size_t size = str.size(); 668 char *buffer = new (C) char[size]; 669 memcpy(buffer, str.data(), size); 670 return StringRef(buffer, size); 671 } 672 673 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, 674 ArrayRef<Token> asmtoks, 675 ArrayRef<StringRef> constraints, 676 ArrayRef<Expr*> exprs, 677 ArrayRef<StringRef> clobbers) { 678 assert(NumAsmToks == asmtoks.size()); 679 assert(NumClobbers == clobbers.size()); 680 681 unsigned NumExprs = exprs.size(); 682 assert(NumExprs == NumOutputs + NumInputs); 683 assert(NumExprs == constraints.size()); 684 685 AsmStr = copyIntoContext(C, asmstr); 686 687 Exprs = new (C) Stmt*[NumExprs]; 688 for (unsigned i = 0, e = NumExprs; i != e; ++i) 689 Exprs[i] = exprs[i]; 690 691 AsmToks = new (C) Token[NumAsmToks]; 692 for (unsigned i = 0, e = NumAsmToks; i != e; ++i) 693 AsmToks[i] = asmtoks[i]; 694 695 Constraints = new (C) StringRef[NumExprs]; 696 for (unsigned i = 0, e = NumExprs; i != e; ++i) { 697 Constraints[i] = copyIntoContext(C, constraints[i]); 698 } 699 700 Clobbers = new (C) StringRef[NumClobbers]; 701 for (unsigned i = 0, e = NumClobbers; i != e; ++i) { 702 // FIXME: Avoid the allocation/copy if at all possible. 703 Clobbers[i] = copyIntoContext(C, clobbers[i]); 704 } 705 } 706 707 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, 708 Stmt *Body, SourceLocation FCL, 709 SourceLocation RPL) 710 : Stmt(ObjCForCollectionStmtClass) { 711 SubExprs[ELEM] = Elem; 712 SubExprs[COLLECTION] = Collect; 713 SubExprs[BODY] = Body; 714 ForLoc = FCL; 715 RParenLoc = RPL; 716 } 717 718 ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, 719 Stmt **CatchStmts, unsigned NumCatchStmts, 720 Stmt *atFinallyStmt) 721 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), 722 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { 723 Stmt **Stmts = getStmts(); 724 Stmts[0] = atTryStmt; 725 for (unsigned I = 0; I != NumCatchStmts; ++I) 726 Stmts[I + 1] = CatchStmts[I]; 727 728 if (HasFinally) 729 Stmts[NumCatchStmts + 1] = atFinallyStmt; 730 } 731 732 ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, 733 SourceLocation atTryLoc, 734 Stmt *atTryStmt, 735 Stmt **CatchStmts, 736 unsigned NumCatchStmts, 737 Stmt *atFinallyStmt) { 738 unsigned Size = sizeof(ObjCAtTryStmt) + 739 (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); 740 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); 741 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, 742 atFinallyStmt); 743 } 744 745 ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, 746 unsigned NumCatchStmts, 747 bool HasFinally) { 748 unsigned Size = sizeof(ObjCAtTryStmt) + 749 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); 750 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); 751 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); 752 } 753 754 SourceLocation ObjCAtTryStmt::getLocEnd() const { 755 if (HasFinally) 756 return getFinallyStmt()->getLocEnd(); 757 if (NumCatchStmts) 758 return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); 759 return getTryBody()->getLocEnd(); 760 } 761 762 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, 763 Stmt *tryBlock, ArrayRef<Stmt*> handlers) { 764 std::size_t Size = sizeof(CXXTryStmt); 765 Size += ((handlers.size() + 1) * sizeof(Stmt)); 766 767 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); 768 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); 769 } 770 771 CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, 772 unsigned numHandlers) { 773 std::size_t Size = sizeof(CXXTryStmt); 774 Size += ((numHandlers + 1) * sizeof(Stmt)); 775 776 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); 777 return new (Mem) CXXTryStmt(Empty, numHandlers); 778 } 779 780 CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, 781 ArrayRef<Stmt*> handlers) 782 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { 783 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); 784 Stmts[0] = tryBlock; 785 std::copy(handlers.begin(), handlers.end(), Stmts + 1); 786 } 787 788 CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, 789 Expr *Cond, Expr *Inc, DeclStmt *LoopVar, 790 Stmt *Body, SourceLocation FL, 791 SourceLocation CL, SourceLocation RPL) 792 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { 793 SubExprs[RANGE] = Range; 794 SubExprs[BEGINEND] = BeginEndStmt; 795 SubExprs[COND] = Cond; 796 SubExprs[INC] = Inc; 797 SubExprs[LOOPVAR] = LoopVar; 798 SubExprs[BODY] = Body; 799 } 800 801 Expr *CXXForRangeStmt::getRangeInit() { 802 DeclStmt *RangeStmt = getRangeStmt(); 803 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); 804 assert(RangeDecl && "for-range should have a single var decl"); 805 return RangeDecl->getInit(); 806 } 807 808 const Expr *CXXForRangeStmt::getRangeInit() const { 809 return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); 810 } 811 812 VarDecl *CXXForRangeStmt::getLoopVariable() { 813 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); 814 assert(LV && "No loop variable in CXXForRangeStmt"); 815 return cast<VarDecl>(LV); 816 } 817 818 const VarDecl *CXXForRangeStmt::getLoopVariable() const { 819 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); 820 } 821 822 IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 823 Stmt *then, SourceLocation EL, Stmt *elsev) 824 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) 825 { 826 setConditionVariable(C, var); 827 SubExprs[COND] = cond; 828 SubExprs[THEN] = then; 829 SubExprs[ELSE] = elsev; 830 } 831 832 VarDecl *IfStmt::getConditionVariable() const { 833 if (!SubExprs[VAR]) 834 return nullptr; 835 836 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 837 return cast<VarDecl>(DS->getSingleDecl()); 838 } 839 840 void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 841 if (!V) { 842 SubExprs[VAR] = nullptr; 843 return; 844 } 845 846 SourceRange VarRange = V->getSourceRange(); 847 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 848 VarRange.getEnd()); 849 } 850 851 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, 852 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, 853 SourceLocation RP) 854 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) 855 { 856 SubExprs[INIT] = Init; 857 setConditionVariable(C, condVar); 858 SubExprs[COND] = Cond; 859 SubExprs[INC] = Inc; 860 SubExprs[BODY] = Body; 861 } 862 863 VarDecl *ForStmt::getConditionVariable() const { 864 if (!SubExprs[CONDVAR]) 865 return nullptr; 866 867 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); 868 return cast<VarDecl>(DS->getSingleDecl()); 869 } 870 871 void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 872 if (!V) { 873 SubExprs[CONDVAR] = nullptr; 874 return; 875 } 876 877 SourceRange VarRange = V->getSourceRange(); 878 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 879 VarRange.getEnd()); 880 } 881 882 SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) 883 : Stmt(SwitchStmtClass), FirstCase(nullptr), AllEnumCasesCovered(0) 884 { 885 setConditionVariable(C, Var); 886 SubExprs[COND] = cond; 887 SubExprs[BODY] = nullptr; 888 } 889 890 VarDecl *SwitchStmt::getConditionVariable() const { 891 if (!SubExprs[VAR]) 892 return nullptr; 893 894 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 895 return cast<VarDecl>(DS->getSingleDecl()); 896 } 897 898 void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 899 if (!V) { 900 SubExprs[VAR] = nullptr; 901 return; 902 } 903 904 SourceRange VarRange = V->getSourceRange(); 905 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 906 VarRange.getEnd()); 907 } 908 909 Stmt *SwitchCase::getSubStmt() { 910 if (isa<CaseStmt>(this)) 911 return cast<CaseStmt>(this)->getSubStmt(); 912 return cast<DefaultStmt>(this)->getSubStmt(); 913 } 914 915 WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 916 SourceLocation WL) 917 : Stmt(WhileStmtClass) { 918 setConditionVariable(C, Var); 919 SubExprs[COND] = cond; 920 SubExprs[BODY] = body; 921 WhileLoc = WL; 922 } 923 924 VarDecl *WhileStmt::getConditionVariable() const { 925 if (!SubExprs[VAR]) 926 return nullptr; 927 928 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); 929 return cast<VarDecl>(DS->getSingleDecl()); 930 } 931 932 void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { 933 if (!V) { 934 SubExprs[VAR] = nullptr; 935 return; 936 } 937 938 SourceRange VarRange = V->getSourceRange(); 939 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), 940 VarRange.getEnd()); 941 } 942 943 // IndirectGotoStmt 944 LabelDecl *IndirectGotoStmt::getConstantTarget() { 945 if (AddrLabelExpr *E = 946 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) 947 return E->getLabel(); 948 return nullptr; 949 } 950 951 // ReturnStmt 952 const Expr* ReturnStmt::getRetValue() const { 953 return cast_or_null<Expr>(RetExpr); 954 } 955 Expr* ReturnStmt::getRetValue() { 956 return cast_or_null<Expr>(RetExpr); 957 } 958 959 SEHTryStmt::SEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, 960 Stmt *Handler, int HandlerIndex, int HandlerParentIndex) 961 : Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc), 962 HandlerIndex(HandlerIndex), HandlerParentIndex(HandlerParentIndex) { 963 Children[TRY] = TryBlock; 964 Children[HANDLER] = Handler; 965 } 966 967 SEHTryStmt *SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, 968 SourceLocation TryLoc, Stmt *TryBlock, 969 Stmt *Handler, int HandlerIndex, 970 int HandlerParentIndex) { 971 return new (C) SEHTryStmt(IsCXXTry, TryLoc, TryBlock, Handler, HandlerIndex, 972 HandlerParentIndex); 973 } 974 975 SEHExceptStmt* SEHTryStmt::getExceptHandler() const { 976 return dyn_cast<SEHExceptStmt>(getHandler()); 977 } 978 979 SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { 980 return dyn_cast<SEHFinallyStmt>(getHandler()); 981 } 982 983 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, 984 Expr *FilterExpr, 985 Stmt *Block) 986 : Stmt(SEHExceptStmtClass), 987 Loc(Loc) 988 { 989 Children[FILTER_EXPR] = FilterExpr; 990 Children[BLOCK] = Block; 991 } 992 993 SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, 994 Expr *FilterExpr, Stmt *Block) { 995 return new(C) SEHExceptStmt(Loc,FilterExpr,Block); 996 } 997 998 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, 999 Stmt *Block) 1000 : Stmt(SEHFinallyStmtClass), 1001 Loc(Loc), 1002 Block(Block) 1003 {} 1004 1005 SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, 1006 Stmt *Block) { 1007 return new(C)SEHFinallyStmt(Loc,Block); 1008 } 1009 1010 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { 1011 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); 1012 1013 // Offset of the first Capture object. 1014 unsigned FirstCaptureOffset = 1015 llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1016 1017 return reinterpret_cast<Capture *>( 1018 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) 1019 + FirstCaptureOffset); 1020 } 1021 1022 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, 1023 ArrayRef<Capture> Captures, 1024 ArrayRef<Expr *> CaptureInits, 1025 CapturedDecl *CD, 1026 RecordDecl *RD) 1027 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), 1028 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { 1029 assert( S && "null captured statement"); 1030 assert(CD && "null captured declaration for captured statement"); 1031 assert(RD && "null record declaration for captured statement"); 1032 1033 // Copy initialization expressions. 1034 Stmt **Stored = getStoredStmts(); 1035 for (unsigned I = 0, N = NumCaptures; I != N; ++I) 1036 *Stored++ = CaptureInits[I]; 1037 1038 // Copy the statement being captured. 1039 *Stored = S; 1040 1041 // Copy all Capture objects. 1042 Capture *Buffer = getStoredCaptures(); 1043 std::copy(Captures.begin(), Captures.end(), Buffer); 1044 } 1045 1046 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) 1047 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), 1048 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { 1049 getStoredStmts()[NumCaptures] = nullptr; 1050 } 1051 1052 CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, 1053 CapturedRegionKind Kind, 1054 ArrayRef<Capture> Captures, 1055 ArrayRef<Expr *> CaptureInits, 1056 CapturedDecl *CD, 1057 RecordDecl *RD) { 1058 // The layout is 1059 // 1060 // ----------------------------------------------------------- 1061 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | 1062 // ----------------^-------------------^---------------------- 1063 // getStoredStmts() getStoredCaptures() 1064 // 1065 // where S is the statement being captured. 1066 // 1067 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); 1068 1069 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); 1070 if (!Captures.empty()) { 1071 // Realign for the following Capture array. 1072 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1073 Size += sizeof(Capture) * Captures.size(); 1074 } 1075 1076 void *Mem = Context.Allocate(Size); 1077 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); 1078 } 1079 1080 CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, 1081 unsigned NumCaptures) { 1082 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); 1083 if (NumCaptures > 0) { 1084 // Realign for the following Capture array. 1085 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); 1086 Size += sizeof(Capture) * NumCaptures; 1087 } 1088 1089 void *Mem = Context.Allocate(Size); 1090 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); 1091 } 1092 1093 Stmt::child_range CapturedStmt::children() { 1094 // Children are captured field initilizers. 1095 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); 1096 } 1097 1098 bool CapturedStmt::capturesVariable(const VarDecl *Var) const { 1099 for (const auto &I : captures()) { 1100 if (!I.capturesVariable()) 1101 continue; 1102 1103 // This does not handle variable redeclarations. This should be 1104 // extended to capture variables with redeclarations, for example 1105 // a thread-private variable in OpenMP. 1106 if (I.getCapturedVar() == Var) 1107 return true; 1108 } 1109 1110 return false; 1111 } 1112 1113 StmtRange OMPClause::children() { 1114 switch(getClauseKind()) { 1115 default : break; 1116 #define OPENMP_CLAUSE(Name, Class) \ 1117 case OMPC_ ## Name : return static_cast<Class *>(this)->children(); 1118 #include "clang/Basic/OpenMPKinds.def" 1119 } 1120 llvm_unreachable("unknown OMPClause"); 1121 } 1122 1123 OMPPrivateClause *OMPPrivateClause::Create(const ASTContext &C, 1124 SourceLocation StartLoc, 1125 SourceLocation LParenLoc, 1126 SourceLocation EndLoc, 1127 ArrayRef<Expr *> VL) { 1128 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), 1129 llvm::alignOf<Expr *>()) + 1130 sizeof(Expr *) * VL.size()); 1131 OMPPrivateClause *Clause = new (Mem) OMPPrivateClause(StartLoc, LParenLoc, 1132 EndLoc, VL.size()); 1133 Clause->setVarRefs(VL); 1134 return Clause; 1135 } 1136 1137 OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, 1138 unsigned N) { 1139 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), 1140 llvm::alignOf<Expr *>()) + 1141 sizeof(Expr *) * N); 1142 return new (Mem) OMPPrivateClause(N); 1143 } 1144 1145 OMPFirstprivateClause *OMPFirstprivateClause::Create(const ASTContext &C, 1146 SourceLocation StartLoc, 1147 SourceLocation LParenLoc, 1148 SourceLocation EndLoc, 1149 ArrayRef<Expr *> VL) { 1150 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), 1151 llvm::alignOf<Expr *>()) + 1152 sizeof(Expr *) * VL.size()); 1153 OMPFirstprivateClause *Clause = new (Mem) OMPFirstprivateClause(StartLoc, 1154 LParenLoc, 1155 EndLoc, 1156 VL.size()); 1157 Clause->setVarRefs(VL); 1158 return Clause; 1159 } 1160 1161 OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, 1162 unsigned N) { 1163 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), 1164 llvm::alignOf<Expr *>()) + 1165 sizeof(Expr *) * N); 1166 return new (Mem) OMPFirstprivateClause(N); 1167 } 1168 1169 OMPLastprivateClause *OMPLastprivateClause::Create(const ASTContext &C, 1170 SourceLocation StartLoc, 1171 SourceLocation LParenLoc, 1172 SourceLocation EndLoc, 1173 ArrayRef<Expr *> VL) { 1174 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), 1175 llvm::alignOf<Expr *>()) + 1176 sizeof(Expr *) * VL.size()); 1177 OMPLastprivateClause *Clause = 1178 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1179 Clause->setVarRefs(VL); 1180 return Clause; 1181 } 1182 1183 OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, 1184 unsigned N) { 1185 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), 1186 llvm::alignOf<Expr *>()) + 1187 sizeof(Expr *) * N); 1188 return new (Mem) OMPLastprivateClause(N); 1189 } 1190 1191 OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, 1192 SourceLocation StartLoc, 1193 SourceLocation LParenLoc, 1194 SourceLocation EndLoc, 1195 ArrayRef<Expr *> VL) { 1196 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), 1197 llvm::alignOf<Expr *>()) + 1198 sizeof(Expr *) * VL.size()); 1199 OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, 1200 EndLoc, VL.size()); 1201 Clause->setVarRefs(VL); 1202 return Clause; 1203 } 1204 1205 OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, 1206 unsigned N) { 1207 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), 1208 llvm::alignOf<Expr *>()) + 1209 sizeof(Expr *) * N); 1210 return new (Mem) OMPSharedClause(N); 1211 } 1212 1213 OMPLinearClause *OMPLinearClause::Create(const ASTContext &C, 1214 SourceLocation StartLoc, 1215 SourceLocation LParenLoc, 1216 SourceLocation ColonLoc, 1217 SourceLocation EndLoc, 1218 ArrayRef<Expr *> VL, Expr *Step) { 1219 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), 1220 llvm::alignOf<Expr *>()) + 1221 sizeof(Expr *) * (VL.size() + 1)); 1222 OMPLinearClause *Clause = new (Mem) 1223 OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 1224 Clause->setVarRefs(VL); 1225 Clause->setStep(Step); 1226 return Clause; 1227 } 1228 1229 OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, 1230 unsigned NumVars) { 1231 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), 1232 llvm::alignOf<Expr *>()) + 1233 sizeof(Expr *) * (NumVars + 1)); 1234 return new (Mem) OMPLinearClause(NumVars); 1235 } 1236 1237 OMPAlignedClause * 1238 OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, 1239 SourceLocation LParenLoc, SourceLocation ColonLoc, 1240 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { 1241 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), 1242 llvm::alignOf<Expr *>()) + 1243 sizeof(Expr *) * (VL.size() + 1)); 1244 OMPAlignedClause *Clause = new (Mem) 1245 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); 1246 Clause->setVarRefs(VL); 1247 Clause->setAlignment(A); 1248 return Clause; 1249 } 1250 1251 OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, 1252 unsigned NumVars) { 1253 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), 1254 llvm::alignOf<Expr *>()) + 1255 sizeof(Expr *) * (NumVars + 1)); 1256 return new (Mem) OMPAlignedClause(NumVars); 1257 } 1258 1259 OMPCopyinClause *OMPCopyinClause::Create(const ASTContext &C, 1260 SourceLocation StartLoc, 1261 SourceLocation LParenLoc, 1262 SourceLocation EndLoc, 1263 ArrayRef<Expr *> VL) { 1264 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), 1265 llvm::alignOf<Expr *>()) + 1266 sizeof(Expr *) * VL.size()); 1267 OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, 1268 EndLoc, VL.size()); 1269 Clause->setVarRefs(VL); 1270 return Clause; 1271 } 1272 1273 OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, 1274 unsigned N) { 1275 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), 1276 llvm::alignOf<Expr *>()) + 1277 sizeof(Expr *) * N); 1278 return new (Mem) OMPCopyinClause(N); 1279 } 1280 1281 OMPCopyprivateClause *OMPCopyprivateClause::Create(const ASTContext &C, 1282 SourceLocation StartLoc, 1283 SourceLocation LParenLoc, 1284 SourceLocation EndLoc, 1285 ArrayRef<Expr *> VL) { 1286 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), 1287 llvm::alignOf<Expr *>()) + 1288 sizeof(Expr *) * VL.size()); 1289 OMPCopyprivateClause *Clause = 1290 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1291 Clause->setVarRefs(VL); 1292 return Clause; 1293 } 1294 1295 OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, 1296 unsigned N) { 1297 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), 1298 llvm::alignOf<Expr *>()) + 1299 sizeof(Expr *) * N); 1300 return new (Mem) OMPCopyprivateClause(N); 1301 } 1302 1303 void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { 1304 assert(Clauses.size() == getNumClauses() && 1305 "Number of clauses is not the same as the preallocated buffer"); 1306 std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); 1307 } 1308 1309 OMPReductionClause *OMPReductionClause::Create( 1310 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, 1311 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, 1312 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo) { 1313 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), 1314 llvm::alignOf<Expr *>()) + 1315 sizeof(Expr *) * VL.size()); 1316 OMPReductionClause *Clause = new (Mem) OMPReductionClause( 1317 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); 1318 Clause->setVarRefs(VL); 1319 return Clause; 1320 } 1321 1322 OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, 1323 unsigned N) { 1324 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), 1325 llvm::alignOf<Expr *>()) + 1326 sizeof(Expr *) * N); 1327 return new (Mem) OMPReductionClause(N); 1328 } 1329 1330 OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, 1331 SourceLocation StartLoc, 1332 SourceLocation LParenLoc, 1333 SourceLocation EndLoc, 1334 ArrayRef<Expr *> VL) { 1335 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), 1336 llvm::alignOf<Expr *>()) + 1337 sizeof(Expr *) * VL.size()); 1338 OMPFlushClause *Clause = 1339 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); 1340 Clause->setVarRefs(VL); 1341 return Clause; 1342 } 1343 1344 OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { 1345 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), 1346 llvm::alignOf<Expr *>()) + 1347 sizeof(Expr *) * N); 1348 return new (Mem) OMPFlushClause(N); 1349 } 1350 1351 OMPParallelDirective *OMPParallelDirective::Create( 1352 const ASTContext &C, 1353 SourceLocation StartLoc, 1354 SourceLocation EndLoc, 1355 ArrayRef<OMPClause *> Clauses, 1356 Stmt *AssociatedStmt) { 1357 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), 1358 llvm::alignOf<OMPClause *>()); 1359 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + 1360 sizeof(Stmt *)); 1361 OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, 1362 Clauses.size()); 1363 Dir->setClauses(Clauses); 1364 Dir->setAssociatedStmt(AssociatedStmt); 1365 return Dir; 1366 } 1367 1368 OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, 1369 unsigned NumClauses, 1370 EmptyShell) { 1371 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), 1372 llvm::alignOf<OMPClause *>()); 1373 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 1374 sizeof(Stmt *)); 1375 return new (Mem) OMPParallelDirective(NumClauses); 1376 } 1377 1378 OMPSimdDirective * 1379 OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1380 SourceLocation EndLoc, unsigned CollapsedNum, 1381 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { 1382 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), 1383 llvm::alignOf<OMPClause *>()); 1384 void *Mem = 1385 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1386 OMPSimdDirective *Dir = new (Mem) 1387 OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1388 Dir->setClauses(Clauses); 1389 Dir->setAssociatedStmt(AssociatedStmt); 1390 return Dir; 1391 } 1392 1393 OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, 1394 unsigned NumClauses, 1395 unsigned CollapsedNum, 1396 EmptyShell) { 1397 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), 1398 llvm::alignOf<OMPClause *>()); 1399 void *Mem = 1400 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1401 return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); 1402 } 1403 1404 OMPForDirective * 1405 OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1406 SourceLocation EndLoc, unsigned CollapsedNum, 1407 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { 1408 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), 1409 llvm::alignOf<OMPClause *>()); 1410 void *Mem = 1411 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1412 OMPForDirective *Dir = 1413 new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1414 Dir->setClauses(Clauses); 1415 Dir->setAssociatedStmt(AssociatedStmt); 1416 return Dir; 1417 } 1418 1419 OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, 1420 unsigned NumClauses, 1421 unsigned CollapsedNum, 1422 EmptyShell) { 1423 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), 1424 llvm::alignOf<OMPClause *>()); 1425 void *Mem = 1426 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1427 return new (Mem) OMPForDirective(CollapsedNum, NumClauses); 1428 } 1429 1430 OMPSectionsDirective *OMPSectionsDirective::Create( 1431 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1432 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { 1433 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), 1434 llvm::alignOf<OMPClause *>()); 1435 void *Mem = 1436 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1437 OMPSectionsDirective *Dir = 1438 new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); 1439 Dir->setClauses(Clauses); 1440 Dir->setAssociatedStmt(AssociatedStmt); 1441 return Dir; 1442 } 1443 1444 OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, 1445 unsigned NumClauses, 1446 EmptyShell) { 1447 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), 1448 llvm::alignOf<OMPClause *>()); 1449 void *Mem = 1450 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1451 return new (Mem) OMPSectionsDirective(NumClauses); 1452 } 1453 1454 OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, 1455 SourceLocation StartLoc, 1456 SourceLocation EndLoc, 1457 Stmt *AssociatedStmt) { 1458 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), 1459 llvm::alignOf<Stmt *>()); 1460 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1461 OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); 1462 Dir->setAssociatedStmt(AssociatedStmt); 1463 return Dir; 1464 } 1465 1466 OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, 1467 EmptyShell) { 1468 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), 1469 llvm::alignOf<Stmt *>()); 1470 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1471 return new (Mem) OMPSectionDirective(); 1472 } 1473 1474 OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, 1475 SourceLocation StartLoc, 1476 SourceLocation EndLoc, 1477 ArrayRef<OMPClause *> Clauses, 1478 Stmt *AssociatedStmt) { 1479 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), 1480 llvm::alignOf<OMPClause *>()); 1481 void *Mem = 1482 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1483 OMPSingleDirective *Dir = 1484 new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); 1485 Dir->setClauses(Clauses); 1486 Dir->setAssociatedStmt(AssociatedStmt); 1487 return Dir; 1488 } 1489 1490 OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, 1491 unsigned NumClauses, 1492 EmptyShell) { 1493 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), 1494 llvm::alignOf<OMPClause *>()); 1495 void *Mem = 1496 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1497 return new (Mem) OMPSingleDirective(NumClauses); 1498 } 1499 1500 OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, 1501 SourceLocation StartLoc, 1502 SourceLocation EndLoc, 1503 Stmt *AssociatedStmt) { 1504 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), 1505 llvm::alignOf<Stmt *>()); 1506 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1507 OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); 1508 Dir->setAssociatedStmt(AssociatedStmt); 1509 return Dir; 1510 } 1511 1512 OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, 1513 EmptyShell) { 1514 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), 1515 llvm::alignOf<Stmt *>()); 1516 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1517 return new (Mem) OMPMasterDirective(); 1518 } 1519 1520 OMPCriticalDirective *OMPCriticalDirective::Create( 1521 const ASTContext &C, const DeclarationNameInfo &Name, 1522 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { 1523 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), 1524 llvm::alignOf<Stmt *>()); 1525 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1526 OMPCriticalDirective *Dir = 1527 new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc); 1528 Dir->setAssociatedStmt(AssociatedStmt); 1529 return Dir; 1530 } 1531 1532 OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, 1533 EmptyShell) { 1534 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), 1535 llvm::alignOf<Stmt *>()); 1536 void *Mem = C.Allocate(Size + sizeof(Stmt *)); 1537 return new (Mem) OMPCriticalDirective(); 1538 } 1539 1540 OMPParallelForDirective * 1541 OMPParallelForDirective::Create(const ASTContext &C, SourceLocation StartLoc, 1542 SourceLocation EndLoc, unsigned CollapsedNum, 1543 ArrayRef<OMPClause *> Clauses, 1544 Stmt *AssociatedStmt) { 1545 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), 1546 llvm::alignOf<OMPClause *>()); 1547 void *Mem = 1548 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1549 OMPParallelForDirective *Dir = new (Mem) 1550 OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); 1551 Dir->setClauses(Clauses); 1552 Dir->setAssociatedStmt(AssociatedStmt); 1553 return Dir; 1554 } 1555 1556 OMPParallelForDirective * 1557 OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, 1558 unsigned CollapsedNum, EmptyShell) { 1559 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), 1560 llvm::alignOf<OMPClause *>()); 1561 void *Mem = 1562 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1563 return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); 1564 } 1565 1566 OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( 1567 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, 1568 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { 1569 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), 1570 llvm::alignOf<OMPClause *>()); 1571 void *Mem = 1572 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1573 OMPParallelSectionsDirective *Dir = 1574 new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); 1575 Dir->setClauses(Clauses); 1576 Dir->setAssociatedStmt(AssociatedStmt); 1577 return Dir; 1578 } 1579 1580 OMPParallelSectionsDirective * 1581 OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, 1582 unsigned NumClauses, EmptyShell) { 1583 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), 1584 llvm::alignOf<OMPClause *>()); 1585 void *Mem = 1586 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1587 return new (Mem) OMPParallelSectionsDirective(NumClauses); 1588 } 1589 1590 OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C, 1591 SourceLocation StartLoc, 1592 SourceLocation EndLoc, 1593 ArrayRef<OMPClause *> Clauses, 1594 Stmt *AssociatedStmt) { 1595 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), 1596 llvm::alignOf<OMPClause *>()); 1597 void *Mem = 1598 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); 1599 OMPTaskDirective *Dir = 1600 new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); 1601 Dir->setClauses(Clauses); 1602 Dir->setAssociatedStmt(AssociatedStmt); 1603 return Dir; 1604 } 1605 1606 OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, 1607 unsigned NumClauses, 1608 EmptyShell) { 1609 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), 1610 llvm::alignOf<OMPClause *>()); 1611 void *Mem = 1612 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); 1613 return new (Mem) OMPTaskDirective(NumClauses); 1614 } 1615 1616 OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, 1617 SourceLocation StartLoc, 1618 SourceLocation EndLoc) { 1619 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); 1620 OMPTaskyieldDirective *Dir = 1621 new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); 1622 return Dir; 1623 } 1624 1625 OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, 1626 EmptyShell) { 1627 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); 1628 return new (Mem) OMPTaskyieldDirective(); 1629 } 1630 1631 OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, 1632 SourceLocation StartLoc, 1633 SourceLocation EndLoc) { 1634 void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); 1635 OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); 1636 return Dir; 1637 } 1638 1639 OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, 1640 EmptyShell) { 1641 void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); 1642 return new (Mem) OMPBarrierDirective(); 1643 } 1644 1645 OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, 1646 SourceLocation StartLoc, 1647 SourceLocation EndLoc) { 1648 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); 1649 OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); 1650 return Dir; 1651 } 1652 1653 OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, 1654 EmptyShell) { 1655 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); 1656 return new (Mem) OMPTaskwaitDirective(); 1657 } 1658 1659 OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, 1660 SourceLocation StartLoc, 1661 SourceLocation EndLoc, 1662 ArrayRef<OMPClause *> Clauses) { 1663 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), 1664 llvm::alignOf<OMPClause *>()); 1665 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); 1666 OMPFlushDirective *Dir = 1667 new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); 1668 Dir->setClauses(Clauses); 1669 return Dir; 1670 } 1671 1672 OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, 1673 unsigned NumClauses, 1674 EmptyShell) { 1675 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), 1676 llvm::alignOf<OMPClause *>()); 1677 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); 1678 return new (Mem) OMPFlushDirective(NumClauses); 1679 } 1680 1681