33#include "llvm/ADT/SmallVector.h"
34#include "llvm/ADT/StringExtras.h"
35#include "llvm/ADT/StringRef.h"
36#include "llvm/Support/Casting.h"
37#include "llvm/Support/Compiler.h"
38#include "llvm/Support/ErrorHandling.h"
39#include "llvm/Support/MathExtras.h"
40#include "llvm/Support/raw_ostream.h"
64#define ABSTRACT_STMT(STMT)
65#define STMT(CLASS, PARENT) \
66 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
67 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
68#include "clang/AST/StmtNodes.inc"
75 return ::operator
new(
bytes,
C, alignment);
85#define STMT(CLASS, PARENT) \
86 static_assert(!std::is_polymorphic<CLASS>::value, \
87 #CLASS " should not be polymorphic!");
88#include "clang/AST/StmtNodes.inc"
93#define STMT(CLASS, PARENT) \
94 static_assert(std::is_trivially_destructible<CLASS>::value, \
95 #CLASS " should be trivially destructible!");
97#define INITLISTEXPR(CLASS, PARENT)
98#include "clang/AST/StmtNodes.inc"
105 llvm::errs() <<
"\n*** Stmt/Expr Stats:\n";
106 for (
int i = 0; i != Stmt::lastStmtConstant+1; i++) {
110 llvm::errs() <<
" " << sum <<
" stmts/exprs total.\n";
112 for (
int i = 0; i != Stmt::lastStmtConstant+1; i++) {
122 llvm::errs() <<
"Total bytes = " << sum <<
"\n";
129bool Stmt::StatisticsEnabled =
false;
131 StatisticsEnabled =
true;
134static std::pair<Stmt::Likelihood, const Attr *>
136 for (
const auto *A : Attrs) {
137 if (isa<LikelyAttr>(A))
140 if (isa<UnlikelyAttr>(A))
148 if (
const auto *AS = dyn_cast_or_null<AttributedStmt>(S))
155 return ::getLikelihood(Attrs).first;
159 return ::getLikelihood(S).first;
163 return ::getLikelihood(S).second;
183std::tuple<bool, const Attr *, const Attr *>
188 if (LHT.first !=
LH_None && LHT.first == LHE.first)
189 return std::make_tuple(
true, LHT.second, LHE.second);
191 return std::make_tuple(
false,
nullptr,
nullptr);
199 if (
auto CapS = dyn_cast_or_null<CapturedStmt>(S))
200 S = CapS->getCapturedStmt();
202 if (
auto AS = dyn_cast_or_null<AttributedStmt>(S))
203 S = AS->getSubStmt();
204 else if (
auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
219 const Stmt *S =
this;
221 if (
const auto *LS = dyn_cast<LabelStmt>(S))
222 S = LS->getSubStmt();
223 else if (
const auto *SC = dyn_cast<SwitchCase>(S))
224 S = SC->getSubStmt();
225 else if (
const auto *AS = dyn_cast<AttributedStmt>(S))
226 S = AS->getSubStmt();
240 static good is_good(good) {
return good(); }
243 template <
class T> good implements_children(children_t T::*) {
246 LLVM_ATTRIBUTE_UNUSED
247 static bad implements_children(children_t
Stmt::*) {
252 template <
class T> good implements_getBeginLoc(getBeginLoc_t T::*) {
255 LLVM_ATTRIBUTE_UNUSED
256 static bad implements_getBeginLoc(getBeginLoc_t
Stmt::*) {
return bad(); }
259 template <
class T> good implements_getEndLoc(getLocEnd_t T::*) {
262 LLVM_ATTRIBUTE_UNUSED
263 static bad implements_getEndLoc(getLocEnd_t
Stmt::*) {
return bad(); }
265#define ASSERT_IMPLEMENTS_children(type) \
266 (void) is_good(implements_children(&type::children))
267#define ASSERT_IMPLEMENTS_getBeginLoc(type) \
268 (void)is_good(implements_getBeginLoc(&type::getBeginLoc))
269#define ASSERT_IMPLEMENTS_getEndLoc(type) \
270 (void)is_good(implements_getEndLoc(&type::getEndLoc))
278#define ABSTRACT_STMT(type)
279#define STMT(type, base) \
280 ASSERT_IMPLEMENTS_children(type); \
281 ASSERT_IMPLEMENTS_getBeginLoc(type); \
282 ASSERT_IMPLEMENTS_getEndLoc(type);
283#include "clang/AST/StmtNodes.inc"
289#define ABSTRACT_STMT(type)
290#define STMT(type, base) \
291 case Stmt::type##Class: \
292 return static_cast<type*>(this)->children();
293#include "clang/AST/StmtNodes.inc"
295 llvm_unreachable(
"unknown statement kind!");
306 template <
class S,
class T>
309 return static_cast<const S*
>(
stmt)->getSourceRange();
320 static_cast<const S *
>(
stmt)->getEndLoc());
328#define ABSTRACT_STMT(type)
329#define STMT(type, base) \
330 case Stmt::type##Class: \
331 return getSourceRangeImpl<type>(this, &type::getSourceRange);
332#include "clang/AST/StmtNodes.inc"
334 llvm_unreachable(
"unknown statement kind!");
340#define ABSTRACT_STMT(type)
341#define STMT(type, base) \
342 case Stmt::type##Class: \
343 return static_cast<const type *>(this)->getBeginLoc();
344#include "clang/AST/StmtNodes.inc"
346 llvm_unreachable(
"unknown statement kind");
352#define ABSTRACT_STMT(type)
353#define STMT(type, base) \
354 case Stmt::type##Class: \
355 return static_cast<const type *>(this)->getEndLoc();
356#include "clang/AST/StmtNodes.inc"
358 llvm_unreachable(
"unknown statement kind");
367 :
Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
371 if (hasStoredFPFeatures())
372 setStoredFPFeatures(FPFeatures);
377 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
379 std::copy(Stmts.begin(), Stmts.end(),
body_begin());
386 C.Allocate(totalSizeToAlloc<Stmt *, FPOptionsOverride>(
389 return new (Mem)
CompoundStmt(Stmts, FPFeatures, LB, RB);
393 bool HasFPFeatures) {
394 void *Mem =
C.Allocate(
395 totalSizeToAlloc<Stmt *, FPOptionsOverride>(NumStmts, HasFPFeatures),
404 const Stmt *S =
this;
406 if (
const auto *E = dyn_cast<Expr>(S))
409 if (
const auto *LS = dyn_cast<LabelStmt>(S))
410 S = LS->getSubStmt();
411 else if (
const auto *AS = dyn_cast<AttributedStmt>(S))
412 S = AS->getSubStmt();
414 llvm_unreachable(
"unknown kind of ValueStmt");
415 }
while (isa<ValueStmt>(S));
427 assert(!Attrs.empty() &&
"Attrs should not be empty");
428 void *Mem =
C.Allocate(totalSizeToAlloc<const Attr *>(Attrs.size()),
435 assert(NumAttrs > 0 &&
"NumAttrs should be greater than zero");
436 void *Mem =
C.Allocate(totalSizeToAlloc<const Attr *>(NumAttrs),
442 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
443 return gccAsmStmt->generateAsmString(
C);
444 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
445 return msAsmStmt->generateAsmString(
C);
446 llvm_unreachable(
"unknown asm statement kind!");
450 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
451 return gccAsmStmt->getOutputConstraint(i);
452 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
453 return msAsmStmt->getOutputConstraint(i);
454 llvm_unreachable(
"unknown asm statement kind!");
458 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
459 return gccAsmStmt->getOutputExpr(i);
460 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
461 return msAsmStmt->getOutputExpr(i);
462 llvm_unreachable(
"unknown asm statement kind!");
466 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
467 return gccAsmStmt->getInputConstraint(i);
468 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
469 return msAsmStmt->getInputConstraint(i);
470 llvm_unreachable(
"unknown asm statement kind!");
474 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
475 return gccAsmStmt->getInputExpr(i);
476 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
477 return msAsmStmt->getInputExpr(i);
478 llvm_unreachable(
"unknown asm statement kind!");
482 if (
const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(
this))
483 return gccAsmStmt->getClobber(i);
484 if (
const auto *msAsmStmt = dyn_cast<MSAsmStmt>(
this))
485 return msAsmStmt->getClobber(i);
486 llvm_unreachable(
"unknown asm statement kind!");
500 assert(
isOperand() &&
"Only Operands can have modifiers.");
501 return isLetter(Str[0]) ? Str[0] :
'\0';
509 return cast<Expr>(
Exprs[i]);
541void GCCAsmStmt::setOutputsAndInputsAndClobbers(
const ASTContext &
C,
553 this->NumLabels = NumLabels;
557 C.Deallocate(this->Names);
559 std::copy(Names, Names + NumExprs, this->Names);
561 C.Deallocate(this->Exprs);
562 this->Exprs =
new (
C)
Stmt*[NumExprs];
563 std::copy(
Exprs,
Exprs + NumExprs, this->Exprs);
566 C.Deallocate(this->Constraints);
568 std::copy(Constraints, Constraints +
NumConstraints, this->Constraints);
570 C.Deallocate(this->Clobbers);
572 std::copy(Clobbers, Clobbers +
NumClobbers, this->Clobbers);
586 for (
unsigned i = 0; i !=
NumInputs; ++i)
604 const char *StrStart = Str.begin();
605 const char *StrEnd = Str.end();
606 const char *CurPtr = StrStart;
612 for (; CurPtr != StrEnd; ++CurPtr) {
628 std::string CurStringPiece;
630 bool HasVariants = !
C.getTargetInfo().hasNoAsmVariants();
632 unsigned LastAsmStringToken = 0;
633 unsigned LastAsmStringOffset = 0;
637 if (CurPtr == StrEnd) {
638 if (!CurStringPiece.empty())
643 char CurChar = *CurPtr++;
645 case '$': CurStringPiece +=
"$$";
continue;
646 case '{': CurStringPiece += (HasVariants ?
"$(" :
"{");
continue;
647 case '|': CurStringPiece += (HasVariants ?
"$|" :
"|");
continue;
648 case '}': CurStringPiece += (HasVariants ?
"$)" :
"}");
continue;
652 CurStringPiece += CurChar;
659 if (CurPtr == StrEnd) {
661 DiagOffs = CurPtr-StrStart-1;
662 return diag::err_asm_invalid_escape;
665 char EscapedChar = *CurPtr++;
666 switch (EscapedChar) {
670 CurStringPiece += *MaybeReplaceStr;
677 CurStringPiece += EscapedChar;
680 CurStringPiece +=
"${:uid}";
686 if (!CurStringPiece.empty()) {
688 CurStringPiece.clear();
694 const char *
Begin = CurPtr - 1;
695 const char *Percent =
Begin - 1;
698 if (CurPtr == StrEnd) {
699 DiagOffs = CurPtr-StrStart-1;
700 return diag::err_asm_invalid_escape;
702 EscapedChar = *CurPtr++;
714 while (CurPtr != StrEnd &&
isDigit(*CurPtr))
715 N = N*10 + ((*CurPtr++)-
'0');
719 if (N >= NumOperands) {
720 DiagOffs = CurPtr-StrStart-1;
721 return diag::err_asm_invalid_operand_number;
730 Percent - StrStart,
SM, LO, TI, &LastAsmStringToken,
731 &LastAsmStringOffset);
733 CurPtr - StrStart,
SM, LO, TI, &LastAsmStringToken,
734 &LastAsmStringOffset);
736 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
741 if (EscapedChar ==
'[') {
742 DiagOffs = CurPtr-StrStart-1;
745 const char *NameEnd = (
const char*)memchr(CurPtr,
']', StrEnd-CurPtr);
746 if (NameEnd ==
nullptr)
747 return diag::err_asm_unterminated_symbolic_operand_name;
748 if (NameEnd == CurPtr)
749 return diag::err_asm_empty_symbolic_operand_name;
751 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
756 DiagOffs = CurPtr-StrStart;
757 return diag::err_asm_unknown_symbolic_operand_name;
766 Percent - StrStart,
SM, LO, TI, &LastAsmStringToken,
767 &LastAsmStringOffset);
769 NameEnd + 1 - StrStart,
SM, LO, TI, &LastAsmStringToken,
770 &LastAsmStringOffset);
772 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
778 DiagOffs = CurPtr-StrStart-1;
779 return diag::err_asm_invalid_escape;
791 std::string AsmString;
792 for (
const auto &Piece : Pieces) {
793 if (Piece.isString())
794 AsmString += Piece.getString();
795 else if (Piece.getModifier() ==
'\0')
796 AsmString +=
'$' + llvm::utostr(Piece.getOperandNo());
798 AsmString +=
"${" + llvm::utostr(Piece.getOperandNo()) +
':' +
799 Piece.getModifier() +
'}';
808 AsmStr.split(Pieces,
"\n\t");
809 std::string MSAsmString;
810 for (
size_t I = 0, E = Pieces.size(); I < E; ++I) {
811 StringRef Instruction = Pieces[I];
814 if (Instruction.startswith(
"vex "))
815 MSAsmString +=
'{' + Instruction.substr(0, 3).str() +
'}' +
816 Instruction.substr(3).str();
817 else if (Instruction.startswith(
"vex2 ") ||
818 Instruction.startswith(
"vex3 ") || Instruction.startswith(
"evex "))
819 MSAsmString +=
'{' + Instruction.substr(0, 4).str() +
'}' +
820 Instruction.substr(4).str();
822 MSAsmString += Instruction.str();
825 MSAsmString +=
"\n\t";
831 return cast<Expr>(
Exprs[i]);
847 bool issimple,
bool isvolatile,
unsigned numoutputs,
853 :
AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
854 numinputs, numclobbers),
855 RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
859 std::copy(names, names + NumExprs, Names);
862 std::copy(exprs, exprs + NumExprs,
Exprs);
866 std::copy(constraints, constraints +
NumConstraints, Constraints);
869 std::copy(clobbers, clobbers +
NumClobbers, Clobbers);
879 :
AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
880 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
881 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
882 initialize(
C, asmstr, asmtoks, constraints, exprs, clobbers);
889void MSAsmStmt::initialize(
const ASTContext &
C, StringRef asmstr,
894 assert(NumAsmToks == asmtoks.size());
898 assert(exprs.size() == constraints.size());
903 std::copy(exprs.begin(), exprs.end(),
Exprs);
905 AsmToks =
new (
C)
Token[asmtoks.size()];
906 std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
908 Constraints =
new (
C) StringRef[exprs.size()];
909 std::transform(constraints.begin(), constraints.end(), Constraints,
910 [&](StringRef Constraint) {
911 return copyIntoContext(C, Constraint);
916 std::transform(clobbers.begin(), clobbers.end(), Clobbers,
917 [&](StringRef Clobber) {
918 return copyIntoContext(C, Clobber);
925 :
Stmt(IfStmtClass), LParenLoc(LPL), RParenLoc(RPL) {
926 bool HasElse = Else !=
nullptr;
927 bool HasVar = Var !=
nullptr;
928 bool HasInit = Init !=
nullptr;
929 IfStmtBits.HasElse = HasElse;
930 IfStmtBits.HasVar = HasVar;
931 IfStmtBits.HasInit = HasInit;
933 setStatementKind(Kind);
940 setConditionVariable(Ctx, Var);
949IfStmt::IfStmt(EmptyShell Empty,
bool HasElse,
bool HasVar,
bool HasInit)
950 :
Stmt(IfStmtClass, Empty) {
951 IfStmtBits.HasElse = HasElse;
952 IfStmtBits.HasVar = HasVar;
953 IfStmtBits.HasInit = HasInit;
960 bool HasElse = Else !=
nullptr;
961 bool HasVar = Var !=
nullptr;
962 bool HasInit = Init !=
nullptr;
964 totalSizeToAlloc<Stmt *, SourceLocation>(
965 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
968 IfStmt(Ctx, IL, Kind, Init, Var, Cond, LPL, RPL, Then, EL, Else);
974 totalSizeToAlloc<Stmt *, SourceLocation>(
975 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
984 return cast<VarDecl>(DS->getSingleDecl());
989 "This if statement has no storage for a condition variable!");
992 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
997 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
1002 return isa<ObjCAvailabilityCheckExpr>(
getCond());
1007 return std::nullopt;
1011std::optional<const Stmt *>
1013 if (std::optional<Stmt *>
Result =
1016 return std::nullopt;
1022 :
Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP)
1024 SubExprs[INIT] = Init;
1026 SubExprs[COND] = Cond;
1027 SubExprs[INC] = Inc;
1028 SubExprs[BODY] = Body;
1033 if (!SubExprs[CONDVAR])
1036 auto *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
1037 return cast<VarDecl>(DS->getSingleDecl());
1042 SubExprs[CONDVAR] =
nullptr;
1054 :
Stmt(SwitchStmtClass), FirstCase(nullptr), LParenLoc(LParenLoc),
1055 RParenLoc(RParenLoc) {
1056 bool HasInit = Init !=
nullptr;
1057 bool HasVar = Var !=
nullptr;
1072SwitchStmt::SwitchStmt(EmptyShell Empty,
bool HasInit,
bool HasVar)
1073 :
Stmt(SwitchStmtClass, Empty) {
1082 bool HasInit = Init !=
nullptr;
1083 bool HasVar = Var !=
nullptr;
1085 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1087 return new (Mem)
SwitchStmt(Ctx, Init, Var, Cond, LParenLoc, RParenLoc);
1093 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1102 return cast<VarDecl>(DS->getSingleDecl());
1107 "This switch statement has no storage for a condition variable!");
1110 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
1115 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
1122 :
Stmt(WhileStmtClass) {
1123 bool HasVar = Var !=
nullptr;
1136WhileStmt::WhileStmt(EmptyShell Empty,
bool HasVar)
1137 :
Stmt(WhileStmtClass, Empty) {
1145 bool HasVar = Var !=
nullptr;
1147 Ctx.
Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1149 return new (Mem)
WhileStmt(Ctx, Var, Cond, Body, WL, LParenLoc, RParenLoc);
1154 Ctx.
Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1163 return cast<VarDecl>(DS->getSingleDecl());
1168 "This while statement has no storage for a condition variable!");
1171 getTrailingObjects<Stmt *>()[varOffset()] =
nullptr;
1176 getTrailingObjects<Stmt *>()[varOffset()] =
new (Ctx)
1182 if (
auto *E = dyn_cast<AddrLabelExpr>(
getTarget()->IgnoreParenImpCasts()))
1183 return E->getLabel();
1189 :
Stmt(ReturnStmtClass), RetExpr(E) {
1190 bool HasNRVOCandidate = NRVOCandidate !=
nullptr;
1192 if (HasNRVOCandidate)
1193 setNRVOCandidate(NRVOCandidate);
1197ReturnStmt::ReturnStmt(EmptyShell Empty,
bool HasNRVOCandidate)
1198 :
Stmt(ReturnStmtClass, Empty) {
1204 bool HasNRVOCandidate = NRVOCandidate !=
nullptr;
1205 void *Mem = Ctx.
Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1207 return new (Mem)
ReturnStmt(RL, E, NRVOCandidate);
1211 bool HasNRVOCandidate) {
1212 void *Mem = Ctx.
Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1221 bool CaseStmtIsGNURange = rhs !=
nullptr;
1223 totalSizeToAlloc<Stmt *, SourceLocation>(
1224 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1226 return new (Mem)
CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc);
1230 bool CaseStmtIsGNURange) {
1232 totalSizeToAlloc<Stmt *, SourceLocation>(
1233 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1240 :
Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc) {
1241 Children[TRY] = TryBlock;
1242 Children[HANDLER] = Handler;
1248 return new(
C)
SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
1252 return dyn_cast<SEHExceptStmt>(
getHandler());
1256 return dyn_cast<SEHFinallyStmt>(
getHandler());
1260 :
Stmt(SEHExceptStmtClass), Loc(Loc) {
1261 Children[FILTER_EXPR] = FilterExpr;
1280 : VarAndKind(Var, Kind), Loc(Loc) {
1283 assert(!Var &&
"'this' capture cannot have a variable!");
1286 assert(Var &&
"capturing by reference must have a variable!");
1289 assert(Var &&
"capturing by copy must have a variable!");
1293 "Variable-length array type capture cannot have a variable!");
1300 return VarAndKind.getInt();
1305 "No variable available for 'this' or VAT capture");
1306 return VarAndKind.getPointer();
1313 unsigned FirstCaptureOffset = llvm::alignTo(Size,
alignof(
Capture));
1315 return reinterpret_cast<Capture *
>(
1316 reinterpret_cast<char *
>(
const_cast<CapturedStmt *
>(
this))
1317 + FirstCaptureOffset);
1325 :
Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
1326 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
1327 assert( S &&
"null captured statement");
1328 assert(CD &&
"null captured declaration for captured statement");
1329 assert(RD &&
"null record declaration for captured statement");
1332 Stmt **Stored = getStoredStmts();
1333 for (
unsigned I = 0, N = NumCaptures; I != N; ++I)
1334 *Stored++ = CaptureInits[I];
1340 Capture *Buffer = getStoredCaptures();
1341 std::copy(Captures.begin(), Captures.end(), Buffer);
1344CapturedStmt::CapturedStmt(EmptyShell Empty,
unsigned NumCaptures)
1345 :
Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1347 getStoredStmts()[NumCaptures] =
nullptr;
1350 Capture *Buffer = getStoredCaptures();
1351 for (
unsigned I = 0, N = NumCaptures; I != N; ++I)
1370 assert(CaptureInits.size() == Captures.size() &&
"wrong number of arguments");
1372 unsigned Size =
sizeof(
CapturedStmt) +
sizeof(
Stmt *) * (Captures.size() + 1);
1373 if (!Captures.empty()) {
1375 Size = llvm::alignTo(Size,
alignof(
Capture));
1376 Size +=
sizeof(
Capture) * Captures.size();
1379 void *Mem = Context.
Allocate(Size);
1380 return new (Mem)
CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1384 unsigned NumCaptures) {
1386 if (NumCaptures > 0) {
1388 Size = llvm::alignTo(Size,
alignof(
Capture));
1389 Size +=
sizeof(
Capture) * NumCaptures;
1392 void *Mem = Context.
Allocate(Size);
1398 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1406 return CapDeclAndKind.getPointer();
1410 return CapDeclAndKind.getPointer();
1415 assert(D &&
"null CapturedDecl");
1416 CapDeclAndKind.setPointer(D);
1421 return CapDeclAndKind.getInt();
1426 CapDeclAndKind.setInt(Kind);
1431 if (!I.capturesVariable() && !I.capturesVariableByCopy())
Defines the clang::ASTContext interface.
static StringRef bytes(const std::vector< T, Allocator > &v)
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines the Objective-C statement AST node classes.
This file defines OpenMP AST classes for executable directives and clauses.
static StmtClassNameTable & getStmtInfoTableEntry(Stmt::StmtClass E)
static LLVM_ATTRIBUTE_UNUSED void check_implementations()
Check whether the various Stmt classes implement their member functions.
static StringRef copyIntoContext(const ASTContext &C, StringRef str)
static std::pair< Stmt::Likelihood, const Attr * > getLikelihood(ArrayRef< const Attr * > Attrs)
static struct StmtClassNameTable StmtClassInfo[Stmt::lastStmtConstant+1]
#define BLOCK(DERIVED, BASE)
C Language Family Type Representation.
__device__ __2f16 float __ockl_bool s
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::BumpPtrAllocator & getAllocator() const
void * Allocate(size_t Size, unsigned Align=8) const
AddrLabelExpr - The GNU address of label extension, representing &&label.
LabelDecl * getLabel() const
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
const Expr * getInputExpr(unsigned i) const
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
const Expr * getOutputExpr(unsigned i) const
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
unsigned getNumOutputs() const
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
unsigned getNumInputs() const
StringRef getClobber(unsigned i) const
Attr - This represents one attribute.
Represents an attribute applied to a statement.
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Represents the body of a CapturedStmt, and serves as its DeclContext.
Describes the capture of either a variable, or 'this', or variable-length array type.
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
This captures a statement into a function.
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc.
CaseStmt - Represent a case statement.
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
CompoundStmt - This represents a group of statements like { stmt stmt }.
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts, bool HasFPFeatures)
body_iterator body_begin()
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
This represents one expression.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Represents difference between two FPOptions values.
bool requiresTrailingStorage() const
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
void setConditionVariable(const ASTContext &C, VarDecl *V)
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
char getModifier() const
getModifier - Get the modifier for this operand, if present.
unsigned getNumLabels() const
const StringLiteral * getInputConstraintLiteral(unsigned i) const
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
StringRef getClobber(unsigned i) const
StringRef getLabelName(unsigned i) const
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces.
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
void setInputExpr(unsigned i, Expr *E)
const StringLiteral * getAsmString() const
StringLiteral * getClobberStringLiteral(unsigned i)
StringRef getInputName(unsigned i) const
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile, unsigned numoutputs, unsigned numinputs, IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, StringLiteral **clobbers, unsigned numlabels, SourceLocation rparenloc)
StringRef getOutputName(unsigned i) const
Expr * getOutputExpr(unsigned i)
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Expr * getInputExpr(unsigned i)
AddrLabelExpr * getLabelExpr(unsigned i) const
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
One of these records is kept for each identifier that is lexed.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
IfStmt - This represents an if/then/else.
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable for this if statement.
bool hasVarStorage() const
True if this IfStmt has storage for a variable declaration.
static IfStmt * CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar, bool HasInit)
Create an empty IfStmt optionally with storage for an else statement, condition variable and init exp...
std::optional< const Stmt * > getNondiscardedCase(const ASTContext &Ctx) const
If this is an 'if constexpr', determine which substatement will be taken.
bool isObjCAvailabilityCheck() const
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Represents the declaration of a label.
LabelDecl * getDecl() const
const char * getName() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Expr * getOutputExpr(unsigned i)
void setInputExpr(unsigned i, Expr *E)
MSAsmStmt(const ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, bool issimple, bool isvolatile, ArrayRef< Token > asmtoks, unsigned numoutputs, unsigned numinputs, ArrayRef< StringRef > constraints, ArrayRef< Expr * > exprs, StringRef asmstr, ArrayRef< StringRef > clobbers, SourceLocation endloc)
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Expr * getInputExpr(unsigned i)
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Represents a struct/union/class.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
static ReturnStmt * CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate)
Create an empty return statement, optionally with storage for an NRVO candidate.
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
SEHFinallyStmt * getFinallyHandler() const
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Stmt * getHandler() const
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
WhileStmtBitfields WhileStmtBits
static void EnableStatistics()
SwitchStmtBitfields SwitchStmtBits
const Stmt * stripLabelLikeStatements() const
Strip off all label-like statements.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
llvm::iterator_range< child_iterator > child_range
CompoundStmtBitfields CompoundStmtBits
Likelihood
The likelihood of a branch being taken.
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
@ LH_Likely
Branch has the [[likely]] attribute.
static void addStmtClass(const StmtClass s)
ForStmtBitfields ForStmtBits
const char * getStmtClassName() const
static const Attr * getLikelihoodAttr(const Stmt *S)
Stmt * IgnoreContainers(bool IgnoreCaptured=false)
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top,...
int64_t getID(const ASTContext &Context) const
ReturnStmtBitfields ReturnStmtBits
SourceLocation getBeginLoc() const LLVM_READONLY
llvm::iterator_range< const_child_iterator > const_child_range
static Likelihood getLikelihood(ArrayRef< const Attr * > Attrs)
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
getLocationOfByte - Return a source location that points to the specified byte of this string literal...
StringRef getString() const
SwitchStmt - This represents a 'switch' stmt.
void setRParenLoc(SourceLocation Loc)
void setConditionVariable(const ASTContext &Ctx, VarDecl *VD)
Set the condition variable in this switch statement.
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
void setLParenLoc(SourceLocation Loc)
static SwitchStmt * CreateEmpty(const ASTContext &Ctx, bool HasInit, bool HasVar)
Create an empty switch statement optionally with storage for an init expression and a condition varia...
bool hasVarStorage() const
True if this SwitchStmt has storage for a condition variable.
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Exposes information about the current target.
virtual std::optional< std::string > handleAsmEscapedChar(char C) const
Replace some escaped characters with another string based on target-specific rules.
Token - This structure provides full information about a lexed token.
const Expr * getExprStmt() const
Represents a variable declaration or definition.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
WhileStmt - This represents a 'while' stmt.
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable of this while statement.
bool hasVarStorage() const
True if this WhileStmt has storage for a condition variable.
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
static WhileStmt * CreateEmpty(const ASTContext &Ctx, bool HasVar)
Create an empty while statement optionally with storage for a condition variable.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
CapturedRegionKind
The different kinds of captured statement.
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....