clang 20.0.0git
Stmt.cpp
Go to the documentation of this file.
1//===- Stmt.cpp - Statement AST Node Implementation -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Stmt class and statement subclasses.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/AST/Stmt.h"
16#include "clang/AST/Attr.h"
17#include "clang/AST/Decl.h"
18#include "clang/AST/DeclGroup.h"
19#include "clang/AST/Expr.h"
20#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
28#include "clang/AST/Type.h"
30#include "clang/Basic/LLVM.h"
33#include "clang/Lex/Token.h"
34#include "llvm/ADT/SmallVector.h"
35#include "llvm/ADT/StringExtras.h"
36#include "llvm/ADT/StringRef.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"
41#include <algorithm>
42#include <cassert>
43#include <cstring>
44#include <optional>
45#include <string>
46#include <utility>
47
48using namespace clang;
49
50static struct StmtClassNameTable {
51 const char *Name;
52 unsigned Counter;
53 unsigned Size;
54} StmtClassInfo[Stmt::lastStmtConstant+1];
55
57 static bool Initialized = false;
58 if (Initialized)
59 return StmtClassInfo[E];
60
61 // Initialize the table on the first use.
62 Initialized = true;
63#define ABSTRACT_STMT(STMT)
64#define STMT(CLASS, PARENT) \
65 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
66 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
67#include "clang/AST/StmtNodes.inc"
68
69 return StmtClassInfo[E];
70}
71
72void *Stmt::operator new(size_t bytes, const ASTContext& C,
73 unsigned alignment) {
74 return ::operator new(bytes, C, alignment);
75}
76
77const char *Stmt::getStmtClassName() const {
79}
80
81// Check that no statement / expression class is polymorphic. LLVM style RTTI
82// should be used instead. If absolutely needed an exception can still be added
83// here by defining the appropriate macro (but please don't do this).
84#define STMT(CLASS, PARENT) \
85 static_assert(!std::is_polymorphic<CLASS>::value, \
86 #CLASS " should not be polymorphic!");
87#include "clang/AST/StmtNodes.inc"
88
89// Check that no statement / expression class has a non-trival destructor.
90// Statements and expressions are allocated with the BumpPtrAllocator from
91// ASTContext and therefore their destructor is not executed.
92#define STMT(CLASS, PARENT) \
93 static_assert(std::is_trivially_destructible<CLASS>::value, \
94 #CLASS " should be trivially destructible!");
95// FIXME: InitListExpr is not trivially destructible due to its ASTVector.
96#define INITLISTEXPR(CLASS, PARENT)
97#include "clang/AST/StmtNodes.inc"
98
100 // Ensure the table is primed.
101 getStmtInfoTableEntry(Stmt::NullStmtClass);
102
103 unsigned sum = 0;
104 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
105 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
106 if (StmtClassInfo[i].Name == nullptr) continue;
107 sum += StmtClassInfo[i].Counter;
108 }
109 llvm::errs() << " " << sum << " stmts/exprs total.\n";
110 sum = 0;
111 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
112 if (StmtClassInfo[i].Name == nullptr) continue;
113 if (StmtClassInfo[i].Counter == 0) continue;
114 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
115 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
116 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
117 << " bytes)\n";
119 }
120
121 llvm::errs() << "Total bytes = " << sum << "\n";
122}
123
126}
127
128bool Stmt::StatisticsEnabled = false;
130 StatisticsEnabled = true;
131}
132
133static std::pair<Stmt::Likelihood, const Attr *>
135 for (const auto *A : Attrs) {
136 if (isa<LikelyAttr>(A))
137 return std::make_pair(Stmt::LH_Likely, A);
138
139 if (isa<UnlikelyAttr>(A))
140 return std::make_pair(Stmt::LH_Unlikely, A);
141 }
142
143 return std::make_pair(Stmt::LH_None, nullptr);
144}
145
146static std::pair<Stmt::Likelihood, const Attr *> getLikelihood(const Stmt *S) {
147 if (const auto *AS = dyn_cast_or_null<AttributedStmt>(S))
148 return getLikelihood(AS->getAttrs());
149
150 return std::make_pair(Stmt::LH_None, nullptr);
151}
152
154 return ::getLikelihood(Attrs).first;
155}
156
158 return ::getLikelihood(S).first;
159}
160
162 return ::getLikelihood(S).second;
163}
164
166 Likelihood LHT = ::getLikelihood(Then).first;
167 Likelihood LHE = ::getLikelihood(Else).first;
168 if (LHE == LH_None)
169 return LHT;
170
171 // If the same attribute is used on both branches there's a conflict.
172 if (LHT == LHE)
173 return LH_None;
174
175 if (LHT != LH_None)
176 return LHT;
177
178 // Invert the value of Else to get the value for Then.
179 return LHE == LH_Likely ? LH_Unlikely : LH_Likely;
180}
181
182std::tuple<bool, const Attr *, const Attr *>
183Stmt::determineLikelihoodConflict(const Stmt *Then, const Stmt *Else) {
184 std::pair<Likelihood, const Attr *> LHT = ::getLikelihood(Then);
185 std::pair<Likelihood, const Attr *> LHE = ::getLikelihood(Else);
186 // If the same attribute is used on both branches there's a conflict.
187 if (LHT.first != LH_None && LHT.first == LHE.first)
188 return std::make_tuple(true, LHT.second, LHE.second);
189
190 return std::make_tuple(false, nullptr, nullptr);
191}
192
193/// Skip no-op (attributed, compound) container stmts and skip captured
194/// stmt at the top, if \a IgnoreCaptured is true.
195Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
196 Stmt *S = this;
197 if (IgnoreCaptured)
198 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
199 S = CapS->getCapturedStmt();
200 while (true) {
201 if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
202 S = AS->getSubStmt();
203 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
204 if (CS->size() != 1)
205 break;
206 S = CS->body_back();
207 } else
208 break;
209 }
210 return S;
211}
212
213/// Strip off all label-like statements.
214///
215/// This will strip off label statements, case statements, attributed
216/// statements and default statements recursively.
218 const Stmt *S = this;
219 while (true) {
220 if (const auto *LS = dyn_cast<LabelStmt>(S))
221 S = LS->getSubStmt();
222 else if (const auto *SC = dyn_cast<SwitchCase>(S))
223 S = SC->getSubStmt();
224 else if (const auto *AS = dyn_cast<AttributedStmt>(S))
225 S = AS->getSubStmt();
226 else
227 return S;
228 }
229}
230
231namespace {
232
233 struct good {};
234 struct bad {};
235
236 // These silly little functions have to be static inline to suppress
237 // unused warnings, and they have to be defined to suppress other
238 // warnings.
239 static good is_good(good) { return good(); }
240
241 typedef Stmt::child_range children_t();
242 template <class T> good implements_children(children_t T::*) {
243 return good();
244 }
245 LLVM_ATTRIBUTE_UNUSED
246 static bad implements_children(children_t Stmt::*) {
247 return bad();
248 }
249
250 typedef SourceLocation getBeginLoc_t() const;
251 template <class T> good implements_getBeginLoc(getBeginLoc_t T::*) {
252 return good();
253 }
254 LLVM_ATTRIBUTE_UNUSED
255 static bad implements_getBeginLoc(getBeginLoc_t Stmt::*) { return bad(); }
256
257 typedef SourceLocation getLocEnd_t() const;
258 template <class T> good implements_getEndLoc(getLocEnd_t T::*) {
259 return good();
260 }
261 LLVM_ATTRIBUTE_UNUSED
262 static bad implements_getEndLoc(getLocEnd_t Stmt::*) { return bad(); }
263
264#define ASSERT_IMPLEMENTS_children(type) \
265 (void) is_good(implements_children(&type::children))
266#define ASSERT_IMPLEMENTS_getBeginLoc(type) \
267 (void)is_good(implements_getBeginLoc(&type::getBeginLoc))
268#define ASSERT_IMPLEMENTS_getEndLoc(type) \
269 (void)is_good(implements_getEndLoc(&type::getEndLoc))
270
271} // namespace
272
273/// Check whether the various Stmt classes implement their member
274/// functions.
275LLVM_ATTRIBUTE_UNUSED
276static inline void check_implementations() {
277#define ABSTRACT_STMT(type)
278#define STMT(type, base) \
279 ASSERT_IMPLEMENTS_children(type); \
280 ASSERT_IMPLEMENTS_getBeginLoc(type); \
281 ASSERT_IMPLEMENTS_getEndLoc(type);
282#include "clang/AST/StmtNodes.inc"
283}
284
286 switch (getStmtClass()) {
287 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
288#define ABSTRACT_STMT(type)
289#define STMT(type, base) \
290 case Stmt::type##Class: \
291 return static_cast<type*>(this)->children();
292#include "clang/AST/StmtNodes.inc"
293 }
294 llvm_unreachable("unknown statement kind!");
295}
296
297// Amusing macro metaprogramming hack: check whether a class provides
298// a more specific implementation of getSourceRange.
299//
300// See also Expr.cpp:getExprLoc().
301namespace {
302
303 /// This implementation is used when a class provides a custom
304 /// implementation of getSourceRange.
305 template <class S, class T>
306 SourceRange getSourceRangeImpl(const Stmt *stmt,
307 SourceRange (T::*v)() const) {
308 return static_cast<const S*>(stmt)->getSourceRange();
309 }
310
311 /// This implementation is used when a class doesn't provide a custom
312 /// implementation of getSourceRange. Overload resolution should pick it over
313 /// the implementation above because it's more specialized according to
314 /// function template partial ordering.
315 template <class S>
316 SourceRange getSourceRangeImpl(const Stmt *stmt,
317 SourceRange (Stmt::*v)() const) {
318 return SourceRange(static_cast<const S *>(stmt)->getBeginLoc(),
319 static_cast<const S *>(stmt)->getEndLoc());
320 }
321
322} // namespace
323
325 switch (getStmtClass()) {
326 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
327#define ABSTRACT_STMT(type)
328#define STMT(type, base) \
329 case Stmt::type##Class: \
330 return getSourceRangeImpl<type>(this, &type::getSourceRange);
331#include "clang/AST/StmtNodes.inc"
332 }
333 llvm_unreachable("unknown statement kind!");
334}
335
337 switch (getStmtClass()) {
338 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
339#define ABSTRACT_STMT(type)
340#define STMT(type, base) \
341 case Stmt::type##Class: \
342 return static_cast<const type *>(this)->getBeginLoc();
343#include "clang/AST/StmtNodes.inc"
344 }
345 llvm_unreachable("unknown statement kind");
346}
347
349 switch (getStmtClass()) {
350 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
351#define ABSTRACT_STMT(type)
352#define STMT(type, base) \
353 case Stmt::type##Class: \
354 return static_cast<const type *>(this)->getEndLoc();
355#include "clang/AST/StmtNodes.inc"
356 }
357 llvm_unreachable("unknown statement kind");
358}
359
360int64_t Stmt::getID(const ASTContext &Context) const {
361 return Context.getAllocator().identifyKnownAlignedObject<Stmt>(this);
362}
363
364CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, FPOptionsOverride FPFeatures,
366 : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
367 CompoundStmtBits.NumStmts = Stmts.size();
368 CompoundStmtBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
369 setStmts(Stmts);
370 if (hasStoredFPFeatures())
371 setStoredFPFeatures(FPFeatures);
372}
373
374void CompoundStmt::setStmts(ArrayRef<Stmt *> Stmts) {
375 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
376 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
377
378 std::copy(Stmts.begin(), Stmts.end(), body_begin());
379}
380
382 FPOptionsOverride FPFeatures,
384 void *Mem =
385 C.Allocate(totalSizeToAlloc<Stmt *, FPOptionsOverride>(
386 Stmts.size(), FPFeatures.requiresTrailingStorage()),
387 alignof(CompoundStmt));
388 return new (Mem) CompoundStmt(Stmts, FPFeatures, LB, RB);
389}
390
392 bool HasFPFeatures) {
393 void *Mem = C.Allocate(
394 totalSizeToAlloc<Stmt *, FPOptionsOverride>(NumStmts, HasFPFeatures),
395 alignof(CompoundStmt));
396 CompoundStmt *New = new (Mem) CompoundStmt(EmptyShell());
397 New->CompoundStmtBits.NumStmts = NumStmts;
398 New->CompoundStmtBits.HasFPFeatures = HasFPFeatures;
399 return New;
400}
401
403 const Stmt *S = this;
404 do {
405 if (const auto *E = dyn_cast<Expr>(S))
406 return E;
407
408 if (const auto *LS = dyn_cast<LabelStmt>(S))
409 S = LS->getSubStmt();
410 else if (const auto *AS = dyn_cast<AttributedStmt>(S))
411 S = AS->getSubStmt();
412 else
413 llvm_unreachable("unknown kind of ValueStmt");
414 } while (isa<ValueStmt>(S));
415
416 return nullptr;
417}
418
419const char *LabelStmt::getName() const {
420 return getDecl()->getIdentifier()->getNameStart();
421}
422
425 Stmt *SubStmt) {
426 assert(!Attrs.empty() && "Attrs should not be empty");
427 void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(Attrs.size()),
428 alignof(AttributedStmt));
429 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
430}
431
433 unsigned NumAttrs) {
434 assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
435 void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(NumAttrs),
436 alignof(AttributedStmt));
437 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
438}
439
440std::string AsmStmt::generateAsmString(const ASTContext &C) const {
441 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
442 return gccAsmStmt->generateAsmString(C);
443 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
444 return msAsmStmt->generateAsmString(C);
445 llvm_unreachable("unknown asm statement kind!");
446}
447
448StringRef AsmStmt::getOutputConstraint(unsigned i) const {
449 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
450 return gccAsmStmt->getOutputConstraint(i);
451 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
452 return msAsmStmt->getOutputConstraint(i);
453 llvm_unreachable("unknown asm statement kind!");
454}
455
456const Expr *AsmStmt::getOutputExpr(unsigned i) const {
457 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
458 return gccAsmStmt->getOutputExpr(i);
459 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
460 return msAsmStmt->getOutputExpr(i);
461 llvm_unreachable("unknown asm statement kind!");
462}
463
464StringRef AsmStmt::getInputConstraint(unsigned i) const {
465 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
466 return gccAsmStmt->getInputConstraint(i);
467 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
468 return msAsmStmt->getInputConstraint(i);
469 llvm_unreachable("unknown asm statement kind!");
470}
471
472const Expr *AsmStmt::getInputExpr(unsigned i) const {
473 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
474 return gccAsmStmt->getInputExpr(i);
475 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
476 return msAsmStmt->getInputExpr(i);
477 llvm_unreachable("unknown asm statement kind!");
478}
479
480StringRef AsmStmt::getClobber(unsigned i) const {
481 if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
482 return gccAsmStmt->getClobber(i);
483 if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
484 return msAsmStmt->getClobber(i);
485 llvm_unreachable("unknown asm statement kind!");
486}
487
488/// getNumPlusOperands - Return the number of output operands that have a "+"
489/// constraint.
491 unsigned Res = 0;
492 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
494 ++Res;
495 return Res;
496}
497
499 assert(isOperand() && "Only Operands can have modifiers.");
500 return isLetter(Str[0]) ? Str[0] : '\0';
501}
502
503StringRef GCCAsmStmt::getClobber(unsigned i) const {
505}
506
508 return cast<Expr>(Exprs[i]);
509}
510
511/// getOutputConstraint - Return the constraint string for the specified
512/// output operand. All output constraints are known to be non-empty (either
513/// '=' or '+').
514StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
516}
517
519 return cast<Expr>(Exprs[i + NumOutputs]);
520}
521
522void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
523 Exprs[i + NumOutputs] = E;
524}
525
527 return cast<AddrLabelExpr>(Exprs[i + NumOutputs + NumInputs]);
528}
529
530StringRef GCCAsmStmt::getLabelName(unsigned i) const {
531 return getLabelExpr(i)->getLabel()->getName();
532}
533
534/// getInputConstraint - Return the specified input constraint. Unlike output
535/// constraints, these can be empty.
536StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
538}
539
540void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
541 IdentifierInfo **Names,
542 StringLiteral **Constraints,
543 Stmt **Exprs,
544 unsigned NumOutputs,
545 unsigned NumInputs,
546 unsigned NumLabels,
547 StringLiteral **Clobbers,
548 unsigned NumClobbers) {
549 this->NumOutputs = NumOutputs;
550 this->NumInputs = NumInputs;
551 this->NumClobbers = NumClobbers;
552 this->NumLabels = NumLabels;
553
554 unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
555
556 C.Deallocate(this->Names);
557 this->Names = new (C) IdentifierInfo*[NumExprs];
558 std::copy(Names, Names + NumExprs, this->Names);
559
560 C.Deallocate(this->Exprs);
561 this->Exprs = new (C) Stmt*[NumExprs];
562 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
563
565 C.Deallocate(this->Constraints);
566 this->Constraints = new (C) StringLiteral*[NumConstraints];
567 std::copy(Constraints, Constraints + NumConstraints, this->Constraints);
568
569 C.Deallocate(this->Clobbers);
570 this->Clobbers = new (C) StringLiteral*[NumClobbers];
571 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
572}
573
574/// getNamedOperand - Given a symbolic operand reference like %[foo],
575/// translate this into a numeric value needed to reference the same operand.
576/// This returns -1 if the operand name is invalid.
577int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
578 // Check if this is an output operand.
579 unsigned NumOutputs = getNumOutputs();
580 for (unsigned i = 0; i != NumOutputs; ++i)
581 if (getOutputName(i) == SymbolicName)
582 return i;
583
584 unsigned NumInputs = getNumInputs();
585 for (unsigned i = 0; i != NumInputs; ++i)
586 if (getInputName(i) == SymbolicName)
587 return NumOutputs + i;
588
589 for (unsigned i = 0, e = getNumLabels(); i != e; ++i)
590 if (getLabelName(i) == SymbolicName)
591 return NumOutputs + NumInputs + getNumPlusOperands() + i;
592
593 // Not found.
594 return -1;
595}
596
597/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
598/// it into pieces. If the asm string is erroneous, emit errors and return
599/// true, otherwise return false.
601 const ASTContext &C, unsigned &DiagOffs) const {
602 StringRef Str = getAsmString()->getString();
603 const char *StrStart = Str.begin();
604 const char *StrEnd = Str.end();
605 const char *CurPtr = StrStart;
606
607 // "Simple" inline asms have no constraints or operands, just convert the asm
608 // string to escape $'s.
609 if (isSimple()) {
610 std::string Result;
611 for (; CurPtr != StrEnd; ++CurPtr) {
612 switch (*CurPtr) {
613 case '$':
614 Result += "$$";
615 break;
616 default:
617 Result += *CurPtr;
618 break;
619 }
620 }
621 Pieces.push_back(AsmStringPiece(Result));
622 return 0;
623 }
624
625 // CurStringPiece - The current string that we are building up as we scan the
626 // asm string.
627 std::string CurStringPiece;
628
629 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
630
631 unsigned LastAsmStringToken = 0;
632 unsigned LastAsmStringOffset = 0;
633
634 while (true) {
635 // Done with the string?
636 if (CurPtr == StrEnd) {
637 if (!CurStringPiece.empty())
638 Pieces.push_back(AsmStringPiece(CurStringPiece));
639 return 0;
640 }
641
642 char CurChar = *CurPtr++;
643 switch (CurChar) {
644 case '$': CurStringPiece += "$$"; continue;
645 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
646 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
647 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
648 case '%':
649 break;
650 default:
651 CurStringPiece += CurChar;
652 continue;
653 }
654
655 const TargetInfo &TI = C.getTargetInfo();
656
657 // Escaped "%" character in asm string.
658 if (CurPtr == StrEnd) {
659 // % at end of string is invalid (no escape).
660 DiagOffs = CurPtr-StrStart-1;
661 return diag::err_asm_invalid_escape;
662 }
663 // Handle escaped char and continue looping over the asm string.
664 char EscapedChar = *CurPtr++;
665 switch (EscapedChar) {
666 default:
667 // Handle target-specific escaped characters.
668 if (auto MaybeReplaceStr = TI.handleAsmEscapedChar(EscapedChar)) {
669 CurStringPiece += *MaybeReplaceStr;
670 continue;
671 }
672 break;
673 case '%': // %% -> %
674 case '{': // %{ -> {
675 case '}': // %} -> }
676 CurStringPiece += EscapedChar;
677 continue;
678 case '=': // %= -> Generate a unique ID.
679 CurStringPiece += "${:uid}";
680 continue;
681 }
682
683 // Otherwise, we have an operand. If we have accumulated a string so far,
684 // add it to the Pieces list.
685 if (!CurStringPiece.empty()) {
686 Pieces.push_back(AsmStringPiece(CurStringPiece));
687 CurStringPiece.clear();
688 }
689
690 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
691 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
692
693 const char *Begin = CurPtr - 1; // Points to the character following '%'.
694 const char *Percent = Begin - 1; // Points to '%'.
695
696 if (isLetter(EscapedChar)) {
697 if (CurPtr == StrEnd) { // Premature end.
698 DiagOffs = CurPtr-StrStart-1;
699 return diag::err_asm_invalid_escape;
700 }
701 EscapedChar = *CurPtr++;
702 }
703
704 const SourceManager &SM = C.getSourceManager();
705 const LangOptions &LO = C.getLangOpts();
706
707 // Handle operands that don't have asmSymbolicName (e.g., %x4).
708 if (isDigit(EscapedChar)) {
709 // %n - Assembler operand n
710 unsigned N = 0;
711
712 --CurPtr;
713 while (CurPtr != StrEnd && isDigit(*CurPtr))
714 N = N*10 + ((*CurPtr++)-'0');
715
716 unsigned NumOperands = getNumOutputs() + getNumPlusOperands() +
718 if (N >= NumOperands) {
719 DiagOffs = CurPtr-StrStart-1;
720 return diag::err_asm_invalid_operand_number;
721 }
722
723 // Str contains "x4" (Operand without the leading %).
724 std::string Str(Begin, CurPtr - Begin);
725
726 // (BeginLoc, EndLoc) represents the range of the operand we are currently
727 // processing. Unlike Str, the range includes the leading '%'.
729 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
730 &LastAsmStringOffset);
732 CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
733 &LastAsmStringOffset);
734
735 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
736 continue;
737 }
738
739 // Handle operands that have asmSymbolicName (e.g., %x[foo]).
740 if (EscapedChar == '[') {
741 DiagOffs = CurPtr-StrStart-1;
742
743 // Find the ']'.
744 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
745 if (NameEnd == nullptr)
746 return diag::err_asm_unterminated_symbolic_operand_name;
747 if (NameEnd == CurPtr)
748 return diag::err_asm_empty_symbolic_operand_name;
749
750 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
751
752 int N = getNamedOperand(SymbolicName);
753 if (N == -1) {
754 // Verify that an operand with that name exists.
755 DiagOffs = CurPtr-StrStart;
756 return diag::err_asm_unknown_symbolic_operand_name;
757 }
758
759 // Str contains "x[foo]" (Operand without the leading %).
760 std::string Str(Begin, NameEnd + 1 - Begin);
761
762 // (BeginLoc, EndLoc) represents the range of the operand we are currently
763 // processing. Unlike Str, the range includes the leading '%'.
765 Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
766 &LastAsmStringOffset);
768 NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
769 &LastAsmStringOffset);
770
771 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
772
773 CurPtr = NameEnd+1;
774 continue;
775 }
776
777 DiagOffs = CurPtr-StrStart-1;
778 return diag::err_asm_invalid_escape;
779 }
780}
781
782/// Assemble final IR asm string (GCC-style).
783std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
784 // Analyze the asm string to decompose it into its pieces. We know that Sema
785 // has already done this, so it is guaranteed to be successful.
787 unsigned DiagOffs;
788 AnalyzeAsmString(Pieces, C, DiagOffs);
789
790 std::string AsmString;
791 for (const auto &Piece : Pieces) {
792 if (Piece.isString())
793 AsmString += Piece.getString();
794 else if (Piece.getModifier() == '\0')
795 AsmString += '$' + llvm::utostr(Piece.getOperandNo());
796 else
797 AsmString += "${" + llvm::utostr(Piece.getOperandNo()) + ':' +
798 Piece.getModifier() + '}';
799 }
800 return AsmString;
801}
802
803/// Assemble final IR asm string (MS-style).
804std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
805 // FIXME: This needs to be translated into the IR string representation.
807 AsmStr.split(Pieces, "\n\t");
808 std::string MSAsmString;
809 for (size_t I = 0, E = Pieces.size(); I < E; ++I) {
810 StringRef Instruction = Pieces[I];
811 // For vex/vex2/vex3/evex masm style prefix, convert it to att style
812 // since we don't support masm style prefix in backend.
813 if (Instruction.starts_with("vex "))
814 MSAsmString += '{' + Instruction.substr(0, 3).str() + '}' +
815 Instruction.substr(3).str();
816 else if (Instruction.starts_with("vex2 ") ||
817 Instruction.starts_with("vex3 ") ||
818 Instruction.starts_with("evex "))
819 MSAsmString += '{' + Instruction.substr(0, 4).str() + '}' +
820 Instruction.substr(4).str();
821 else
822 MSAsmString += Instruction.str();
823 // If this is not the last instruction, adding back the '\n\t'.
824 if (I < E - 1)
825 MSAsmString += "\n\t";
826 }
827 return MSAsmString;
828}
829
831 return cast<Expr>(Exprs[i]);
832}
833
835 return cast<Expr>(Exprs[i + NumOutputs]);
836}
837
838void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
839 Exprs[i + NumOutputs] = E;
840}
841
842//===----------------------------------------------------------------------===//
843// Constructors
844//===----------------------------------------------------------------------===//
845
847 bool issimple, bool isvolatile, unsigned numoutputs,
848 unsigned numinputs, IdentifierInfo **names,
849 StringLiteral **constraints, Expr **exprs,
850 StringLiteral *asmstr, unsigned numclobbers,
851 StringLiteral **clobbers, unsigned numlabels,
852 SourceLocation rparenloc)
853 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
854 numinputs, numclobbers),
855 RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
856 unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
857
858 Names = new (C) IdentifierInfo*[NumExprs];
859 std::copy(names, names + NumExprs, Names);
860
861 Exprs = new (C) Stmt*[NumExprs];
862 std::copy(exprs, exprs + NumExprs, Exprs);
863
865 Constraints = new (C) StringLiteral*[NumConstraints];
866 std::copy(constraints, constraints + NumConstraints, Constraints);
867
868 Clobbers = new (C) StringLiteral*[NumClobbers];
869 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
870}
871
873 SourceLocation lbraceloc, bool issimple, bool isvolatile,
874 ArrayRef<Token> asmtoks, unsigned numoutputs,
875 unsigned numinputs,
876 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
877 StringRef asmstr, ArrayRef<StringRef> clobbers,
878 SourceLocation endloc)
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);
883}
884
885static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
886 return str.copy(C);
887}
888
889void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
890 ArrayRef<Token> asmtoks,
891 ArrayRef<StringRef> constraints,
892 ArrayRef<Expr*> exprs,
893 ArrayRef<StringRef> clobbers) {
894 assert(NumAsmToks == asmtoks.size());
895 assert(NumClobbers == clobbers.size());
896
897 assert(exprs.size() == NumOutputs + NumInputs);
898 assert(exprs.size() == constraints.size());
899
900 AsmStr = copyIntoContext(C, asmstr);
901
902 Exprs = new (C) Stmt*[exprs.size()];
903 std::copy(exprs.begin(), exprs.end(), Exprs);
904
905 AsmToks = new (C) Token[asmtoks.size()];
906 std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
907
908 Constraints = new (C) StringRef[exprs.size()];
909 std::transform(constraints.begin(), constraints.end(), Constraints,
910 [&](StringRef Constraint) {
911 return copyIntoContext(C, Constraint);
912 });
913
914 Clobbers = new (C) StringRef[NumClobbers];
915 // FIXME: Avoid the allocation/copy if at all possible.
916 std::transform(clobbers.begin(), clobbers.end(), Clobbers,
917 [&](StringRef Clobber) {
918 return copyIntoContext(C, Clobber);
919 });
920}
921
922IfStmt::IfStmt(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind,
923 Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL,
924 SourceLocation RPL, Stmt *Then, SourceLocation EL, Stmt *Else)
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;
932
933 setStatementKind(Kind);
934
935 setCond(Cond);
936 setThen(Then);
937 if (HasElse)
938 setElse(Else);
939 if (HasVar)
940 setConditionVariable(Ctx, Var);
941 if (HasInit)
942 setInit(Init);
943
944 setIfLoc(IL);
945 if (HasElse)
946 setElseLoc(EL);
947}
948
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;
954}
955
957 IfStatementKind Kind, Stmt *Init, VarDecl *Var,
958 Expr *Cond, SourceLocation LPL, SourceLocation RPL,
959 Stmt *Then, SourceLocation EL, Stmt *Else) {
960 bool HasElse = Else != nullptr;
961 bool HasVar = Var != nullptr;
962 bool HasInit = Init != nullptr;
963 void *Mem = Ctx.Allocate(
964 totalSizeToAlloc<Stmt *, SourceLocation>(
965 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
966 alignof(IfStmt));
967 return new (Mem)
968 IfStmt(Ctx, IL, Kind, Init, Var, Cond, LPL, RPL, Then, EL, Else);
969}
970
971IfStmt *IfStmt::CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
972 bool HasInit) {
973 void *Mem = Ctx.Allocate(
974 totalSizeToAlloc<Stmt *, SourceLocation>(
975 NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
976 alignof(IfStmt));
977 return new (Mem) IfStmt(EmptyShell(), HasElse, HasVar, HasInit);
978}
979
981 auto *DS = getConditionVariableDeclStmt();
982 if (!DS)
983 return nullptr;
984 return cast<VarDecl>(DS->getSingleDecl());
985}
986
988 assert(hasVarStorage() &&
989 "This if statement has no storage for a condition variable!");
990
991 if (!V) {
992 getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
993 return;
994 }
995
996 SourceRange VarRange = V->getSourceRange();
997 getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
998 DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
999}
1000
1002 return isa<ObjCAvailabilityCheckExpr>(getCond());
1003}
1004
1005std::optional<Stmt *> IfStmt::getNondiscardedCase(const ASTContext &Ctx) {
1006 if (!isConstexpr() || getCond()->isValueDependent())
1007 return std::nullopt;
1008 return !getCond()->EvaluateKnownConstInt(Ctx) ? getElse() : getThen();
1009}
1010
1011std::optional<const Stmt *>
1013 if (std::optional<Stmt *> Result =
1014 const_cast<IfStmt *>(this)->getNondiscardedCase(Ctx))
1015 return *Result;
1016 return std::nullopt;
1017}
1018
1020 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1021 SourceLocation RP)
1022 : Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP)
1023{
1024 SubExprs[INIT] = Init;
1025 setConditionVariable(C, condVar);
1026 SubExprs[COND] = Cond;
1027 SubExprs[INC] = Inc;
1028 SubExprs[BODY] = Body;
1029 ForStmtBits.ForLoc = FL;
1030}
1031
1033 if (!SubExprs[CONDVAR])
1034 return nullptr;
1035
1036 auto *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
1037 return cast<VarDecl>(DS->getSingleDecl());
1038}
1039
1041 if (!V) {
1042 SubExprs[CONDVAR] = nullptr;
1043 return;
1044 }
1045
1046 SourceRange VarRange = V->getSourceRange();
1047 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
1048 VarRange.getEnd());
1049}
1050
1051SwitchStmt::SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
1052 Expr *Cond, SourceLocation LParenLoc,
1053 SourceLocation RParenLoc)
1054 : Stmt(SwitchStmtClass), FirstCase(nullptr), LParenLoc(LParenLoc),
1055 RParenLoc(RParenLoc) {
1056 bool HasInit = Init != nullptr;
1057 bool HasVar = Var != nullptr;
1058 SwitchStmtBits.HasInit = HasInit;
1059 SwitchStmtBits.HasVar = HasVar;
1060 SwitchStmtBits.AllEnumCasesCovered = false;
1061
1062 setCond(Cond);
1063 setBody(nullptr);
1064 if (HasInit)
1065 setInit(Init);
1066 if (HasVar)
1067 setConditionVariable(Ctx, Var);
1068
1069 setSwitchLoc(SourceLocation{});
1070}
1071
1072SwitchStmt::SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar)
1073 : Stmt(SwitchStmtClass, Empty) {
1074 SwitchStmtBits.HasInit = HasInit;
1075 SwitchStmtBits.HasVar = HasVar;
1076 SwitchStmtBits.AllEnumCasesCovered = false;
1077}
1078
1080 Expr *Cond, SourceLocation LParenLoc,
1081 SourceLocation RParenLoc) {
1082 bool HasInit = Init != nullptr;
1083 bool HasVar = Var != nullptr;
1084 void *Mem = Ctx.Allocate(
1085 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1086 alignof(SwitchStmt));
1087 return new (Mem) SwitchStmt(Ctx, Init, Var, Cond, LParenLoc, RParenLoc);
1088}
1089
1091 bool HasVar) {
1092 void *Mem = Ctx.Allocate(
1093 totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1094 alignof(SwitchStmt));
1095 return new (Mem) SwitchStmt(EmptyShell(), HasInit, HasVar);
1096}
1097
1099 auto *DS = getConditionVariableDeclStmt();
1100 if (!DS)
1101 return nullptr;
1102 return cast<VarDecl>(DS->getSingleDecl());
1103}
1104
1106 assert(hasVarStorage() &&
1107 "This switch statement has no storage for a condition variable!");
1108
1109 if (!V) {
1110 getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1111 return;
1112 }
1113
1114 SourceRange VarRange = V->getSourceRange();
1115 getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1116 DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
1117}
1118
1119WhileStmt::WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
1120 Stmt *Body, SourceLocation WL, SourceLocation LParenLoc,
1121 SourceLocation RParenLoc)
1122 : Stmt(WhileStmtClass) {
1123 bool HasVar = Var != nullptr;
1124 WhileStmtBits.HasVar = HasVar;
1125
1126 setCond(Cond);
1127 setBody(Body);
1128 if (HasVar)
1129 setConditionVariable(Ctx, Var);
1130
1131 setWhileLoc(WL);
1132 setLParenLoc(LParenLoc);
1133 setRParenLoc(RParenLoc);
1134}
1135
1136WhileStmt::WhileStmt(EmptyShell Empty, bool HasVar)
1137 : Stmt(WhileStmtClass, Empty) {
1138 WhileStmtBits.HasVar = HasVar;
1139}
1140
1142 Stmt *Body, SourceLocation WL,
1143 SourceLocation LParenLoc,
1144 SourceLocation RParenLoc) {
1145 bool HasVar = Var != nullptr;
1146 void *Mem =
1147 Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1148 alignof(WhileStmt));
1149 return new (Mem) WhileStmt(Ctx, Var, Cond, Body, WL, LParenLoc, RParenLoc);
1150}
1151
1153 void *Mem =
1154 Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1155 alignof(WhileStmt));
1156 return new (Mem) WhileStmt(EmptyShell(), HasVar);
1157}
1158
1160 auto *DS = getConditionVariableDeclStmt();
1161 if (!DS)
1162 return nullptr;
1163 return cast<VarDecl>(DS->getSingleDecl());
1164}
1165
1167 assert(hasVarStorage() &&
1168 "This while statement has no storage for a condition variable!");
1169
1170 if (!V) {
1171 getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1172 return;
1173 }
1174
1175 SourceRange VarRange = V->getSourceRange();
1176 getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1177 DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
1178}
1179
1180// IndirectGotoStmt
1182 if (auto *E = dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1183 return E->getLabel();
1184 return nullptr;
1185}
1186
1187// ReturnStmt
1188ReturnStmt::ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1189 : Stmt(ReturnStmtClass), RetExpr(E) {
1190 bool HasNRVOCandidate = NRVOCandidate != nullptr;
1191 ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate;
1192 if (HasNRVOCandidate)
1193 setNRVOCandidate(NRVOCandidate);
1194 setReturnLoc(RL);
1195}
1196
1197ReturnStmt::ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate)
1198 : Stmt(ReturnStmtClass, Empty) {
1199 ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate;
1200}
1201
1203 Expr *E, const VarDecl *NRVOCandidate) {
1204 bool HasNRVOCandidate = NRVOCandidate != nullptr;
1205 void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1206 alignof(ReturnStmt));
1207 return new (Mem) ReturnStmt(RL, E, NRVOCandidate);
1208}
1209
1211 bool HasNRVOCandidate) {
1212 void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1213 alignof(ReturnStmt));
1214 return new (Mem) ReturnStmt(EmptyShell(), HasNRVOCandidate);
1215}
1216
1217// CaseStmt
1219 SourceLocation caseLoc, SourceLocation ellipsisLoc,
1220 SourceLocation colonLoc) {
1221 bool CaseStmtIsGNURange = rhs != nullptr;
1222 void *Mem = Ctx.Allocate(
1223 totalSizeToAlloc<Stmt *, SourceLocation>(
1224 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1225 alignof(CaseStmt));
1226 return new (Mem) CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc);
1227}
1228
1230 bool CaseStmtIsGNURange) {
1231 void *Mem = Ctx.Allocate(
1232 totalSizeToAlloc<Stmt *, SourceLocation>(
1233 NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1234 alignof(CaseStmt));
1235 return new (Mem) CaseStmt(EmptyShell(), CaseStmtIsGNURange);
1236}
1237
1238SEHTryStmt::SEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock,
1239 Stmt *Handler)
1240 : Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc) {
1241 Children[TRY] = TryBlock;
1242 Children[HANDLER] = Handler;
1243}
1244
1246 SourceLocation TryLoc, Stmt *TryBlock,
1247 Stmt *Handler) {
1248 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
1249}
1250
1252 return dyn_cast<SEHExceptStmt>(getHandler());
1253}
1254
1256 return dyn_cast<SEHFinallyStmt>(getHandler());
1257}
1258
1259SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
1260 : Stmt(SEHExceptStmtClass), Loc(Loc) {
1261 Children[FILTER_EXPR] = FilterExpr;
1262 Children[BLOCK] = Block;
1263}
1264
1266 Expr *FilterExpr, Stmt *Block) {
1267 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
1268}
1269
1270SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, Stmt *Block)
1271 : Stmt(SEHFinallyStmtClass), Loc(Loc), Block(Block) {}
1272
1274 Stmt *Block) {
1275 return new(C)SEHFinallyStmt(Loc,Block);
1276}
1277
1278CapturedStmt::Capture::Capture(SourceLocation Loc, VariableCaptureKind Kind,
1279 VarDecl *Var)
1280 : VarAndKind(Var, Kind), Loc(Loc) {
1281 switch (Kind) {
1282 case VCK_This:
1283 assert(!Var && "'this' capture cannot have a variable!");
1284 break;
1285 case VCK_ByRef:
1286 assert(Var && "capturing by reference must have a variable!");
1287 break;
1288 case VCK_ByCopy:
1289 assert(Var && "capturing by copy must have a variable!");
1290 break;
1291 case VCK_VLAType:
1292 assert(!Var &&
1293 "Variable-length array type capture cannot have a variable!");
1294 break;
1295 }
1296}
1297
1300 return VarAndKind.getInt();
1301}
1302
1304 assert((capturesVariable() || capturesVariableByCopy()) &&
1305 "No variable available for 'this' or VAT capture");
1306 return VarAndKind.getPointer();
1307}
1308
1309CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
1310 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1311
1312 // Offset of the first Capture object.
1313 unsigned FirstCaptureOffset = llvm::alignTo(Size, alignof(Capture));
1314
1315 return reinterpret_cast<Capture *>(
1316 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1317 + FirstCaptureOffset);
1318}
1319
1320CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1321 ArrayRef<Capture> Captures,
1322 ArrayRef<Expr *> CaptureInits,
1323 CapturedDecl *CD,
1324 RecordDecl *RD)
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");
1330
1331 // Copy initialization expressions.
1332 Stmt **Stored = getStoredStmts();
1333 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1334 *Stored++ = CaptureInits[I];
1335
1336 // Copy the statement being captured.
1337 *Stored = S;
1338
1339 // Copy all Capture objects.
1340 Capture *Buffer = getStoredCaptures();
1341 std::copy(Captures.begin(), Captures.end(), Buffer);
1342}
1343
1344CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1345 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1346 CapDeclAndKind(nullptr, CR_Default) {
1347 getStoredStmts()[NumCaptures] = nullptr;
1348
1349 // Construct default capture objects.
1350 Capture *Buffer = getStoredCaptures();
1351 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1352 new (Buffer++) Capture();
1353}
1354
1356 CapturedRegionKind Kind,
1357 ArrayRef<Capture> Captures,
1358 ArrayRef<Expr *> CaptureInits,
1359 CapturedDecl *CD,
1360 RecordDecl *RD) {
1361 // The layout is
1362 //
1363 // -----------------------------------------------------------
1364 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1365 // ----------------^-------------------^----------------------
1366 // getStoredStmts() getStoredCaptures()
1367 //
1368 // where S is the statement being captured.
1369 //
1370 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1371
1372 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1373 if (!Captures.empty()) {
1374 // Realign for the following Capture array.
1375 Size = llvm::alignTo(Size, alignof(Capture));
1376 Size += sizeof(Capture) * Captures.size();
1377 }
1378
1379 void *Mem = Context.Allocate(Size);
1380 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1381}
1382
1384 unsigned NumCaptures) {
1385 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1386 if (NumCaptures > 0) {
1387 // Realign for the following Capture array.
1388 Size = llvm::alignTo(Size, alignof(Capture));
1389 Size += sizeof(Capture) * NumCaptures;
1390 }
1391
1392 void *Mem = Context.Allocate(Size);
1393 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1394}
1395
1397 // Children are captured field initializers.
1398 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1399}
1400
1402 return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1403}
1404
1406 return CapDeclAndKind.getPointer();
1407}
1408
1410 return CapDeclAndKind.getPointer();
1411}
1412
1413/// Set the outlined function declaration.
1415 assert(D && "null CapturedDecl");
1416 CapDeclAndKind.setPointer(D);
1417}
1418
1419/// Retrieve the captured region kind.
1421 return CapDeclAndKind.getInt();
1422}
1423
1424/// Set the captured region kind.
1426 CapDeclAndKind.setInt(Kind);
1427}
1428
1430 for (const auto &I : captures()) {
1431 if (!I.capturesVariable() && !I.capturesVariableByCopy())
1432 continue;
1433 if (I.getCapturedVar()->getCanonicalDecl() == Var->getCanonicalDecl())
1434 return true;
1435 }
1436
1437 return false;
1438}
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3443
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:131
#define SM(sm)
Definition: Cuda.cpp:84
const Decl * D
Expr * E
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
const CFGBlock * Block
Definition: HTMLLogger.cpp:152
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
static StmtClassNameTable & getStmtInfoTableEntry(Stmt::StmtClass E)
Definition: Stmt.cpp:56
static LLVM_ATTRIBUTE_UNUSED void check_implementations()
Check whether the various Stmt classes implement their member functions.
Definition: Stmt.cpp:276
static StringRef copyIntoContext(const ASTContext &C, StringRef str)
Definition: Stmt.cpp:885
static std::pair< Stmt::Likelihood, const Attr * > getLikelihood(ArrayRef< const Attr * > Attrs)
Definition: Stmt.cpp:134
static struct StmtClassNameTable StmtClassInfo[Stmt::lastStmtConstant+1]
#define BLOCK(DERIVED, BASE)
Definition: Template.h:631
C Language Family Type Representation.
SourceLocation Begin
__device__ __2f16 float __ockl_bool s
do v
Definition: arm_acle.h:91
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
llvm::BumpPtrAllocator & getAllocator() const
Definition: ASTContext.h:750
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:754
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4421
LabelDecl * getLabel() const
Definition: Expr.h:4444
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition: Stmt.h:3137
Stmt ** Exprs
Definition: Stmt.h:3155
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
Definition: Stmt.cpp:490
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:448
const Expr * getInputExpr(unsigned i) const
Definition: Stmt.cpp:472
unsigned NumInputs
Definition: Stmt.h:3152
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition: Stmt.h:3196
const Expr * getOutputExpr(unsigned i) const
Definition: Stmt.cpp:456
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:464
unsigned getNumOutputs() const
Definition: Stmt.h:3186
unsigned NumOutputs
Definition: Stmt.h:3151
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:440
unsigned NumClobbers
Definition: Stmt.h:3153
unsigned getNumInputs() const
Definition: Stmt.h:3208
bool isSimple() const
Definition: Stmt.h:3170
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:480
Attr - This represents one attribute.
Definition: Attr.h:43
Represents an attribute applied to a statement.
Definition: Stmt.h:2117
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition: Stmt.cpp:432
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:423
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4673
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition: Stmt.h:3807
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: Stmt.cpp:1299
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
Definition: Stmt.cpp:1303
This captures a statement into a function.
Definition: Stmt.h:3794
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition: Stmt.cpp:1383
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition: Stmt.cpp:1425
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1405
child_range children()
Definition: Stmt.cpp:1396
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
Definition: Stmt.cpp:1429
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
Definition: Stmt.cpp:1414
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
Definition: Stmt.cpp:1355
capture_range captures()
Definition: Stmt.h:3932
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1420
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc.
Definition: Stmt.h:3798
CaseStmt - Represent a case statement.
Definition: Stmt.h:1838
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1218
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
Definition: Stmt.cpp:1229
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1638
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts, bool HasFPFeatures)
Definition: Stmt.cpp:391
body_iterator body_begin()
Definition: Stmt.h:1702
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:381
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1529
This represents one expression.
Definition: Expr.h:110
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.
Definition: LangOptions.h:978
bool requiresTrailingStorage() const
Definition: LangOptions.h:1004
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
Definition: Stmt.cpp:1019
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:1032
void setBody(Stmt *S)
Definition: Stmt.h:2872
void setCond(Expr *E)
Definition: Stmt.h:2870
void setInit(Stmt *S)
Definition: Stmt.h:2869
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:1040
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:3331
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:498
unsigned getNumLabels() const
Definition: Stmt.h:3445
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:3425
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:783
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:503
StringRef getLabelName(unsigned i) const
Definition: Stmt.cpp:530
unsigned AnalyzeAsmString(SmallVectorImpl< AsmStringPiece > &Pieces, const ASTContext &C, unsigned &DiagOffs) const
AnalyzeAsmString - Analyze the asm string of the current asm, decomposing it into pieces.
Definition: Stmt.cpp:600
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:3397
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:514
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:522
const StringLiteral * getAsmString() const
Definition: Stmt.h:3324
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:3505
StringRef getInputName(unsigned i) const
Definition: Stmt.h:3416
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)
Definition: Stmt.cpp:846
StringRef getOutputName(unsigned i) const
Definition: Stmt.h:3388
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:507
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Definition: Stmt.cpp:577
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:518
AddrLabelExpr * getLabelExpr(unsigned i) const
Definition: Stmt.cpp:526
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:536
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.
Definition: Stmt.h:2175
Stmt * getThen()
Definition: Stmt.h:2264
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.
Definition: Stmt.cpp:956
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable for this if statement.
Definition: Stmt.cpp:987
bool hasVarStorage() const
True if this IfStmt has storage for a variable declaration.
Definition: Stmt.h:2247
Expr * getCond()
Definition: Stmt.h:2252
bool isConstexpr() const
Definition: Stmt.h:2368
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...
Definition: Stmt.cpp:971
std::optional< const Stmt * > getNondiscardedCase(const ASTContext &Ctx) const
If this is an 'if constexpr', determine which substatement will be taken.
Definition: Stmt.cpp:1012
bool isObjCAvailabilityCheck() const
Definition: Stmt.cpp:1001
Stmt * getElse()
Definition: Stmt.h:2273
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
Definition: Stmt.h:2308
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:980
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Definition: Stmt.cpp:1181
Expr * getTarget()
Definition: Stmt.h:2958
Represents the declaration of a label.
Definition: Decl.h:503
LabelDecl * getDecl() const
Definition: Stmt.h:2086
const char * getName() const
Definition: Stmt.cpp:419
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:830
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:838
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)
Definition: Stmt.cpp:872
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:804
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:834
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:280
Represents a struct/union/class.
Definition: Decl.h:4148
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3056
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1202
static ReturnStmt * CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate)
Create an empty return statement, optionally with storage for an NRVO candidate.
Definition: Stmt.cpp:1210
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
Definition: Stmt.cpp:1265
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:1273
SEHFinallyStmt * getFinallyHandler() const
Definition: Stmt.cpp:1255
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Definition: Stmt.cpp:1245
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition: Stmt.cpp:1251
Stmt * getHandler() const
Definition: Stmt.h:3735
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.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
WhileStmtBitfields WhileStmtBits
Definition: Stmt.h:1238
static void EnableStatistics()
Definition: Stmt.cpp:129
SwitchStmtBitfields SwitchStmtBits
Definition: Stmt.h:1237
const Stmt * stripLabelLikeStatements() const
Strip off all label-like statements.
Definition: Stmt.cpp:217
child_range children()
Definition: Stmt.cpp:285
StmtClass getStmtClass() const
Definition: Stmt.h:1390
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
Definition: Stmt.cpp:183
static void PrintStats()
Definition: Stmt.cpp:99
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1479
CompoundStmtBitfields CompoundStmtBits
Definition: Stmt.h:1233
Likelihood
The likelihood of a branch being taken.
Definition: Stmt.h:1333
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
Definition: Stmt.h:1334
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition: Stmt.h:1335
@ LH_Likely
Branch has the [[likely]] attribute.
Definition: Stmt.h:1337
static void addStmtClass(const StmtClass s)
Definition: Stmt.cpp:124
ForStmtBitfields ForStmtBits
Definition: Stmt.h:1240
const char * getStmtClassName() const
Definition: Stmt.cpp:77
static const Attr * getLikelihoodAttr(const Stmt *S)
Definition: Stmt.cpp:161
Stmt * IgnoreContainers(bool IgnoreCaptured=false)
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top,...
Definition: Stmt.cpp:195
StmtBitfields StmtBits
Definition: Stmt.h:1231
int64_t getID(const ASTContext &Context) const
Definition: Stmt.cpp:360
ReturnStmtBitfields ReturnStmtBits
Definition: Stmt.h:1244
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1480
static Likelihood getLikelihood(ArrayRef< const Attr * > Attrs)
Definition: Stmt.cpp:153
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
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...
Definition: Expr.cpp:1325
StringRef getString() const
Definition: Expr.h:1855
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2425
void setCond(Expr *Cond)
Definition: Stmt.h:2496
void setBody(Stmt *Body)
Definition: Stmt.h:2505
void setRParenLoc(SourceLocation Loc)
Definition: Stmt.h:2571
void setConditionVariable(const ASTContext &Ctx, VarDecl *VD)
Set the condition variable in this switch statement.
Definition: Stmt.cpp:1105
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1079
void setLParenLoc(SourceLocation Loc)
Definition: Stmt.h:2569
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...
Definition: Stmt.cpp:1090
bool hasVarStorage() const
True if this SwitchStmt has storage for a condition variable.
Definition: Stmt.h:2486
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:1098
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Definition: Stmt.h:2545
Exposes information about the current target.
Definition: TargetInfo.h:220
virtual std::optional< std::string > handleAsmEscapedChar(char C) const
Replace some escaped characters with another string based on target-specific rules.
Definition: TargetInfo.h:1241
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
const Expr * getExprStmt() const
Definition: Stmt.cpp:402
Represents a variable declaration or definition.
Definition: Decl.h:882
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2246
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2621
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
Definition: Stmt.h:2713
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:1159
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable of this while statement.
Definition: Stmt.cpp:1166
bool hasVarStorage() const
True if this WhileStmt has storage for a condition variable.
Definition: Stmt.h:2671
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition: Stmt.cpp:1141
static WhileStmt * CreateEmpty(const ASTContext &Ctx, bool HasVar)
Create an empty while statement optionally with storage for a condition variable.
Definition: Stmt.cpp:1152
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
The JSON file list parser is used to communicate input to InstallAPI.
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition: Specifiers.h:39
@ NumConstraints
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:16
@ CR_Default
Definition: CapturedStmt.h:17
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
Definition: CharInfo.h:132
@ 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].
Definition: CharInfo.h:114
const FunctionProtoType * T
const char * Name
Definition: Stmt.cpp:51
unsigned Size
Definition: Stmt.cpp:53
unsigned Counter
Definition: Stmt.cpp:52
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition: Stmt.h:1330