clang  14.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"
14 #include "clang/AST/ASTContext.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"
21 #include "clang/AST/ExprConcepts.h"
22 #include "clang/AST/ExprObjC.h"
23 #include "clang/AST/ExprOpenMP.h"
24 #include "clang/AST/StmtCXX.h"
25 #include "clang/AST/StmtObjC.h"
26 #include "clang/AST/StmtOpenMP.h"
27 #include "clang/AST/Type.h"
28 #include "clang/Basic/CharInfo.h"
29 #include "clang/Basic/LLVM.h"
31 #include "clang/Basic/TargetInfo.h"
32 #include "clang/Lex/Token.h"
33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/ADT/StringExtras.h"
35 #include "llvm/ADT/StringRef.h"
36 #include "llvm/Support/Casting.h"
37 #include "llvm/Support/Compiler.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/MathExtras.h"
40 #include "llvm/Support/raw_ostream.h"
41 #include <algorithm>
42 #include <cassert>
43 #include <cstring>
44 #include <string>
45 #include <type_traits>
46 #include <utility>
47 
48 using namespace clang;
49 
50 static 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 
72 void *Stmt::operator new(size_t bytes, const ASTContext& C,
73  unsigned alignment) {
74  return ::operator new(bytes, C, alignment);
75 }
76 
77 const 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 
128 bool Stmt::StatisticsEnabled = false;
130  StatisticsEnabled = true;
131 }
132 
133 static 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 
146 static 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 
165 Stmt::Likelihood Stmt::getLikelihood(const Stmt *Then, const Stmt *Else) {
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 
182 std::tuple<bool, const Attr *, const Attr *>
183 Stmt::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.
195 Stmt *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 
231 namespace {
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.
275 LLVM_ATTRIBUTE_UNUSED
276 static 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().
301 namespace {
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 
360 int64_t Stmt::getID(const ASTContext &Context) const {
361  return Context.getAllocator().identifyKnownAlignedObject<Stmt>(this);
362 }
363 
364 CompoundStmt::CompoundStmt(ArrayRef<Stmt *> Stmts, SourceLocation LB,
365  SourceLocation RB)
366  : Stmt(CompoundStmtClass), RBraceLoc(RB) {
367  CompoundStmtBits.NumStmts = Stmts.size();
368  setStmts(Stmts);
369  CompoundStmtBits.LBraceLoc = LB;
370 }
371 
372 void CompoundStmt::setStmts(ArrayRef<Stmt *> Stmts) {
373  assert(CompoundStmtBits.NumStmts == Stmts.size() &&
374  "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
375 
376  std::copy(Stmts.begin(), Stmts.end(), body_begin());
377 }
378 
381  void *Mem =
382  C.Allocate(totalSizeToAlloc<Stmt *>(Stmts.size()), alignof(CompoundStmt));
383  return new (Mem) CompoundStmt(Stmts, LB, RB);
384 }
385 
387  unsigned NumStmts) {
388  void *Mem =
389  C.Allocate(totalSizeToAlloc<Stmt *>(NumStmts), alignof(CompoundStmt));
390  CompoundStmt *New = new (Mem) CompoundStmt(EmptyShell());
391  New->CompoundStmtBits.NumStmts = NumStmts;
392  return New;
393 }
394 
395 const Expr *ValueStmt::getExprStmt() const {
396  const Stmt *S = this;
397  do {
398  if (const auto *E = dyn_cast<Expr>(S))
399  return E;
400 
401  if (const auto *LS = dyn_cast<LabelStmt>(S))
402  S = LS->getSubStmt();
403  else if (const auto *AS = dyn_cast<AttributedStmt>(S))
404  S = AS->getSubStmt();
405  else
406  llvm_unreachable("unknown kind of ValueStmt");
407  } while (isa<ValueStmt>(S));
408 
409  return nullptr;
410 }
411 
412 const char *LabelStmt::getName() const {
413  return getDecl()->getIdentifier()->getNameStart();
414 }
415 
417  ArrayRef<const Attr*> Attrs,
418  Stmt *SubStmt) {
419  assert(!Attrs.empty() && "Attrs should not be empty");
420  void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(Attrs.size()),
421  alignof(AttributedStmt));
422  return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
423 }
424 
426  unsigned NumAttrs) {
427  assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
428  void *Mem = C.Allocate(totalSizeToAlloc<const Attr *>(NumAttrs),
429  alignof(AttributedStmt));
430  return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
431 }
432 
434  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
435  return gccAsmStmt->generateAsmString(C);
436  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
437  return msAsmStmt->generateAsmString(C);
438  llvm_unreachable("unknown asm statement kind!");
439 }
440 
441 StringRef AsmStmt::getOutputConstraint(unsigned i) const {
442  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
443  return gccAsmStmt->getOutputConstraint(i);
444  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
445  return msAsmStmt->getOutputConstraint(i);
446  llvm_unreachable("unknown asm statement kind!");
447 }
448 
449 const Expr *AsmStmt::getOutputExpr(unsigned i) const {
450  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
451  return gccAsmStmt->getOutputExpr(i);
452  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
453  return msAsmStmt->getOutputExpr(i);
454  llvm_unreachable("unknown asm statement kind!");
455 }
456 
457 StringRef AsmStmt::getInputConstraint(unsigned i) const {
458  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
459  return gccAsmStmt->getInputConstraint(i);
460  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
461  return msAsmStmt->getInputConstraint(i);
462  llvm_unreachable("unknown asm statement kind!");
463 }
464 
465 const Expr *AsmStmt::getInputExpr(unsigned i) const {
466  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
467  return gccAsmStmt->getInputExpr(i);
468  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
469  return msAsmStmt->getInputExpr(i);
470  llvm_unreachable("unknown asm statement kind!");
471 }
472 
473 StringRef AsmStmt::getClobber(unsigned i) const {
474  if (const auto *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
475  return gccAsmStmt->getClobber(i);
476  if (const auto *msAsmStmt = dyn_cast<MSAsmStmt>(this))
477  return msAsmStmt->getClobber(i);
478  llvm_unreachable("unknown asm statement kind!");
479 }
480 
481 /// getNumPlusOperands - Return the number of output operands that have a "+"
482 /// constraint.
483 unsigned AsmStmt::getNumPlusOperands() const {
484  unsigned Res = 0;
485  for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
486  if (isOutputPlusConstraint(i))
487  ++Res;
488  return Res;
489 }
490 
492  assert(isOperand() && "Only Operands can have modifiers.");
493  return isLetter(Str[0]) ? Str[0] : '\0';
494 }
495 
496 StringRef GCCAsmStmt::getClobber(unsigned i) const {
497  return getClobberStringLiteral(i)->getString();
498 }
499 
501  return cast<Expr>(Exprs[i]);
502 }
503 
504 /// getOutputConstraint - Return the constraint string for the specified
505 /// output operand. All output constraints are known to be non-empty (either
506 /// '=' or '+').
507 StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
509 }
510 
512  return cast<Expr>(Exprs[i + NumOutputs]);
513 }
514 
515 void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
516  Exprs[i + NumOutputs] = E;
517 }
518 
520  return cast<AddrLabelExpr>(Exprs[i + NumOutputs + NumInputs]);
521 }
522 
523 StringRef GCCAsmStmt::getLabelName(unsigned i) const {
524  return getLabelExpr(i)->getLabel()->getName();
525 }
526 
527 /// getInputConstraint - Return the specified input constraint. Unlike output
528 /// constraints, these can be empty.
529 StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
531 }
532 
533 void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
534  IdentifierInfo **Names,
535  StringLiteral **Constraints,
536  Stmt **Exprs,
537  unsigned NumOutputs,
538  unsigned NumInputs,
539  unsigned NumLabels,
540  StringLiteral **Clobbers,
541  unsigned NumClobbers) {
542  this->NumOutputs = NumOutputs;
543  this->NumInputs = NumInputs;
544  this->NumClobbers = NumClobbers;
545  this->NumLabels = NumLabels;
546 
547  unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
548 
549  C.Deallocate(this->Names);
550  this->Names = new (C) IdentifierInfo*[NumExprs];
551  std::copy(Names, Names + NumExprs, this->Names);
552 
553  C.Deallocate(this->Exprs);
554  this->Exprs = new (C) Stmt*[NumExprs];
555  std::copy(Exprs, Exprs + NumExprs, this->Exprs);
556 
557  unsigned NumConstraints = NumOutputs + NumInputs;
558  C.Deallocate(this->Constraints);
559  this->Constraints = new (C) StringLiteral*[NumConstraints];
560  std::copy(Constraints, Constraints + NumConstraints, this->Constraints);
561 
562  C.Deallocate(this->Clobbers);
563  this->Clobbers = new (C) StringLiteral*[NumClobbers];
564  std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
565 }
566 
567 /// getNamedOperand - Given a symbolic operand reference like %[foo],
568 /// translate this into a numeric value needed to reference the same operand.
569 /// This returns -1 if the operand name is invalid.
570 int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
571  unsigned NumPlusOperands = 0;
572 
573  // Check if this is an output operand.
574  for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
575  if (getOutputName(i) == SymbolicName)
576  return i;
577  }
578 
579  for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
580  if (getInputName(i) == SymbolicName)
581  return getNumOutputs() + NumPlusOperands + i;
582 
583  for (unsigned i = 0, e = getNumLabels(); i != e; ++i)
584  if (getLabelName(i) == SymbolicName)
585  return i + getNumOutputs() + getNumInputs();
586 
587  // Not found.
588  return -1;
589 }
590 
591 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
592 /// it into pieces. If the asm string is erroneous, emit errors and return
593 /// true, otherwise return false.
595  const ASTContext &C, unsigned &DiagOffs) const {
596  StringRef Str = getAsmString()->getString();
597  const char *StrStart = Str.begin();
598  const char *StrEnd = Str.end();
599  const char *CurPtr = StrStart;
600 
601  // "Simple" inline asms have no constraints or operands, just convert the asm
602  // string to escape $'s.
603  if (isSimple()) {
604  std::string Result;
605  for (; CurPtr != StrEnd; ++CurPtr) {
606  switch (*CurPtr) {
607  case '$':
608  Result += "$$";
609  break;
610  default:
611  Result += *CurPtr;
612  break;
613  }
614  }
615  Pieces.push_back(AsmStringPiece(Result));
616  return 0;
617  }
618 
619  // CurStringPiece - The current string that we are building up as we scan the
620  // asm string.
621  std::string CurStringPiece;
622 
623  bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
624 
625  unsigned LastAsmStringToken = 0;
626  unsigned LastAsmStringOffset = 0;
627 
628  while (true) {
629  // Done with the string?
630  if (CurPtr == StrEnd) {
631  if (!CurStringPiece.empty())
632  Pieces.push_back(AsmStringPiece(CurStringPiece));
633  return 0;
634  }
635 
636  char CurChar = *CurPtr++;
637  switch (CurChar) {
638  case '$': CurStringPiece += "$$"; continue;
639  case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
640  case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
641  case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
642  case '%':
643  break;
644  default:
645  CurStringPiece += CurChar;
646  continue;
647  }
648 
649  const TargetInfo &TI = C.getTargetInfo();
650 
651  // Escaped "%" character in asm string.
652  if (CurPtr == StrEnd) {
653  // % at end of string is invalid (no escape).
654  DiagOffs = CurPtr-StrStart-1;
655  return diag::err_asm_invalid_escape;
656  }
657  // Handle escaped char and continue looping over the asm string.
658  char EscapedChar = *CurPtr++;
659  switch (EscapedChar) {
660  default:
661  // Handle target-specific escaped characters.
662  if (auto MaybeReplaceStr = TI.handleAsmEscapedChar(EscapedChar)) {
663  CurStringPiece += *MaybeReplaceStr;
664  continue;
665  }
666  break;
667  case '%': // %% -> %
668  case '{': // %{ -> {
669  case '}': // %} -> }
670  CurStringPiece += EscapedChar;
671  continue;
672  case '=': // %= -> Generate a unique ID.
673  CurStringPiece += "${:uid}";
674  continue;
675  }
676 
677  // Otherwise, we have an operand. If we have accumulated a string so far,
678  // add it to the Pieces list.
679  if (!CurStringPiece.empty()) {
680  Pieces.push_back(AsmStringPiece(CurStringPiece));
681  CurStringPiece.clear();
682  }
683 
684  // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
685  // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
686 
687  const char *Begin = CurPtr - 1; // Points to the character following '%'.
688  const char *Percent = Begin - 1; // Points to '%'.
689 
690  if (isLetter(EscapedChar)) {
691  if (CurPtr == StrEnd) { // Premature end.
692  DiagOffs = CurPtr-StrStart-1;
693  return diag::err_asm_invalid_escape;
694  }
695  EscapedChar = *CurPtr++;
696  }
697 
698  const SourceManager &SM = C.getSourceManager();
699  const LangOptions &LO = C.getLangOpts();
700 
701  // Handle operands that don't have asmSymbolicName (e.g., %x4).
702  if (isDigit(EscapedChar)) {
703  // %n - Assembler operand n
704  unsigned N = 0;
705 
706  --CurPtr;
707  while (CurPtr != StrEnd && isDigit(*CurPtr))
708  N = N*10 + ((*CurPtr++)-'0');
709 
710  unsigned NumOperands = getNumOutputs() + getNumPlusOperands() +
712  if (N >= NumOperands) {
713  DiagOffs = CurPtr-StrStart-1;
714  return diag::err_asm_invalid_operand_number;
715  }
716 
717  // Str contains "x4" (Operand without the leading %).
718  std::string Str(Begin, CurPtr - Begin);
719 
720  // (BeginLoc, EndLoc) represents the range of the operand we are currently
721  // processing. Unlike Str, the range includes the leading '%'.
723  Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
724  &LastAsmStringOffset);
726  CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken,
727  &LastAsmStringOffset);
728 
729  Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
730  continue;
731  }
732 
733  // Handle operands that have asmSymbolicName (e.g., %x[foo]).
734  if (EscapedChar == '[') {
735  DiagOffs = CurPtr-StrStart-1;
736 
737  // Find the ']'.
738  const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
739  if (NameEnd == nullptr)
740  return diag::err_asm_unterminated_symbolic_operand_name;
741  if (NameEnd == CurPtr)
742  return diag::err_asm_empty_symbolic_operand_name;
743 
744  StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
745 
746  int N = getNamedOperand(SymbolicName);
747  if (N == -1) {
748  // Verify that an operand with that name exists.
749  DiagOffs = CurPtr-StrStart;
750  return diag::err_asm_unknown_symbolic_operand_name;
751  }
752 
753  // Str contains "x[foo]" (Operand without the leading %).
754  std::string Str(Begin, NameEnd + 1 - Begin);
755 
756  // (BeginLoc, EndLoc) represents the range of the operand we are currently
757  // processing. Unlike Str, the range includes the leading '%'.
759  Percent - StrStart, SM, LO, TI, &LastAsmStringToken,
760  &LastAsmStringOffset);
762  NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken,
763  &LastAsmStringOffset);
764 
765  Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
766 
767  CurPtr = NameEnd+1;
768  continue;
769  }
770 
771  DiagOffs = CurPtr-StrStart-1;
772  return diag::err_asm_invalid_escape;
773  }
774 }
775 
776 /// Assemble final IR asm string (GCC-style).
778  // Analyze the asm string to decompose it into its pieces. We know that Sema
779  // has already done this, so it is guaranteed to be successful.
781  unsigned DiagOffs;
782  AnalyzeAsmString(Pieces, C, DiagOffs);
783 
784  std::string AsmString;
785  for (const auto &Piece : Pieces) {
786  if (Piece.isString())
787  AsmString += Piece.getString();
788  else if (Piece.getModifier() == '\0')
789  AsmString += '$' + llvm::utostr(Piece.getOperandNo());
790  else
791  AsmString += "${" + llvm::utostr(Piece.getOperandNo()) + ':' +
792  Piece.getModifier() + '}';
793  }
794  return AsmString;
795 }
796 
797 /// Assemble final IR asm string (MS-style).
799  // FIXME: This needs to be translated into the IR string representation.
801  AsmStr.split(Pieces, "\n\t");
802  std::string MSAsmString;
803  for (size_t I = 0, E = Pieces.size(); I < E; ++I) {
804  StringRef Instruction = Pieces[I];
805  // For vex/vex2/vex3/evex masm style prefix, convert it to att style
806  // since we don't support masm style prefix in backend.
807  if (Instruction.startswith("vex "))
808  MSAsmString += '{' + Instruction.substr(0, 3).str() + '}' +
809  Instruction.substr(3).str();
810  else if (Instruction.startswith("vex2 ") ||
811  Instruction.startswith("vex3 ") || Instruction.startswith("evex "))
812  MSAsmString += '{' + Instruction.substr(0, 4).str() + '}' +
813  Instruction.substr(4).str();
814  else
815  MSAsmString += Instruction.str();
816  // If this is not the last instruction, adding back the '\n\t'.
817  if (I < E - 1)
818  MSAsmString += "\n\t";
819  }
820  return MSAsmString;
821 }
822 
824  return cast<Expr>(Exprs[i]);
825 }
826 
828  return cast<Expr>(Exprs[i + NumOutputs]);
829 }
830 
831 void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
832  Exprs[i + NumOutputs] = E;
833 }
834 
835 //===----------------------------------------------------------------------===//
836 // Constructors
837 //===----------------------------------------------------------------------===//
838 
840  bool issimple, bool isvolatile, unsigned numoutputs,
841  unsigned numinputs, IdentifierInfo **names,
842  StringLiteral **constraints, Expr **exprs,
843  StringLiteral *asmstr, unsigned numclobbers,
844  StringLiteral **clobbers, unsigned numlabels,
845  SourceLocation rparenloc)
846  : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
847  numinputs, numclobbers),
848  RParenLoc(rparenloc), AsmStr(asmstr), NumLabels(numlabels) {
849  unsigned NumExprs = NumOutputs + NumInputs + NumLabels;
850 
851  Names = new (C) IdentifierInfo*[NumExprs];
852  std::copy(names, names + NumExprs, Names);
853 
854  Exprs = new (C) Stmt*[NumExprs];
855  std::copy(exprs, exprs + NumExprs, Exprs);
856 
857  unsigned NumConstraints = NumOutputs + NumInputs;
858  Constraints = new (C) StringLiteral*[NumConstraints];
859  std::copy(constraints, constraints + NumConstraints, Constraints);
860 
861  Clobbers = new (C) StringLiteral*[NumClobbers];
862  std::copy(clobbers, clobbers + NumClobbers, Clobbers);
863 }
864 
866  SourceLocation lbraceloc, bool issimple, bool isvolatile,
867  ArrayRef<Token> asmtoks, unsigned numoutputs,
868  unsigned numinputs,
869  ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
870  StringRef asmstr, ArrayRef<StringRef> clobbers,
871  SourceLocation endloc)
872  : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
873  numinputs, clobbers.size()), LBraceLoc(lbraceloc),
874  EndLoc(endloc), NumAsmToks(asmtoks.size()) {
875  initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
876 }
877 
878 static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
879  return str.copy(C);
880 }
881 
882 void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
883  ArrayRef<Token> asmtoks,
884  ArrayRef<StringRef> constraints,
885  ArrayRef<Expr*> exprs,
886  ArrayRef<StringRef> clobbers) {
887  assert(NumAsmToks == asmtoks.size());
888  assert(NumClobbers == clobbers.size());
889 
890  assert(exprs.size() == NumOutputs + NumInputs);
891  assert(exprs.size() == constraints.size());
892 
893  AsmStr = copyIntoContext(C, asmstr);
894 
895  Exprs = new (C) Stmt*[exprs.size()];
896  std::copy(exprs.begin(), exprs.end(), Exprs);
897 
898  AsmToks = new (C) Token[asmtoks.size()];
899  std::copy(asmtoks.begin(), asmtoks.end(), AsmToks);
900 
901  Constraints = new (C) StringRef[exprs.size()];
902  std::transform(constraints.begin(), constraints.end(), Constraints,
903  [&](StringRef Constraint) {
904  return copyIntoContext(C, Constraint);
905  });
906 
907  Clobbers = new (C) StringRef[NumClobbers];
908  // FIXME: Avoid the allocation/copy if at all possible.
909  std::transform(clobbers.begin(), clobbers.end(), Clobbers,
910  [&](StringRef Clobber) {
911  return copyIntoContext(C, Clobber);
912  });
913 }
914 
915 IfStmt::IfStmt(const ASTContext &Ctx, SourceLocation IL, bool IsConstexpr,
916  Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL,
917  SourceLocation RPL, Stmt *Then, SourceLocation EL, Stmt *Else)
918  : Stmt(IfStmtClass), LParenLoc(LPL), RParenLoc(RPL) {
919  bool HasElse = Else != nullptr;
920  bool HasVar = Var != nullptr;
921  bool HasInit = Init != nullptr;
922  IfStmtBits.HasElse = HasElse;
923  IfStmtBits.HasVar = HasVar;
924  IfStmtBits.HasInit = HasInit;
925 
926  setConstexpr(IsConstexpr);
927 
928  setCond(Cond);
929  setThen(Then);
930  if (HasElse)
931  setElse(Else);
932  if (HasVar)
933  setConditionVariable(Ctx, Var);
934  if (HasInit)
935  setInit(Init);
936 
937  setIfLoc(IL);
938  if (HasElse)
939  setElseLoc(EL);
940 }
941 
942 IfStmt::IfStmt(EmptyShell Empty, bool HasElse, bool HasVar, bool HasInit)
943  : Stmt(IfStmtClass, Empty) {
944  IfStmtBits.HasElse = HasElse;
945  IfStmtBits.HasVar = HasVar;
946  IfStmtBits.HasInit = HasInit;
947 }
948 
949 IfStmt *IfStmt::Create(const ASTContext &Ctx, SourceLocation IL,
950  bool IsConstexpr, Stmt *Init, VarDecl *Var, Expr *Cond,
951  SourceLocation LPL, SourceLocation RPL, Stmt *Then,
952  SourceLocation EL, Stmt *Else) {
953  bool HasElse = Else != nullptr;
954  bool HasVar = Var != nullptr;
955  bool HasInit = Init != nullptr;
956  void *Mem = Ctx.Allocate(
957  totalSizeToAlloc<Stmt *, SourceLocation>(
958  NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
959  alignof(IfStmt));
960  return new (Mem)
961  IfStmt(Ctx, IL, IsConstexpr, Init, Var, Cond, LPL, RPL, Then, EL, Else);
962 }
963 
964 IfStmt *IfStmt::CreateEmpty(const ASTContext &Ctx, bool HasElse, bool HasVar,
965  bool HasInit) {
966  void *Mem = Ctx.Allocate(
967  totalSizeToAlloc<Stmt *, SourceLocation>(
968  NumMandatoryStmtPtr + HasElse + HasVar + HasInit, HasElse),
969  alignof(IfStmt));
970  return new (Mem) IfStmt(EmptyShell(), HasElse, HasVar, HasInit);
971 }
972 
974  auto *DS = getConditionVariableDeclStmt();
975  if (!DS)
976  return nullptr;
977  return cast<VarDecl>(DS->getSingleDecl());
978 }
979 
981  assert(hasVarStorage() &&
982  "This if statement has no storage for a condition variable!");
983 
984  if (!V) {
985  getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
986  return;
987  }
988 
989  SourceRange VarRange = V->getSourceRange();
990  getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
991  DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
992 }
993 
995  return isa<ObjCAvailabilityCheckExpr>(getCond());
996 }
997 
999  if (!isConstexpr() || getCond()->isValueDependent())
1000  return None;
1001  return !getCond()->EvaluateKnownConstInt(Ctx) ? getElse() : getThen();
1002 }
1003 
1006  if (Optional<Stmt *> Result =
1007  const_cast<IfStmt *>(this)->getNondiscardedCase(Ctx))
1008  return *Result;
1009  return None;
1010 }
1011 
1012 ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1013  Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1014  SourceLocation RP)
1015  : Stmt(ForStmtClass), LParenLoc(LP), RParenLoc(RP)
1016 {
1017  SubExprs[INIT] = Init;
1018  setConditionVariable(C, condVar);
1019  SubExprs[COND] = Cond;
1020  SubExprs[INC] = Inc;
1021  SubExprs[BODY] = Body;
1022  ForStmtBits.ForLoc = FL;
1023 }
1024 
1026  if (!SubExprs[CONDVAR])
1027  return nullptr;
1028 
1029  auto *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
1030  return cast<VarDecl>(DS->getSingleDecl());
1031 }
1032 
1034  if (!V) {
1035  SubExprs[CONDVAR] = nullptr;
1036  return;
1037  }
1038 
1039  SourceRange VarRange = V->getSourceRange();
1040  SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
1041  VarRange.getEnd());
1042 }
1043 
1044 SwitchStmt::SwitchStmt(const ASTContext &Ctx, Stmt *Init, VarDecl *Var,
1045  Expr *Cond, SourceLocation LParenLoc,
1046  SourceLocation RParenLoc)
1047  : Stmt(SwitchStmtClass), FirstCase(nullptr), LParenLoc(LParenLoc),
1048  RParenLoc(RParenLoc) {
1049  bool HasInit = Init != nullptr;
1050  bool HasVar = Var != nullptr;
1051  SwitchStmtBits.HasInit = HasInit;
1052  SwitchStmtBits.HasVar = HasVar;
1053  SwitchStmtBits.AllEnumCasesCovered = false;
1054 
1055  setCond(Cond);
1056  setBody(nullptr);
1057  if (HasInit)
1058  setInit(Init);
1059  if (HasVar)
1060  setConditionVariable(Ctx, Var);
1061 
1062  setSwitchLoc(SourceLocation{});
1063 }
1064 
1065 SwitchStmt::SwitchStmt(EmptyShell Empty, bool HasInit, bool HasVar)
1066  : Stmt(SwitchStmtClass, Empty) {
1067  SwitchStmtBits.HasInit = HasInit;
1068  SwitchStmtBits.HasVar = HasVar;
1069  SwitchStmtBits.AllEnumCasesCovered = false;
1070 }
1071 
1073  Expr *Cond, SourceLocation LParenLoc,
1074  SourceLocation RParenLoc) {
1075  bool HasInit = Init != nullptr;
1076  bool HasVar = Var != nullptr;
1077  void *Mem = Ctx.Allocate(
1078  totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1079  alignof(SwitchStmt));
1080  return new (Mem) SwitchStmt(Ctx, Init, Var, Cond, LParenLoc, RParenLoc);
1081 }
1082 
1084  bool HasVar) {
1085  void *Mem = Ctx.Allocate(
1086  totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasInit + HasVar),
1087  alignof(SwitchStmt));
1088  return new (Mem) SwitchStmt(EmptyShell(), HasInit, HasVar);
1089 }
1090 
1092  auto *DS = getConditionVariableDeclStmt();
1093  if (!DS)
1094  return nullptr;
1095  return cast<VarDecl>(DS->getSingleDecl());
1096 }
1097 
1099  assert(hasVarStorage() &&
1100  "This switch statement has no storage for a condition variable!");
1101 
1102  if (!V) {
1103  getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1104  return;
1105  }
1106 
1107  SourceRange VarRange = V->getSourceRange();
1108  getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1109  DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
1110 }
1111 
1112 WhileStmt::WhileStmt(const ASTContext &Ctx, VarDecl *Var, Expr *Cond,
1113  Stmt *Body, SourceLocation WL, SourceLocation LParenLoc,
1114  SourceLocation RParenLoc)
1115  : Stmt(WhileStmtClass) {
1116  bool HasVar = Var != nullptr;
1117  WhileStmtBits.HasVar = HasVar;
1118 
1119  setCond(Cond);
1120  setBody(Body);
1121  if (HasVar)
1122  setConditionVariable(Ctx, Var);
1123 
1124  setWhileLoc(WL);
1125  setLParenLoc(LParenLoc);
1126  setRParenLoc(RParenLoc);
1127 }
1128 
1129 WhileStmt::WhileStmt(EmptyShell Empty, bool HasVar)
1130  : Stmt(WhileStmtClass, Empty) {
1131  WhileStmtBits.HasVar = HasVar;
1132 }
1133 
1135  Stmt *Body, SourceLocation WL,
1136  SourceLocation LParenLoc,
1137  SourceLocation RParenLoc) {
1138  bool HasVar = Var != nullptr;
1139  void *Mem =
1140  Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1141  alignof(WhileStmt));
1142  return new (Mem) WhileStmt(Ctx, Var, Cond, Body, WL, LParenLoc, RParenLoc);
1143 }
1144 
1145 WhileStmt *WhileStmt::CreateEmpty(const ASTContext &Ctx, bool HasVar) {
1146  void *Mem =
1147  Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumMandatoryStmtPtr + HasVar),
1148  alignof(WhileStmt));
1149  return new (Mem) WhileStmt(EmptyShell(), HasVar);
1150 }
1151 
1153  auto *DS = getConditionVariableDeclStmt();
1154  if (!DS)
1155  return nullptr;
1156  return cast<VarDecl>(DS->getSingleDecl());
1157 }
1158 
1160  assert(hasVarStorage() &&
1161  "This while statement has no storage for a condition variable!");
1162 
1163  if (!V) {
1164  getTrailingObjects<Stmt *>()[varOffset()] = nullptr;
1165  return;
1166  }
1167 
1168  SourceRange VarRange = V->getSourceRange();
1169  getTrailingObjects<Stmt *>()[varOffset()] = new (Ctx)
1170  DeclStmt(DeclGroupRef(V), VarRange.getBegin(), VarRange.getEnd());
1171 }
1172 
1173 // IndirectGotoStmt
1175  if (auto *E = dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1176  return E->getLabel();
1177  return nullptr;
1178 }
1179 
1180 // ReturnStmt
1181 ReturnStmt::ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1182  : Stmt(ReturnStmtClass), RetExpr(E) {
1183  bool HasNRVOCandidate = NRVOCandidate != nullptr;
1184  ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate;
1185  if (HasNRVOCandidate)
1186  setNRVOCandidate(NRVOCandidate);
1187  setReturnLoc(RL);
1188 }
1189 
1190 ReturnStmt::ReturnStmt(EmptyShell Empty, bool HasNRVOCandidate)
1191  : Stmt(ReturnStmtClass, Empty) {
1192  ReturnStmtBits.HasNRVOCandidate = HasNRVOCandidate;
1193 }
1194 
1196  Expr *E, const VarDecl *NRVOCandidate) {
1197  bool HasNRVOCandidate = NRVOCandidate != nullptr;
1198  void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1199  alignof(ReturnStmt));
1200  return new (Mem) ReturnStmt(RL, E, NRVOCandidate);
1201 }
1202 
1204  bool HasNRVOCandidate) {
1205  void *Mem = Ctx.Allocate(totalSizeToAlloc<const VarDecl *>(HasNRVOCandidate),
1206  alignof(ReturnStmt));
1207  return new (Mem) ReturnStmt(EmptyShell(), HasNRVOCandidate);
1208 }
1209 
1210 // CaseStmt
1212  SourceLocation caseLoc, SourceLocation ellipsisLoc,
1213  SourceLocation colonLoc) {
1214  bool CaseStmtIsGNURange = rhs != nullptr;
1215  void *Mem = Ctx.Allocate(
1216  totalSizeToAlloc<Stmt *, SourceLocation>(
1217  NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1218  alignof(CaseStmt));
1219  return new (Mem) CaseStmt(lhs, rhs, caseLoc, ellipsisLoc, colonLoc);
1220 }
1221 
1223  bool CaseStmtIsGNURange) {
1224  void *Mem = Ctx.Allocate(
1225  totalSizeToAlloc<Stmt *, SourceLocation>(
1226  NumMandatoryStmtPtr + CaseStmtIsGNURange, CaseStmtIsGNURange),
1227  alignof(CaseStmt));
1228  return new (Mem) CaseStmt(EmptyShell(), CaseStmtIsGNURange);
1229 }
1230 
1231 SEHTryStmt::SEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock,
1232  Stmt *Handler)
1233  : Stmt(SEHTryStmtClass), IsCXXTry(IsCXXTry), TryLoc(TryLoc) {
1234  Children[TRY] = TryBlock;
1235  Children[HANDLER] = Handler;
1236 }
1237 
1238 SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
1239  SourceLocation TryLoc, Stmt *TryBlock,
1240  Stmt *Handler) {
1241  return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
1242 }
1243 
1245  return dyn_cast<SEHExceptStmt>(getHandler());
1246 }
1247 
1249  return dyn_cast<SEHFinallyStmt>(getHandler());
1250 }
1251 
1252 SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
1253  : Stmt(SEHExceptStmtClass), Loc(Loc) {
1254  Children[FILTER_EXPR] = FilterExpr;
1255  Children[BLOCK] = Block;
1256 }
1257 
1259  Expr *FilterExpr, Stmt *Block) {
1260  return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
1261 }
1262 
1263 SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, Stmt *Block)
1264  : Stmt(SEHFinallyStmtClass), Loc(Loc), Block(Block) {}
1265 
1267  Stmt *Block) {
1268  return new(C)SEHFinallyStmt(Loc,Block);
1269 }
1270 
1272  VarDecl *Var)
1273  : VarAndKind(Var, Kind), Loc(Loc) {
1274  switch (Kind) {
1275  case VCK_This:
1276  assert(!Var && "'this' capture cannot have a variable!");
1277  break;
1278  case VCK_ByRef:
1279  assert(Var && "capturing by reference must have a variable!");
1280  break;
1281  case VCK_ByCopy:
1282  assert(Var && "capturing by copy must have a variable!");
1283  break;
1284  case VCK_VLAType:
1285  assert(!Var &&
1286  "Variable-length array type capture cannot have a variable!");
1287  break;
1288  }
1289 }
1290 
1293  return VarAndKind.getInt();
1294 }
1295 
1297  assert((capturesVariable() || capturesVariableByCopy()) &&
1298  "No variable available for 'this' or VAT capture");
1299  return VarAndKind.getPointer();
1300 }
1301 
1302 CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
1303  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1304 
1305  // Offset of the first Capture object.
1306  unsigned FirstCaptureOffset = llvm::alignTo(Size, alignof(Capture));
1307 
1308  return reinterpret_cast<Capture *>(
1309  reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1310  + FirstCaptureOffset);
1311 }
1312 
1313 CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1314  ArrayRef<Capture> Captures,
1315  ArrayRef<Expr *> CaptureInits,
1316  CapturedDecl *CD,
1317  RecordDecl *RD)
1318  : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
1319  CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
1320  assert( S && "null captured statement");
1321  assert(CD && "null captured declaration for captured statement");
1322  assert(RD && "null record declaration for captured statement");
1323 
1324  // Copy initialization expressions.
1325  Stmt **Stored = getStoredStmts();
1326  for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1327  *Stored++ = CaptureInits[I];
1328 
1329  // Copy the statement being captured.
1330  *Stored = S;
1331 
1332  // Copy all Capture objects.
1333  Capture *Buffer = getStoredCaptures();
1334  std::copy(Captures.begin(), Captures.end(), Buffer);
1335 }
1336 
1337 CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1338  : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
1339  CapDeclAndKind(nullptr, CR_Default) {
1340  getStoredStmts()[NumCaptures] = nullptr;
1341 }
1342 
1345  ArrayRef<Capture> Captures,
1346  ArrayRef<Expr *> CaptureInits,
1347  CapturedDecl *CD,
1348  RecordDecl *RD) {
1349  // The layout is
1350  //
1351  // -----------------------------------------------------------
1352  // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1353  // ----------------^-------------------^----------------------
1354  // getStoredStmts() getStoredCaptures()
1355  //
1356  // where S is the statement being captured.
1357  //
1358  assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1359 
1360  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1361  if (!Captures.empty()) {
1362  // Realign for the following Capture array.
1363  Size = llvm::alignTo(Size, alignof(Capture));
1364  Size += sizeof(Capture) * Captures.size();
1365  }
1366 
1367  void *Mem = Context.Allocate(Size);
1368  return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
1369 }
1370 
1372  unsigned NumCaptures) {
1373  unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1374  if (NumCaptures > 0) {
1375  // Realign for the following Capture array.
1376  Size = llvm::alignTo(Size, alignof(Capture));
1377  Size += sizeof(Capture) * NumCaptures;
1378  }
1379 
1380  void *Mem = Context.Allocate(Size);
1381  return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1382 }
1383 
1385  // Children are captured field initializers.
1386  return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1387 }
1388 
1390  return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
1391 }
1392 
1394  return CapDeclAndKind.getPointer();
1395 }
1396 
1398  return CapDeclAndKind.getPointer();
1399 }
1400 
1401 /// Set the outlined function declaration.
1403  assert(D && "null CapturedDecl");
1404  CapDeclAndKind.setPointer(D);
1405 }
1406 
1407 /// Retrieve the captured region kind.
1409  return CapDeclAndKind.getInt();
1410 }
1411 
1412 /// Set the captured region kind.
1414  CapDeclAndKind.setInt(Kind);
1415 }
1416 
1417 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
1418  for (const auto &I : captures()) {
1419  if (!I.capturesVariable() && !I.capturesVariableByCopy())
1420  continue;
1421  if (I.getCapturedVar()->getCanonicalDecl() == Var->getCanonicalDecl())
1422  return true;
1423  }
1424 
1425  return false;
1426 }
clang::CapturedStmt::VCK_VLAType
@ VCK_VLAType
Definition: Stmt.h:3479
StmtClassNameTable
Definition: Stmt.cpp:50
clang::CapturedStmt::VCK_ByCopy
@ VCK_ByCopy
Definition: Stmt.h:3478
clang::SwitchStmt::hasVarStorage
bool hasVarStorage() const
True if this SwitchStmt has storage for a condition variable.
Definition: Stmt.h:2183
clang::GCCAsmStmt::getNamedOperand
int getNamedOperand(StringRef SymbolicName) const
getNamedOperand - Given a symbolic operand reference like %[foo], translate this into a numeric value...
Definition: Stmt.cpp:570
clang::ForStmt::getConditionVariable
VarDecl * getConditionVariable() const
Retrieve the variable declared in this "for" statement, if any.
Definition: Stmt.cpp:1025
clang::CaseStmt
CaseStmt - Represent a case statement.
Definition: Stmt.h:1566
clang::AsmStmt::getInputConstraint
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:457
clang::CaseStmt::CreateEmpty
static CaseStmt * CreateEmpty(const ASTContext &Ctx, bool CaseStmtIsGNURange)
Build an empty case statement.
Definition: Stmt.cpp:1222
clang::ForStmt::setBody
void setBody(Stmt *S)
Definition: Stmt.h:2549
clang::SEHTryStmt::getFinallyHandler
SEHFinallyStmt * getFinallyHandler() const
Definition: Stmt.cpp:1248
clang::GCCAsmStmt::getLabelExpr
AddrLabelExpr * getLabelExpr(unsigned i) const
Definition: Stmt.cpp:519
copyIntoContext
static StringRef copyIntoContext(const ASTContext &C, StringRef str)
Definition: Stmt.cpp:878
clang::SwitchStmt
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2121
clang::AsmStmt::generateAsmString
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:433
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
clang::IfStmt::hasVarStorage
bool hasVarStorage() const
True if this IfStmt has storage for a variable declaration.
Definition: Stmt.h:1977
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::AsmStmt::getClobber
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:473
clang::WhileStmt
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2312
clang::CapturedStmt::captures
capture_range captures()
Definition: Stmt.h:3606
clang::ast_matchers::stmt
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
Definition: ASTMatchersInternal.cpp:796
clang::IfStmt::isObjCAvailabilityCheck
bool isObjCAvailabilityCheck() const
Definition: Stmt.cpp:994
clang::SEHTryStmt::getExceptHandler
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition: Stmt.cpp:1244
clang::VarDecl::getCanonicalDecl
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.cpp:2125
clang::CapturedStmt::setCapturedRegionKind
void setCapturedRegionKind(CapturedRegionKind Kind)
Set the captured region kind.
Definition: Stmt.cpp:1413
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::AttributedStmt::CreateEmpty
static AttributedStmt * CreateEmpty(const ASTContext &C, unsigned NumAttrs)
Definition: Stmt.cpp:425
clang::CompoundStmt::body_begin
body_iterator body_begin()
Definition: Stmt.h:1432
clang::Stmt::EnableStatistics
static void EnableStatistics()
Definition: Stmt.cpp:129
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:221
clang::Stmt::StmtClass
StmtClass
Definition: Stmt.h:70
TargetInfo.h
clang::WhileStmt::hasVarStorage
bool hasVarStorage() const
True if this WhileStmt has storage for a condition variable.
Definition: Stmt.h:2363
clang::Stmt::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
clang::GCCAsmStmt::getLabelName
StringRef getLabelName(unsigned i) const
Definition: Stmt.cpp:523
Attr.h
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
clang::AsmStmt::getOutputConstraint
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:441
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::IfStmt
IfStmt - This represents an if/then/else.
Definition: Stmt.h:1903
clang::CapturedRegionKind
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:16
llvm::Optional
Definition: LLVM.h:40
clang::IfStmt::getNondiscardedCase
Optional< const Stmt * > getNondiscardedCase(const ASTContext &Ctx) const
If this is an 'if constexpr', determine which substatement will be taken.
Definition: Stmt.cpp:1005
ExprOpenMP.h
clang::MSAsmStmt::MSAsmStmt
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:865
clang::sema::Capture
Definition: ScopeInfo.h:521
check_implementations
static LLVM_ATTRIBUTE_UNUSED void check_implementations()
Check whether the various Stmt classes implement their member functions.
Definition: Stmt.cpp:276
clang::tooling::fixit::internal::getSourceRange
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
clang::CapturedDecl
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4342
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::SEHExceptStmt::Create
static SEHExceptStmt * Create(const ASTContext &C, SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block)
Definition: Stmt.cpp:1258
clang::CapturedStmt::getCapturedRegionKind
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition: Stmt.cpp:1408
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:626
clang::Stmt::EmptyShell
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition: Stmt.h:1102
clang::SEHTryStmt
Definition: Stmt.h:3379
clang::AsmStmt::isSimple
bool isSimple() const
Definition: Stmt.h:2847
Decl.h
clang::Stmt::NoStmtClass
@ NoStmtClass
Definition: Stmt.h:71
clang::ForStmt::ForStmt
ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP)
Definition: Stmt.cpp:1012
ExprConcepts.h
clang::CapturedStmt::VCK_ByRef
@ VCK_ByRef
Definition: Stmt.h:3477
clang::ASTContext::Allocate
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:701
clang::AsmStmt::Exprs
Stmt ** Exprs
Definition: Stmt.h:2832
clang::AttributedStmt
Represents an attribute applied to a statement.
Definition: Stmt.h:1845
clang::CapturedStmt::capturesVariable
bool capturesVariable(const VarDecl *Var) const
True if this variable has been captured.
Definition: Stmt.cpp:1417
BLOCK
#define BLOCK(DERIVED, BASE)
Definition: Template.h:516
V
#define V(N, I)
Definition: ASTContext.h:3113
clang::ReturnStmt::Create
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1195
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1398
StmtOpenMP.h
clang::IndirectGotoStmt::getConstantTarget
LabelDecl * getConstantTarget()
getConstantTarget - Returns the fixed target of this indirect goto, if one exists.
Definition: Stmt.cpp:1174
clang::WhileStmt::Create
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:1134
clang::Stmt::SwitchStmtBits
SwitchStmtBitfields SwitchStmtBits
Definition: Stmt.h:1010
clang::GCCAsmStmt::getClobber
StringRef getClobber(unsigned i) const
Definition: Stmt.cpp:496
clang::CapturedStmt::Capture::Capture
Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var=nullptr)
Create a new capture.
Definition: Stmt.cpp:1271
clang::AsmStmt::getInputExpr
const Expr * getInputExpr(unsigned i) const
Definition: Stmt.cpp:465
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:222
clang::GCCAsmStmt::getAsmString
const StringLiteral * getAsmString() const
Definition: Stmt.h:3001
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:211
clang::isLetter
LLVM_READONLY bool isLetter(unsigned char c)
Return true if this character is an ASCII letter: [a-zA-Z].
Definition: CharInfo.h:116
clang::IfStmt::getConditionVariableDeclStmt
DeclStmt * getConditionVariableDeclStmt()
If this IfStmt has a condition variable, return the faux DeclStmt associated with the creation of tha...
Definition: Stmt.h:2038
clang::GCCAsmStmt::AsmStringPiece
AsmStringPiece - this is part of a decomposed asm string specification (for use with the AnalyzeAsmSt...
Definition: Stmt.h:3008
clang::SwitchStmt::CreateEmpty
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:1083
clang::CapturedStmt::setCapturedDecl
void setCapturedDecl(CapturedDecl *D)
Set the outlined function declaration.
Definition: Stmt.cpp:1402
clang::LabelDecl
Represents the declaration of a label.
Definition: Decl.h:496
clang::Stmt::stripLabelLikeStatements
const Stmt * stripLabelLikeStatements() const
Strip off all label-like statements.
Definition: Stmt.cpp:217
clang::CaseStmt::Create
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1211
clang::Stmt::children
child_range children()
Definition: Stmt.cpp:285
clang::GCCAsmStmt::getOutputName
StringRef getOutputName(unsigned i) const
Definition: Stmt.h:3065
clang::Stmt::LH_None
@ LH_None
No attribute set or branches of the IfStmt have the same attribute.
Definition: Stmt.h:1107
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
clang::CapturedStmt::VariableCaptureKind
VariableCaptureKind
The different capture forms: by 'this', by reference, capture for variable-length array type etc.
Definition: Stmt.h:3475
clang::ValueStmt::getExprStmt
const Expr * getExprStmt() const
Definition: Stmt.cpp:395
clang::SwitchStmt::getConditionVariableDeclStmt
DeclStmt * getConditionVariableDeclStmt()
If this SwitchStmt has a condition variable, return the faux DeclStmt associated with the creation of...
Definition: Stmt.h:2242
clang::AttributedStmt::Create
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:416
Type.h
Expr.h
ASTContext.h
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::CapturedStmt::CreateDeserialized
static CapturedStmt * CreateDeserialized(const ASTContext &Context, unsigned NumCaptures)
Definition: Stmt.cpp:1371
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1761
clang::Stmt::LH_Likely
@ LH_Likely
Branch has the [[likely]] attribute.
Definition: Stmt.h:1109
clang::CapturedStmt
This captures a statement into a function.
Definition: Stmt.h:3471
clang::Expr::EvaluateKnownConstInt
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Definition: ExprConstant.cpp:14961
StmtClassNameTable::Size
unsigned Size
Definition: Stmt.cpp:53
clang::CapturedStmt::Capture
Describes the capture of either a variable, or 'this', or variable-length array type.
Definition: Stmt.h:3484
clang::IfStmt::getElse
Stmt * getElse()
Definition: Stmt.h:2003
clang::SwitchStmt::Create
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1072
ExprObjC.h
getStmtInfoTableEntry
static StmtClassNameTable & getStmtInfoTableEntry(Stmt::StmtClass E)
Definition: Stmt.cpp:56
ExprCXX.h
clang::ReturnStmt::CreateEmpty
static ReturnStmt * CreateEmpty(const ASTContext &Ctx, bool HasNRVOCandidate)
Create an empty return statement, optionally with storage for an NRVO candidate.
Definition: Stmt.cpp:1203
clang::Stmt::child_range
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1246
clang::IfStmt::CreateEmpty
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:964
DeclGroup.h
clang::Stmt::WhileStmtBits
WhileStmtBitfields WhileStmtBits
Definition: Stmt.h:1011
clang::GCCAsmStmt::AnalyzeAsmString
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:594
clang::SwitchStmt::setBody
void setBody(Stmt *Body)
Definition: Stmt.h:2202
ASTDiagnostic.h
clang::StringLiteral::getLocationOfByte
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:1259
clang::WhileStmt::getConditionVariable
VarDecl * getConditionVariable()
Retrieve the variable declared in this "while" statement, if any.
Definition: Stmt.cpp:1152
clang::GCCAsmStmt::getInputName
StringRef getInputName(unsigned i) const
Definition: Stmt.h:3093
clang::MSAsmStmt::generateAsmString
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:798
StmtObjC.h
clang::CompoundStmt::CreateEmpty
static CompoundStmt * CreateEmpty(const ASTContext &C, unsigned NumStmts)
Definition: Stmt.cpp:386
clang::AsmStmt::getNumOutputs
unsigned getNumOutputs() const
Definition: Stmt.h:2863
clang::SEHExceptStmt
Definition: Stmt.h:3300
StmtClassNameTable::Counter
unsigned Counter
Definition: Stmt.cpp:52
clang::GCCAsmStmt::getInputConstraintLiteral
const StringLiteral * getInputConstraintLiteral(unsigned i) const
Definition: Stmt.h:3102
clang::Stmt::const_child_range
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1247
clang::AsmStmt::NumOutputs
unsigned NumOutputs
Definition: Stmt.h:2828
clang::GCCAsmStmt::getInputConstraint
StringRef getInputConstraint(unsigned i) const
getInputConstraint - Return the specified input constraint.
Definition: Stmt.cpp:529
clang::WhileStmt::setConditionVariable
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable of this while statement.
Definition: Stmt.cpp:1159
SourceLocation.h
clang::CR_Default
@ CR_Default
Definition: CapturedStmt.h:17
clang::AsmStmt
AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
Definition: Stmt.h:2814
clang::GCCAsmStmt::getOutputConstraint
StringRef getOutputConstraint(unsigned i) const
getOutputConstraint - Return the constraint string for the specified output operand.
Definition: Stmt.cpp:507
clang::ForStmt::setInit
void setInit(Stmt *S)
Definition: Stmt.h:2546
clang::Stmt::getID
int64_t getID(const ASTContext &Context) const
Definition: Stmt.cpp:360
clang::AsmStmt::NumInputs
unsigned NumInputs
Definition: Stmt.h:2829
clang::SwitchStmt::setCond
void setCond(Expr *Cond)
Definition: Stmt.h:2193
CharInfo.h
clang::MSAsmStmt::setInputExpr
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:831
clang::Stmt::getStmtClass
StmtClass getStmtClass() const
Definition: Stmt.h:1162
clang::SwitchStmt::setRParenLoc
void setRParenLoc(SourceLocation Loc)
Definition: Stmt.h:2263
clang::Stmt::IgnoreContainers
Stmt * IgnoreContainers(bool IgnoreCaptured=false)
Skip no-op (attributed, compound) container stmts and skip captured stmt at the top,...
Definition: Stmt.cpp:195
clang::SwitchStmt::setLParenLoc
void setLParenLoc(SourceLocation Loc)
Definition: Stmt.h:2261
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
clang::Stmt::addStmtClass
static void addStmtClass(const StmtClass s)
Definition: Stmt.cpp:124
StmtClassInfo
static struct StmtClassNameTable StmtClassInfo[Stmt::lastStmtConstant+1]
clang::Stmt::determineLikelihoodConflict
static std::tuple< bool, const Attr *, const Attr * > determineLikelihoodConflict(const Stmt *Then, const Stmt *Else)
Definition: Stmt.cpp:183
clang::LabelStmt::getName
const char * getName() const
Definition: Stmt.cpp:412
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
llvm::ArrayRef
Definition: LLVM.h:34
clang::Stmt::Likelihood
Likelihood
The likelihood of a branch being taken.
Definition: Stmt.h:1105
clang::ForStmt::setConditionVariable
void setConditionVariable(const ASTContext &C, VarDecl *V)
Definition: Stmt.cpp:1033
clang::AddrLabelExpr
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4300
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::AsmStmt::getNumInputs
unsigned getNumInputs() const
Definition: Stmt.h:2885
clang::WhileStmt::CreateEmpty
static WhileStmt * CreateEmpty(const ASTContext &Ctx, bool HasVar)
Create an empty while statement optionally with storage for a condition variable.
Definition: Stmt.cpp:1145
clang::IndirectGotoStmt::getTarget
Expr * getTarget()
Definition: Stmt.h:2635
clang::SEHFinallyStmt::Create
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:1266
LLVM.h
clang::GCCAsmStmt::getOutputConstraintLiteral
const StringLiteral * getOutputConstraintLiteral(unsigned i) const
Definition: Stmt.h:3074
clang::SEHTryStmt::getHandler
Stmt * getHandler() const
Definition: Stmt.h:3412
clang::GCCAsmStmt::getOutputExpr
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:500
clang::IfStmt::getConditionVariable
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition: Stmt.cpp:973
clang::GCCAsmStmt::AsmStringPiece::getModifier
char getModifier() const
getModifier - Get the modifier for this operand, if present.
Definition: Stmt.cpp:491
clang::MSAsmStmt::getOutputExpr
Expr * getOutputExpr(unsigned i)
Definition: Stmt.cpp:823
clang::Stmt::getLikelihood
static Likelihood getLikelihood(ArrayRef< const Attr * > Attrs)
Definition: Stmt.cpp:153
clang::GCCAsmStmt::getNumLabels
unsigned getNumLabels() const
Definition: Stmt.h:3122
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:67
clang::GCCAsmStmt::GCCAsmStmt
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:839
clang::AsmStmt::getNumPlusOperands
unsigned getNumPlusOperands() const
getNumPlusOperands - Return the number of output operands that have a "+" constraint.
Definition: Stmt.cpp:483
clang::Stmt::LH_Unlikely
@ LH_Unlikely
Branch has the [[unlikely]] attribute.
Definition: Stmt.h:1106
clang::AsmStmt::isOutputPlusConstraint
bool isOutputPlusConstraint(unsigned i) const
isOutputPlusConstraint - Return true if the specified output constraint is a "+" constraint (which is...
Definition: Stmt.h:2873
clang::Stmt::PrintStats
static void PrintStats()
Definition: Stmt.cpp:99
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
getLikelihood
static std::pair< Stmt::Likelihood, const Attr * > getLikelihood(ArrayRef< const Attr * > Attrs)
Definition: Stmt.cpp:134
bytes
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:123
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::IdentifierInfo::getNameStart
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
Definition: IdentifierTable.h:169
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1291
clang::TargetInfo::handleAsmEscapedChar
virtual llvm::Optional< std::string > handleAsmEscapedChar(char C) const
Replace some escaped characters with another string based on target-specific rules.
Definition: TargetInfo.h:1115
clang::IfStmt::getCond
Expr * getCond()
Definition: Stmt.h:1982
clang::GCCAsmStmt::generateAsmString
std::string generateAsmString(const ASTContext &C) const
Assemble final IR asm string.
Definition: Stmt.cpp:777
clang::SEHFinallyStmt
Definition: Stmt.h:3344
clang::MSAsmStmt::getInputExpr
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:827
clang::AsmStmt::getOutputExpr
const Expr * getOutputExpr(unsigned i) const
Definition: Stmt.cpp:449
clang::IfStmt::isConstexpr
bool isConstexpr() const
Definition: Stmt.h:2080
clang::CapturedStmt::children
child_range children()
Definition: Stmt.cpp:1384
clang::IfStmt::setConditionVariable
void setConditionVariable(const ASTContext &Ctx, VarDecl *V)
Set the condition variable for this if statement.
Definition: Stmt.cpp:980
clang::Stmt::ForStmtBits
ForStmtBitfields ForStmtBits
Definition: Stmt.h:1013
clang
Definition: CalledOnceCheck.h:17
clang::NumConstraints
@ NumConstraints
Definition: AnalyzerOptions.h:54
clang::DeclaratorContext::Block
@ Block
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:68
clang::Stmt::getLikelihoodAttr
static const Attr * getLikelihoodAttr(const Stmt *S)
Definition: Stmt.cpp:161
clang::CapturedStmt::Capture::getCapturedVar
VarDecl * getCapturedVar() const
Retrieve the declaration of the variable being captured.
Definition: Stmt.cpp:1296
clang::GCCAsmStmt::getClobberStringLiteral
StringLiteral * getClobberStringLiteral(unsigned i)
Definition: Stmt.h:3182
clang::GCCAsmStmt::getInputExpr
Expr * getInputExpr(unsigned i)
Definition: Stmt.cpp:511
clang::isDigit
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:98
StmtClassNameTable::Name
const char * Name
Definition: Stmt.cpp:51
clang::CapturedStmt::VCK_This
@ VCK_This
Definition: Stmt.h:3476
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:46
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:315
Initialized
@ Initialized
Definition: UninitializedValues.cpp:103
clang::WhileStmt::getConditionVariableDeclStmt
DeclStmt * getConditionVariableDeclStmt()
If this WhileStmt has a condition variable, return the faux DeclStmt associated with the creation of ...
Definition: Stmt.h:2405
clang::CapturedStmt::Capture::getCaptureKind
VariableCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: Stmt.cpp:1292
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::IfStmt::getThen
Stmt * getThen()
Definition: Stmt.h:1994
clang::Stmt::CompoundStmtBits
CompoundStmtBitfields CompoundStmtBits
Definition: Stmt.h:1006
clang::CapturedStmt::Create
static CapturedStmt * Create(const ASTContext &Context, Stmt *S, CapturedRegionKind Kind, ArrayRef< Capture > Captures, ArrayRef< Expr * > CaptureInits, CapturedDecl *CD, RecordDecl *RD)
Definition: Stmt.cpp:1343
clang::LabelStmt::getDecl
LabelDecl * getDecl() const
Definition: Stmt.h:1816
clang::SwitchStmt::setConditionVariable
void setConditionVariable(const ASTContext &Ctx, VarDecl *VD)
Set the condition variable in this switch statement.
Definition: Stmt.cpp:1098
clang::SEHTryStmt::Create
static SEHTryStmt * Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Definition: Stmt.cpp:1238
v
do v
Definition: arm_acle.h:76
Stmt.h
clang::Stmt::getStmtClassName
const char * getStmtClassName() const
Definition: Stmt.cpp:77
clang::Stmt::ReturnStmtBits
ReturnStmtBitfields ReturnStmtBits
Definition: Stmt.h:1017
clang::SwitchStmt::getConditionVariable
VarDecl * getConditionVariable()
Retrieve the variable declared in this "switch" statement, if any.
Definition: Stmt.cpp:1091
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::ForStmt::setCond
void setCond(Expr *E)
Definition: Stmt.h:2547
clang::Expr
This represents one expression.
Definition: Expr.h:109
SM
#define SM(sm)
Definition: Cuda.cpp:78
clang::CapturedStmt::getCapturedDecl
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition: Stmt.cpp:1393
Token.h
clang::AsmStmt::NumClobbers
unsigned NumClobbers
Definition: Stmt.h:2830
clang::GCCAsmStmt::setInputExpr
void setInputExpr(unsigned i, Expr *E)
Definition: Stmt.cpp:515
clang::Stmt::StmtBits
StmtBitfields StmtBits
Definition: Stmt.h:1004
clang::AddrLabelExpr::getLabel
LabelDecl * getLabel() const
Definition: Expr.h:4323
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3859
clang::CompoundStmt::Create
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:379
StmtCXX.h
clang::StringLiteral::getString
StringRef getString() const
Definition: Expr.h:1844
clang::ASTContext::getAllocator
llvm::BumpPtrAllocator & getAllocator() const
Definition: ASTContext.h:697
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:2731
clang::GCCAsmStmt::AsmStringPiece::isOperand
bool isOperand() const
Definition: Stmt.h:3031
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276