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