clang  8.0.0svn
Expr.cpp
Go to the documentation of this file.
1 //===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Expr class and subclasses.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.h"
20 #include "clang/AST/Expr.h"
21 #include "clang/AST/ExprCXX.h"
22 #include "clang/AST/Mangle.h"
23 #include "clang/AST/RecordLayout.h"
24 #include "clang/AST/StmtVisitor.h"
25 #include "clang/Basic/Builtins.h"
26 #include "clang/Basic/CharInfo.h"
28 #include "clang/Basic/TargetInfo.h"
29 #include "clang/Lex/Lexer.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include <algorithm>
35 #include <cstring>
36 using namespace clang;
37 
39  const Expr *E = this;
40  while (true) {
41  E = E->ignoreParenBaseCasts();
42 
43  // Follow the RHS of a comma operator.
44  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
45  if (BO->getOpcode() == BO_Comma) {
46  E = BO->getRHS();
47  continue;
48  }
49  }
50 
51  // Step into initializer for materialized temporaries.
52  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
53  E = MTE->GetTemporaryExpr();
54  continue;
55  }
56 
57  break;
58  }
59 
60  return E;
61 }
62 
64  const Expr *E = getBestDynamicClassTypeExpr();
65  QualType DerivedType = E->getType();
66  if (const PointerType *PTy = DerivedType->getAs<PointerType>())
67  DerivedType = PTy->getPointeeType();
68 
69  if (DerivedType->isDependentType())
70  return nullptr;
71 
72  const RecordType *Ty = DerivedType->castAs<RecordType>();
73  Decl *D = Ty->getDecl();
74  return cast<CXXRecordDecl>(D);
75 }
76 
79  SmallVectorImpl<SubobjectAdjustment> &Adjustments) const {
80  const Expr *E = this;
81  while (true) {
82  E = E->IgnoreParens();
83 
84  if (const CastExpr *CE = dyn_cast<CastExpr>(E)) {
85  if ((CE->getCastKind() == CK_DerivedToBase ||
86  CE->getCastKind() == CK_UncheckedDerivedToBase) &&
87  E->getType()->isRecordType()) {
88  E = CE->getSubExpr();
89  CXXRecordDecl *Derived
90  = cast<CXXRecordDecl>(E->getType()->getAs<RecordType>()->getDecl());
91  Adjustments.push_back(SubobjectAdjustment(CE, Derived));
92  continue;
93  }
94 
95  if (CE->getCastKind() == CK_NoOp) {
96  E = CE->getSubExpr();
97  continue;
98  }
99  } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
100  if (!ME->isArrow()) {
101  assert(ME->getBase()->getType()->isRecordType());
102  if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
103  if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
104  E = ME->getBase();
105  Adjustments.push_back(SubobjectAdjustment(Field));
106  continue;
107  }
108  }
109  }
110  } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
111  if (BO->getOpcode() == BO_PtrMemD) {
112  assert(BO->getRHS()->isRValue());
113  E = BO->getLHS();
114  const MemberPointerType *MPT =
115  BO->getRHS()->getType()->getAs<MemberPointerType>();
116  Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS()));
117  continue;
118  } else if (BO->getOpcode() == BO_Comma) {
119  CommaLHSs.push_back(BO->getLHS());
120  E = BO->getRHS();
121  continue;
122  }
123  }
124 
125  // Nothing changed.
126  break;
127  }
128  return E;
129 }
130 
131 /// isKnownToHaveBooleanValue - Return true if this is an integer expression
132 /// that is known to return 0 or 1. This happens for _Bool/bool expressions
133 /// but also int expressions which are produced by things like comparisons in
134 /// C.
136  const Expr *E = IgnoreParens();
137 
138  // If this value has _Bool type, it is obvious 0/1.
139  if (E->getType()->isBooleanType()) return true;
140  // If this is a non-scalar-integer type, we don't care enough to try.
141  if (!E->getType()->isIntegralOrEnumerationType()) return false;
142 
143  if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
144  switch (UO->getOpcode()) {
145  case UO_Plus:
146  return UO->getSubExpr()->isKnownToHaveBooleanValue();
147  case UO_LNot:
148  return true;
149  default:
150  return false;
151  }
152  }
153 
154  // Only look through implicit casts. If the user writes
155  // '(int) (a && b)' treat it as an arbitrary int.
156  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
157  return CE->getSubExpr()->isKnownToHaveBooleanValue();
158 
159  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
160  switch (BO->getOpcode()) {
161  default: return false;
162  case BO_LT: // Relational operators.
163  case BO_GT:
164  case BO_LE:
165  case BO_GE:
166  case BO_EQ: // Equality operators.
167  case BO_NE:
168  case BO_LAnd: // AND operator.
169  case BO_LOr: // Logical OR operator.
170  return true;
171 
172  case BO_And: // Bitwise AND operator.
173  case BO_Xor: // Bitwise XOR operator.
174  case BO_Or: // Bitwise OR operator.
175  // Handle things like (x==2)|(y==12).
176  return BO->getLHS()->isKnownToHaveBooleanValue() &&
177  BO->getRHS()->isKnownToHaveBooleanValue();
178 
179  case BO_Comma:
180  case BO_Assign:
181  return BO->getRHS()->isKnownToHaveBooleanValue();
182  }
183  }
184 
185  if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E))
186  return CO->getTrueExpr()->isKnownToHaveBooleanValue() &&
187  CO->getFalseExpr()->isKnownToHaveBooleanValue();
188 
189  return false;
190 }
191 
192 // Amusing macro metaprogramming hack: check whether a class provides
193 // a more specific implementation of getExprLoc().
194 //
195 // See also Stmt.cpp:{getBeginLoc(),getEndLoc()}.
196 namespace {
197  /// This implementation is used when a class provides a custom
198  /// implementation of getExprLoc.
199  template <class E, class T>
200  SourceLocation getExprLocImpl(const Expr *expr,
201  SourceLocation (T::*v)() const) {
202  return static_cast<const E*>(expr)->getExprLoc();
203  }
204 
205  /// This implementation is used when a class doesn't provide
206  /// a custom implementation of getExprLoc. Overload resolution
207  /// should pick it over the implementation above because it's
208  /// more specialized according to function template partial ordering.
209  template <class E>
210  SourceLocation getExprLocImpl(const Expr *expr,
211  SourceLocation (Expr::*v)() const) {
212  return static_cast<const E *>(expr)->getBeginLoc();
213  }
214 }
215 
217  switch (getStmtClass()) {
218  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
219 #define ABSTRACT_STMT(type)
220 #define STMT(type, base) \
221  case Stmt::type##Class: break;
222 #define EXPR(type, base) \
223  case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc);
224 #include "clang/AST/StmtNodes.inc"
225  }
226  llvm_unreachable("unknown expression kind");
227 }
228 
229 //===----------------------------------------------------------------------===//
230 // Primary Expressions.
231 //===----------------------------------------------------------------------===//
232 
233 /// Compute the type-, value-, and instantiation-dependence of a
234 /// declaration reference
235 /// based on the declaration being referenced.
236 static void computeDeclRefDependence(const ASTContext &Ctx, NamedDecl *D,
237  QualType T, bool &TypeDependent,
238  bool &ValueDependent,
239  bool &InstantiationDependent) {
240  TypeDependent = false;
241  ValueDependent = false;
242  InstantiationDependent = false;
243 
244  // (TD) C++ [temp.dep.expr]p3:
245  // An id-expression is type-dependent if it contains:
246  //
247  // and
248  //
249  // (VD) C++ [temp.dep.constexpr]p2:
250  // An identifier is value-dependent if it is:
251 
252  // (TD) - an identifier that was declared with dependent type
253  // (VD) - a name declared with a dependent type,
254  if (T->isDependentType()) {
255  TypeDependent = true;
256  ValueDependent = true;
257  InstantiationDependent = true;
258  return;
259  } else if (T->isInstantiationDependentType()) {
260  InstantiationDependent = true;
261  }
262 
263  // (TD) - a conversion-function-id that specifies a dependent type
264  if (D->getDeclName().getNameKind()
267  if (T->isDependentType()) {
268  TypeDependent = true;
269  ValueDependent = true;
270  InstantiationDependent = true;
271  return;
272  }
273 
275  InstantiationDependent = true;
276  }
277 
278  // (VD) - the name of a non-type template parameter,
279  if (isa<NonTypeTemplateParmDecl>(D)) {
280  ValueDependent = true;
281  InstantiationDependent = true;
282  return;
283  }
284 
285  // (VD) - a constant with integral or enumeration type and is
286  // initialized with an expression that is value-dependent.
287  // (VD) - a constant with literal type and is initialized with an
288  // expression that is value-dependent [C++11].
289  // (VD) - FIXME: Missing from the standard:
290  // - an entity with reference type and is initialized with an
291  // expression that is value-dependent [C++11]
292  if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
293  if ((Ctx.getLangOpts().CPlusPlus11 ?
294  Var->getType()->isLiteralType(Ctx) :
295  Var->getType()->isIntegralOrEnumerationType()) &&
296  (Var->getType().isConstQualified() ||
297  Var->getType()->isReferenceType())) {
298  if (const Expr *Init = Var->getAnyInitializer())
299  if (Init->isValueDependent()) {
300  ValueDependent = true;
301  InstantiationDependent = true;
302  }
303  }
304 
305  // (VD) - FIXME: Missing from the standard:
306  // - a member function or a static data member of the current
307  // instantiation
308  if (Var->isStaticDataMember() &&
309  Var->getDeclContext()->isDependentContext()) {
310  ValueDependent = true;
311  InstantiationDependent = true;
312  TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo();
313  if (TInfo->getType()->isIncompleteArrayType())
314  TypeDependent = true;
315  }
316 
317  return;
318  }
319 
320  // (VD) - FIXME: Missing from the standard:
321  // - a member function or a static data member of the current
322  // instantiation
323  if (isa<CXXMethodDecl>(D) && D->getDeclContext()->isDependentContext()) {
324  ValueDependent = true;
325  InstantiationDependent = true;
326  }
327 }
328 
329 void DeclRefExpr::computeDependence(const ASTContext &Ctx) {
330  bool TypeDependent = false;
331  bool ValueDependent = false;
332  bool InstantiationDependent = false;
333  computeDeclRefDependence(Ctx, getDecl(), getType(), TypeDependent,
334  ValueDependent, InstantiationDependent);
335 
336  ExprBits.TypeDependent |= TypeDependent;
337  ExprBits.ValueDependent |= ValueDependent;
338  ExprBits.InstantiationDependent |= InstantiationDependent;
339 
340  // Is the declaration a parameter pack?
341  if (getDecl()->isParameterPack())
342  ExprBits.ContainsUnexpandedParameterPack = true;
343 }
344 
345 DeclRefExpr::DeclRefExpr(const ASTContext &Ctx,
346  NestedNameSpecifierLoc QualifierLoc,
347  SourceLocation TemplateKWLoc,
348  ValueDecl *D, bool RefersToEnclosingVariableOrCapture,
349  const DeclarationNameInfo &NameInfo,
350  NamedDecl *FoundD,
351  const TemplateArgumentListInfo *TemplateArgs,
352  QualType T, ExprValueKind VK)
353  : Expr(DeclRefExprClass, T, VK, OK_Ordinary, false, false, false, false),
354  D(D), DNLoc(NameInfo.getInfo()) {
355  DeclRefExprBits.Loc = NameInfo.getLoc();
356  DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0;
357  if (QualifierLoc) {
358  new (getTrailingObjects<NestedNameSpecifierLoc>())
359  NestedNameSpecifierLoc(QualifierLoc);
360  auto *NNS = QualifierLoc.getNestedNameSpecifier();
361  if (NNS->isInstantiationDependent())
362  ExprBits.InstantiationDependent = true;
363  if (NNS->containsUnexpandedParameterPack())
364  ExprBits.ContainsUnexpandedParameterPack = true;
365  }
366  DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0;
367  if (FoundD)
368  *getTrailingObjects<NamedDecl *>() = FoundD;
369  DeclRefExprBits.HasTemplateKWAndArgsInfo
370  = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0;
371  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
372  RefersToEnclosingVariableOrCapture;
373  if (TemplateArgs) {
374  bool Dependent = false;
375  bool InstantiationDependent = false;
376  bool ContainsUnexpandedParameterPack = false;
377  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
378  TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
379  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
380  assert(!Dependent && "built a DeclRefExpr with dependent template args");
381  ExprBits.InstantiationDependent |= InstantiationDependent;
382  ExprBits.ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;
383  } else if (TemplateKWLoc.isValid()) {
384  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
385  TemplateKWLoc);
386  }
387  DeclRefExprBits.HadMultipleCandidates = 0;
388 
389  computeDependence(Ctx);
390 }
391 
393  NestedNameSpecifierLoc QualifierLoc,
394  SourceLocation TemplateKWLoc,
395  ValueDecl *D,
396  bool RefersToEnclosingVariableOrCapture,
397  SourceLocation NameLoc,
398  QualType T,
399  ExprValueKind VK,
400  NamedDecl *FoundD,
401  const TemplateArgumentListInfo *TemplateArgs) {
402  return Create(Context, QualifierLoc, TemplateKWLoc, D,
403  RefersToEnclosingVariableOrCapture,
404  DeclarationNameInfo(D->getDeclName(), NameLoc),
405  T, VK, FoundD, TemplateArgs);
406 }
407 
409  NestedNameSpecifierLoc QualifierLoc,
410  SourceLocation TemplateKWLoc,
411  ValueDecl *D,
412  bool RefersToEnclosingVariableOrCapture,
413  const DeclarationNameInfo &NameInfo,
414  QualType T,
415  ExprValueKind VK,
416  NamedDecl *FoundD,
417  const TemplateArgumentListInfo *TemplateArgs) {
418  // Filter out cases where the found Decl is the same as the value refenenced.
419  if (D == FoundD)
420  FoundD = nullptr;
421 
422  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
423  std::size_t Size =
424  totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
426  QualifierLoc ? 1 : 0, FoundD ? 1 : 0,
427  HasTemplateKWAndArgsInfo ? 1 : 0,
428  TemplateArgs ? TemplateArgs->size() : 0);
429 
430  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
431  return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D,
432  RefersToEnclosingVariableOrCapture,
433  NameInfo, FoundD, TemplateArgs, T, VK);
434 }
435 
437  bool HasQualifier,
438  bool HasFoundDecl,
439  bool HasTemplateKWAndArgsInfo,
440  unsigned NumTemplateArgs) {
441  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
442  std::size_t Size =
443  totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
445  HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo,
446  NumTemplateArgs);
447  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
448  return new (Mem) DeclRefExpr(EmptyShell());
449 }
450 
452  if (hasQualifier())
453  return getQualifierLoc().getBeginLoc();
454  return getNameInfo().getBeginLoc();
455 }
457  if (hasExplicitTemplateArgs())
458  return getRAngleLoc();
459  return getNameInfo().getEndLoc();
460 }
461 
462 PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
463  StringLiteral *SL)
464  : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary,
465  FNTy->isDependentType(), FNTy->isDependentType(),
467  /*ContainsUnexpandedParameterPack=*/false) {
468  PredefinedExprBits.Kind = IK;
469  assert((getIdentKind() == IK) &&
470  "IdentKind do not fit in PredefinedExprBitfields!");
471  bool HasFunctionName = SL != nullptr;
472  PredefinedExprBits.HasFunctionName = HasFunctionName;
473  PredefinedExprBits.Loc = L;
474  if (HasFunctionName)
475  setFunctionName(SL);
476 }
477 
478 PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName)
479  : Expr(PredefinedExprClass, Empty) {
480  PredefinedExprBits.HasFunctionName = HasFunctionName;
481 }
482 
484  QualType FNTy, IdentKind IK,
485  StringLiteral *SL) {
486  bool HasFunctionName = SL != nullptr;
487  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
488  alignof(PredefinedExpr));
489  return new (Mem) PredefinedExpr(L, FNTy, IK, SL);
490 }
491 
493  bool HasFunctionName) {
494  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
495  alignof(PredefinedExpr));
496  return new (Mem) PredefinedExpr(EmptyShell(), HasFunctionName);
497 }
498 
500  switch (IK) {
501  case Func:
502  return "__func__";
503  case Function:
504  return "__FUNCTION__";
505  case FuncDName:
506  return "__FUNCDNAME__";
507  case LFunction:
508  return "L__FUNCTION__";
509  case PrettyFunction:
510  return "__PRETTY_FUNCTION__";
511  case FuncSig:
512  return "__FUNCSIG__";
513  case LFuncSig:
514  return "L__FUNCSIG__";
515  case PrettyFunctionNoVirtual:
516  break;
517  }
518  llvm_unreachable("Unknown ident kind for PredefinedExpr");
519 }
520 
521 // FIXME: Maybe this should use DeclPrinter with a special "print predefined
522 // expr" policy instead.
523 std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) {
524  ASTContext &Context = CurrentDecl->getASTContext();
525 
526  if (IK == PredefinedExpr::FuncDName) {
527  if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
528  std::unique_ptr<MangleContext> MC;
529  MC.reset(Context.createMangleContext());
530 
531  if (MC->shouldMangleDeclName(ND)) {
532  SmallString<256> Buffer;
533  llvm::raw_svector_ostream Out(Buffer);
534  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND))
535  MC->mangleCXXCtor(CD, Ctor_Base, Out);
536  else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND))
537  MC->mangleCXXDtor(DD, Dtor_Base, Out);
538  else
539  MC->mangleName(ND, Out);
540 
541  if (!Buffer.empty() && Buffer.front() == '\01')
542  return Buffer.substr(1);
543  return Buffer.str();
544  } else
545  return ND->getIdentifier()->getName();
546  }
547  return "";
548  }
549  if (isa<BlockDecl>(CurrentDecl)) {
550  // For blocks we only emit something if it is enclosed in a function
551  // For top-level block we'd like to include the name of variable, but we
552  // don't have it at this point.
553  auto DC = CurrentDecl->getDeclContext();
554  if (DC->isFileContext())
555  return "";
556 
557  SmallString<256> Buffer;
558  llvm::raw_svector_ostream Out(Buffer);
559  if (auto *DCBlock = dyn_cast<BlockDecl>(DC))
560  // For nested blocks, propagate up to the parent.
561  Out << ComputeName(IK, DCBlock);
562  else if (auto *DCDecl = dyn_cast<Decl>(DC))
563  Out << ComputeName(IK, DCDecl) << "_block_invoke";
564  return Out.str();
565  }
566  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
567  if (IK != PrettyFunction && IK != PrettyFunctionNoVirtual &&
568  IK != FuncSig && IK != LFuncSig)
569  return FD->getNameAsString();
570 
571  SmallString<256> Name;
572  llvm::raw_svector_ostream Out(Name);
573 
574  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
575  if (MD->isVirtual() && IK != PrettyFunctionNoVirtual)
576  Out << "virtual ";
577  if (MD->isStatic())
578  Out << "static ";
579  }
580 
581  PrintingPolicy Policy(Context.getLangOpts());
582  std::string Proto;
583  llvm::raw_string_ostream POut(Proto);
584 
585  const FunctionDecl *Decl = FD;
586  if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
587  Decl = Pattern;
588  const FunctionType *AFT = Decl->getType()->getAs<FunctionType>();
589  const FunctionProtoType *FT = nullptr;
590  if (FD->hasWrittenPrototype())
591  FT = dyn_cast<FunctionProtoType>(AFT);
592 
593  if (IK == FuncSig || IK == LFuncSig) {
594  switch (AFT->getCallConv()) {
595  case CC_C: POut << "__cdecl "; break;
596  case CC_X86StdCall: POut << "__stdcall "; break;
597  case CC_X86FastCall: POut << "__fastcall "; break;
598  case CC_X86ThisCall: POut << "__thiscall "; break;
599  case CC_X86VectorCall: POut << "__vectorcall "; break;
600  case CC_X86RegCall: POut << "__regcall "; break;
601  // Only bother printing the conventions that MSVC knows about.
602  default: break;
603  }
604  }
605 
606  FD->printQualifiedName(POut, Policy);
607 
608  POut << "(";
609  if (FT) {
610  for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
611  if (i) POut << ", ";
612  POut << Decl->getParamDecl(i)->getType().stream(Policy);
613  }
614 
615  if (FT->isVariadic()) {
616  if (FD->getNumParams()) POut << ", ";
617  POut << "...";
618  } else if ((IK == FuncSig || IK == LFuncSig ||
619  !Context.getLangOpts().CPlusPlus) &&
620  !Decl->getNumParams()) {
621  POut << "void";
622  }
623  }
624  POut << ")";
625 
626  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
627  assert(FT && "We must have a written prototype in this case.");
628  if (FT->isConst())
629  POut << " const";
630  if (FT->isVolatile())
631  POut << " volatile";
632  RefQualifierKind Ref = MD->getRefQualifier();
633  if (Ref == RQ_LValue)
634  POut << " &";
635  else if (Ref == RQ_RValue)
636  POut << " &&";
637  }
638 
640  SpecsTy Specs;
641  const DeclContext *Ctx = FD->getDeclContext();
642  while (Ctx && isa<NamedDecl>(Ctx)) {
644  = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
645  if (Spec && !Spec->isExplicitSpecialization())
646  Specs.push_back(Spec);
647  Ctx = Ctx->getParent();
648  }
649 
650  std::string TemplateParams;
651  llvm::raw_string_ostream TOut(TemplateParams);
652  for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend();
653  I != E; ++I) {
654  const TemplateParameterList *Params
655  = (*I)->getSpecializedTemplate()->getTemplateParameters();
656  const TemplateArgumentList &Args = (*I)->getTemplateArgs();
657  assert(Params->size() == Args.size());
658  for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) {
659  StringRef Param = Params->getParam(i)->getName();
660  if (Param.empty()) continue;
661  TOut << Param << " = ";
662  Args.get(i).print(Policy, TOut);
663  TOut << ", ";
664  }
665  }
666 
668  = FD->getTemplateSpecializationInfo();
669  if (FSI && !FSI->isExplicitSpecialization()) {
670  const TemplateParameterList* Params
672  const TemplateArgumentList* Args = FSI->TemplateArguments;
673  assert(Params->size() == Args->size());
674  for (unsigned i = 0, e = Params->size(); i != e; ++i) {
675  StringRef Param = Params->getParam(i)->getName();
676  if (Param.empty()) continue;
677  TOut << Param << " = ";
678  Args->get(i).print(Policy, TOut);
679  TOut << ", ";
680  }
681  }
682 
683  TOut.flush();
684  if (!TemplateParams.empty()) {
685  // remove the trailing comma and space
686  TemplateParams.resize(TemplateParams.size() - 2);
687  POut << " [" << TemplateParams << "]";
688  }
689 
690  POut.flush();
691 
692  // Print "auto" for all deduced return types. This includes C++1y return
693  // type deduction and lambdas. For trailing return types resolve the
694  // decltype expression. Otherwise print the real type when this is
695  // not a constructor or destructor.
696  if (isa<CXXMethodDecl>(FD) &&
697  cast<CXXMethodDecl>(FD)->getParent()->isLambda())
698  Proto = "auto " + Proto;
699  else if (FT && FT->getReturnType()->getAs<DecltypeType>())
700  FT->getReturnType()
701  ->getAs<DecltypeType>()
703  .getAsStringInternal(Proto, Policy);
704  else if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
705  AFT->getReturnType().getAsStringInternal(Proto, Policy);
706 
707  Out << Proto;
708 
709  return Name.str().str();
710  }
711  if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) {
712  for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent())
713  // Skip to its enclosing function or method, but not its enclosing
714  // CapturedDecl.
715  if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) {
716  const Decl *D = Decl::castFromDeclContext(DC);
717  return ComputeName(IK, D);
718  }
719  llvm_unreachable("CapturedDecl not inside a function or method");
720  }
721  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
722  SmallString<256> Name;
723  llvm::raw_svector_ostream Out(Name);
724  Out << (MD->isInstanceMethod() ? '-' : '+');
725  Out << '[';
726 
727  // For incorrect code, there might not be an ObjCInterfaceDecl. Do
728  // a null check to avoid a crash.
729  if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
730  Out << *ID;
731 
732  if (const ObjCCategoryImplDecl *CID =
733  dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext()))
734  Out << '(' << *CID << ')';
735 
736  Out << ' ';
737  MD->getSelector().print(Out);
738  Out << ']';
739 
740  return Name.str().str();
741  }
742  if (isa<TranslationUnitDecl>(CurrentDecl) && IK == PrettyFunction) {
743  // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string.
744  return "top level";
745  }
746  return "";
747 }
748 
750  const llvm::APInt &Val) {
751  if (hasAllocation())
752  C.Deallocate(pVal);
753 
754  BitWidth = Val.getBitWidth();
755  unsigned NumWords = Val.getNumWords();
756  const uint64_t* Words = Val.getRawData();
757  if (NumWords > 1) {
758  pVal = new (C) uint64_t[NumWords];
759  std::copy(Words, Words + NumWords, pVal);
760  } else if (NumWords == 1)
761  VAL = Words[0];
762  else
763  VAL = 0;
764 }
765 
766 IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V,
768  : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
769  false, false),
770  Loc(l) {
771  assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
772  assert(V.getBitWidth() == C.getIntWidth(type) &&
773  "Integer type is not the correct size for constant.");
774  setValue(C, V);
775 }
776 
778 IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V,
780  return new (C) IntegerLiteral(C, V, type, l);
781 }
782 
785  return new (C) IntegerLiteral(Empty);
786 }
787 
788 FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V,
790  unsigned Scale)
791  : Expr(FixedPointLiteralClass, type, VK_RValue, OK_Ordinary, false, false,
792  false, false),
793  Loc(l), Scale(Scale) {
794  assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral");
795  assert(V.getBitWidth() == C.getTypeInfo(type).Width &&
796  "Fixed point type is not the correct size for constant.");
797  setValue(C, V);
798 }
799 
801  const llvm::APInt &V,
802  QualType type,
803  SourceLocation l,
804  unsigned Scale) {
805  return new (C) FixedPointLiteral(C, V, type, l, Scale);
806 }
807 
808 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
809  // Currently the longest decimal number that can be printed is the max for an
810  // unsigned long _Accum: 4294967295.99999999976716935634613037109375
811  // which is 43 characters.
812  SmallString<64> S;
814  S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale);
815  return S.str();
816 }
817 
818 FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V,
819  bool isexact, QualType Type, SourceLocation L)
820  : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary, false, false,
821  false, false), Loc(L) {
822  setSemantics(V.getSemantics());
823  FloatingLiteralBits.IsExact = isexact;
824  setValue(C, V);
825 }
826 
827 FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty)
828  : Expr(FloatingLiteralClass, Empty) {
829  setRawSemantics(IEEEhalf);
830  FloatingLiteralBits.IsExact = false;
831 }
832 
834 FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V,
835  bool isexact, QualType Type, SourceLocation L) {
836  return new (C) FloatingLiteral(C, V, isexact, Type, L);
837 }
838 
841  return new (C) FloatingLiteral(C, Empty);
842 }
843 
844 const llvm::fltSemantics &FloatingLiteral::getSemantics() const {
845  switch(FloatingLiteralBits.Semantics) {
846  case IEEEhalf:
847  return llvm::APFloat::IEEEhalf();
848  case IEEEsingle:
849  return llvm::APFloat::IEEEsingle();
850  case IEEEdouble:
851  return llvm::APFloat::IEEEdouble();
852  case x87DoubleExtended:
853  return llvm::APFloat::x87DoubleExtended();
854  case IEEEquad:
855  return llvm::APFloat::IEEEquad();
856  case PPCDoubleDouble:
857  return llvm::APFloat::PPCDoubleDouble();
858  }
859  llvm_unreachable("Unrecognised floating semantics");
860 }
861 
862 void FloatingLiteral::setSemantics(const llvm::fltSemantics &Sem) {
863  if (&Sem == &llvm::APFloat::IEEEhalf())
864  FloatingLiteralBits.Semantics = IEEEhalf;
865  else if (&Sem == &llvm::APFloat::IEEEsingle())
866  FloatingLiteralBits.Semantics = IEEEsingle;
867  else if (&Sem == &llvm::APFloat::IEEEdouble())
868  FloatingLiteralBits.Semantics = IEEEdouble;
869  else if (&Sem == &llvm::APFloat::x87DoubleExtended())
871  else if (&Sem == &llvm::APFloat::IEEEquad())
872  FloatingLiteralBits.Semantics = IEEEquad;
873  else if (&Sem == &llvm::APFloat::PPCDoubleDouble())
875  else
876  llvm_unreachable("Unknown floating semantics");
877 }
878 
879 /// getValueAsApproximateDouble - This returns the value as an inaccurate
880 /// double. Note that this may cause loss of precision, but is useful for
881 /// debugging dumps, etc.
883  llvm::APFloat V = getValue();
884  bool ignored;
885  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
886  &ignored);
887  return V.convertToDouble();
888 }
889 
890 int StringLiteral::mapCharByteWidth(TargetInfo const &target,StringKind k) {
891  int CharByteWidth = 0;
892  switch(k) {
893  case Ascii:
894  case UTF8:
895  CharByteWidth = target.getCharWidth();
896  break;
897  case Wide:
898  CharByteWidth = target.getWCharWidth();
899  break;
900  case UTF16:
901  CharByteWidth = target.getChar16Width();
902  break;
903  case UTF32:
904  CharByteWidth = target.getChar32Width();
905  break;
906  }
907  assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple");
908  CharByteWidth /= 8;
909  assert((CharByteWidth==1 || CharByteWidth==2 || CharByteWidth==4)
910  && "character byte widths supported are 1, 2, and 4 only");
911  return CharByteWidth;
912 }
913 
915  StringKind Kind, bool Pascal, QualType Ty,
916  const SourceLocation *Loc,
917  unsigned NumStrs) {
918  assert(C.getAsConstantArrayType(Ty) &&
919  "StringLiteral must be of constant array type!");
920 
921  // Allocate enough space for the StringLiteral plus an array of locations for
922  // any concatenated string tokens.
923  void *Mem =
924  C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1),
925  alignof(StringLiteral));
926  StringLiteral *SL = new (Mem) StringLiteral(Ty);
927 
928  // OPTIMIZE: could allocate this appended to the StringLiteral.
929  SL->setString(C,Str,Kind,Pascal);
930 
931  SL->TokLocs[0] = Loc[0];
932  SL->NumConcatenated = NumStrs;
933 
934  if (NumStrs != 1)
935  memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
936  return SL;
937 }
938 
940  unsigned NumStrs) {
941  void *Mem =
942  C.Allocate(sizeof(StringLiteral) + sizeof(SourceLocation) * (NumStrs - 1),
943  alignof(StringLiteral));
944  StringLiteral *SL =
946  SL->CharByteWidth = 0;
947  SL->Length = 0;
948  SL->NumConcatenated = NumStrs;
949  return SL;
950 }
951 
952 void StringLiteral::outputString(raw_ostream &OS) const {
953  switch (getKind()) {
954  case Ascii: break; // no prefix.
955  case Wide: OS << 'L'; break;
956  case UTF8: OS << "u8"; break;
957  case UTF16: OS << 'u'; break;
958  case UTF32: OS << 'U'; break;
959  }
960  OS << '"';
961  static const char Hex[] = "0123456789ABCDEF";
962 
963  unsigned LastSlashX = getLength();
964  for (unsigned I = 0, N = getLength(); I != N; ++I) {
965  switch (uint32_t Char = getCodeUnit(I)) {
966  default:
967  // FIXME: Convert UTF-8 back to codepoints before rendering.
968 
969  // Convert UTF-16 surrogate pairs back to codepoints before rendering.
970  // Leave invalid surrogates alone; we'll use \x for those.
971  if (getKind() == UTF16 && I != N - 1 && Char >= 0xd800 &&
972  Char <= 0xdbff) {
973  uint32_t Trail = getCodeUnit(I + 1);
974  if (Trail >= 0xdc00 && Trail <= 0xdfff) {
975  Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00);
976  ++I;
977  }
978  }
979 
980  if (Char > 0xff) {
981  // If this is a wide string, output characters over 0xff using \x
982  // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a
983  // codepoint: use \x escapes for invalid codepoints.
984  if (getKind() == Wide ||
985  (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) {
986  // FIXME: Is this the best way to print wchar_t?
987  OS << "\\x";
988  int Shift = 28;
989  while ((Char >> Shift) == 0)
990  Shift -= 4;
991  for (/**/; Shift >= 0; Shift -= 4)
992  OS << Hex[(Char >> Shift) & 15];
993  LastSlashX = I;
994  break;
995  }
996 
997  if (Char > 0xffff)
998  OS << "\\U00"
999  << Hex[(Char >> 20) & 15]
1000  << Hex[(Char >> 16) & 15];
1001  else
1002  OS << "\\u";
1003  OS << Hex[(Char >> 12) & 15]
1004  << Hex[(Char >> 8) & 15]
1005  << Hex[(Char >> 4) & 15]
1006  << Hex[(Char >> 0) & 15];
1007  break;
1008  }
1009 
1010  // If we used \x... for the previous character, and this character is a
1011  // hexadecimal digit, prevent it being slurped as part of the \x.
1012  if (LastSlashX + 1 == I) {
1013  switch (Char) {
1014  case '0': case '1': case '2': case '3': case '4':
1015  case '5': case '6': case '7': case '8': case '9':
1016  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1017  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1018  OS << "\"\"";
1019  }
1020  }
1021 
1022  assert(Char <= 0xff &&
1023  "Characters above 0xff should already have been handled.");
1024 
1025  if (isPrintable(Char))
1026  OS << (char)Char;
1027  else // Output anything hard as an octal escape.
1028  OS << '\\'
1029  << (char)('0' + ((Char >> 6) & 7))
1030  << (char)('0' + ((Char >> 3) & 7))
1031  << (char)('0' + ((Char >> 0) & 7));
1032  break;
1033  // Handle some common non-printable cases to make dumps prettier.
1034  case '\\': OS << "\\\\"; break;
1035  case '"': OS << "\\\""; break;
1036  case '\a': OS << "\\a"; break;
1037  case '\b': OS << "\\b"; break;
1038  case '\f': OS << "\\f"; break;
1039  case '\n': OS << "\\n"; break;
1040  case '\r': OS << "\\r"; break;
1041  case '\t': OS << "\\t"; break;
1042  case '\v': OS << "\\v"; break;
1043  }
1044  }
1045  OS << '"';
1046 }
1047 
1048 void StringLiteral::setString(const ASTContext &C, StringRef Str,
1049  StringKind Kind, bool IsPascal) {
1050  //FIXME: we assume that the string data comes from a target that uses the same
1051  // code unit size and endianness for the type of string.
1052  this->Kind = Kind;
1053  this->IsPascal = IsPascal;
1054 
1055  CharByteWidth = mapCharByteWidth(C.getTargetInfo(),Kind);
1056  assert((Str.size()%CharByteWidth == 0)
1057  && "size of data must be multiple of CharByteWidth");
1058  Length = Str.size()/CharByteWidth;
1059 
1060  switch(CharByteWidth) {
1061  case 1: {
1062  char *AStrData = new (C) char[Length];
1063  std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData));
1064  StrData.asChar = AStrData;
1065  break;
1066  }
1067  case 2: {
1068  uint16_t *AStrData = new (C) uint16_t[Length];
1069  std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData));
1070  StrData.asUInt16 = AStrData;
1071  break;
1072  }
1073  case 4: {
1074  uint32_t *AStrData = new (C) uint32_t[Length];
1075  std::memcpy(AStrData,Str.data(),Length*sizeof(*AStrData));
1076  StrData.asUInt32 = AStrData;
1077  break;
1078  }
1079  default:
1080  llvm_unreachable("unsupported CharByteWidth");
1081  }
1082 }
1083 
1084 /// getLocationOfByte - Return a source location that points to the specified
1085 /// byte of this string literal.
1086 ///
1087 /// Strings are amazingly complex. They can be formed from multiple tokens and
1088 /// can have escape sequences in them in addition to the usual trigraph and
1089 /// escaped newline business. This routine handles this complexity.
1090 ///
1091 /// The *StartToken sets the first token to be searched in this function and
1092 /// the *StartTokenByteOffset is the byte offset of the first token. Before
1093 /// returning, it updates the *StartToken to the TokNo of the token being found
1094 /// and sets *StartTokenByteOffset to the byte offset of the token in the
1095 /// string.
1096 /// Using these two parameters can reduce the time complexity from O(n^2) to
1097 /// O(n) if one wants to get the location of byte for all the tokens in a
1098 /// string.
1099 ///
1102  const LangOptions &Features,
1103  const TargetInfo &Target, unsigned *StartToken,
1104  unsigned *StartTokenByteOffset) const {
1105  assert((Kind == StringLiteral::Ascii || Kind == StringLiteral::UTF8) &&
1106  "Only narrow string literals are currently supported");
1107 
1108  // Loop over all of the tokens in this string until we find the one that
1109  // contains the byte we're looking for.
1110  unsigned TokNo = 0;
1111  unsigned StringOffset = 0;
1112  if (StartToken)
1113  TokNo = *StartToken;
1114  if (StartTokenByteOffset) {
1115  StringOffset = *StartTokenByteOffset;
1116  ByteNo -= StringOffset;
1117  }
1118  while (1) {
1119  assert(TokNo < getNumConcatenated() && "Invalid byte number!");
1120  SourceLocation StrTokLoc = getStrTokenLoc(TokNo);
1121 
1122  // Get the spelling of the string so that we can get the data that makes up
1123  // the string literal, not the identifier for the macro it is potentially
1124  // expanded through.
1125  SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc);
1126 
1127  // Re-lex the token to get its length and original spelling.
1128  std::pair<FileID, unsigned> LocInfo =
1129  SM.getDecomposedLoc(StrTokSpellingLoc);
1130  bool Invalid = false;
1131  StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
1132  if (Invalid) {
1133  if (StartTokenByteOffset != nullptr)
1134  *StartTokenByteOffset = StringOffset;
1135  if (StartToken != nullptr)
1136  *StartToken = TokNo;
1137  return StrTokSpellingLoc;
1138  }
1139 
1140  const char *StrData = Buffer.data()+LocInfo.second;
1141 
1142  // Create a lexer starting at the beginning of this token.
1143  Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features,
1144  Buffer.begin(), StrData, Buffer.end());
1145  Token TheTok;
1146  TheLexer.LexFromRawLexer(TheTok);
1147 
1148  // Use the StringLiteralParser to compute the length of the string in bytes.
1149  StringLiteralParser SLP(TheTok, SM, Features, Target);
1150  unsigned TokNumBytes = SLP.GetStringLength();
1151 
1152  // If the byte is in this token, return the location of the byte.
1153  if (ByteNo < TokNumBytes ||
1154  (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) {
1155  unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo);
1156 
1157  // Now that we know the offset of the token in the spelling, use the
1158  // preprocessor to get the offset in the original source.
1159  if (StartTokenByteOffset != nullptr)
1160  *StartTokenByteOffset = StringOffset;
1161  if (StartToken != nullptr)
1162  *StartToken = TokNo;
1163  return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features);
1164  }
1165 
1166  // Move to the next string token.
1167  StringOffset += TokNumBytes;
1168  ++TokNo;
1169  ByteNo -= TokNumBytes;
1170  }
1171 }
1172 
1173 
1174 
1175 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1176 /// corresponds to, e.g. "sizeof" or "[pre]++".
1178  switch (Op) {
1179 #define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
1180 #include "clang/AST/OperationKinds.def"
1181  }
1182  llvm_unreachable("Unknown unary operator");
1183 }
1184 
1187  switch (OO) {
1188  default: llvm_unreachable("No unary operator for overloaded function");
1189  case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc;
1190  case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec;
1191  case OO_Amp: return UO_AddrOf;
1192  case OO_Star: return UO_Deref;
1193  case OO_Plus: return UO_Plus;
1194  case OO_Minus: return UO_Minus;
1195  case OO_Tilde: return UO_Not;
1196  case OO_Exclaim: return UO_LNot;
1197  case OO_Coawait: return UO_Coawait;
1198  }
1199 }
1200 
1202  switch (Opc) {
1203  case UO_PostInc: case UO_PreInc: return OO_PlusPlus;
1204  case UO_PostDec: case UO_PreDec: return OO_MinusMinus;
1205  case UO_AddrOf: return OO_Amp;
1206  case UO_Deref: return OO_Star;
1207  case UO_Plus: return OO_Plus;
1208  case UO_Minus: return OO_Minus;
1209  case UO_Not: return OO_Tilde;
1210  case UO_LNot: return OO_Exclaim;
1211  case UO_Coawait: return OO_Coawait;
1212  default: return OO_None;
1213  }
1214 }
1215 
1216 
1217 //===----------------------------------------------------------------------===//
1218 // Postfix Operators.
1219 //===----------------------------------------------------------------------===//
1220 
1222  ArrayRef<Expr *> preargs, ArrayRef<Expr *> args, QualType t,
1223  ExprValueKind VK, SourceLocation rparenloc)
1224  : Expr(SC, t, VK, OK_Ordinary, fn->isTypeDependent(),
1227  NumArgs(args.size()) {
1228 
1229  unsigned NumPreArgs = preargs.size();
1230  SubExprs = new (C) Stmt *[args.size()+PREARGS_START+NumPreArgs];
1231  SubExprs[FN] = fn;
1232  for (unsigned i = 0; i != NumPreArgs; ++i) {
1233  updateDependenciesFromArg(preargs[i]);
1234  SubExprs[i+PREARGS_START] = preargs[i];
1235  }
1236  for (unsigned i = 0; i != args.size(); ++i) {
1237  updateDependenciesFromArg(args[i]);
1238  SubExprs[i+PREARGS_START+NumPreArgs] = args[i];
1239  }
1240 
1241  CallExprBits.NumPreArgs = NumPreArgs;
1242  RParenLoc = rparenloc;
1243 }
1244 
1247  SourceLocation rparenloc)
1248  : CallExpr(C, SC, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) {}
1249 
1251  QualType t, ExprValueKind VK, SourceLocation rparenloc)
1252  : CallExpr(C, CallExprClass, fn, ArrayRef<Expr *>(), args, t, VK, rparenloc) {
1253 }
1254 
1256  : CallExpr(C, SC, /*NumPreArgs=*/0, Empty) {}
1257 
1258 CallExpr::CallExpr(const ASTContext &C, StmtClass SC, unsigned NumPreArgs,
1259  EmptyShell Empty)
1260  : Expr(SC, Empty), SubExprs(nullptr), NumArgs(0) {
1261  // FIXME: Why do we allocate this?
1262  SubExprs = new (C) Stmt*[PREARGS_START+NumPreArgs]();
1263  CallExprBits.NumPreArgs = NumPreArgs;
1264 }
1265 
1266 void CallExpr::updateDependenciesFromArg(Expr *Arg) {
1267  if (Arg->isTypeDependent())
1268  ExprBits.TypeDependent = true;
1269  if (Arg->isValueDependent())
1270  ExprBits.ValueDependent = true;
1271  if (Arg->isInstantiationDependent())
1272  ExprBits.InstantiationDependent = true;
1274  ExprBits.ContainsUnexpandedParameterPack = true;
1275 }
1276 
1278  return dyn_cast_or_null<FunctionDecl>(getCalleeDecl());
1279 }
1280 
1283 }
1284 
1286  Expr *CEE = IgnoreParenImpCasts();
1287 
1288  while (SubstNonTypeTemplateParmExpr *NTTP
1289  = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
1290  CEE = NTTP->getReplacement()->IgnoreParenCasts();
1291  }
1292 
1293  // If we're calling a dereference, look at the pointer instead.
1294  if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
1295  if (BO->isPtrMemOp())
1296  CEE = BO->getRHS()->IgnoreParenCasts();
1297  } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
1298  if (UO->getOpcode() == UO_Deref)
1299  CEE = UO->getSubExpr()->IgnoreParenCasts();
1300  }
1301  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
1302  return DRE->getDecl();
1303  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
1304  return ME->getMemberDecl();
1305 
1306  return nullptr;
1307 }
1308 
1309 /// setNumArgs - This changes the number of arguments present in this call.
1310 /// Any orphaned expressions are deleted by this, and any new operands are set
1311 /// to null.
1312 void CallExpr::setNumArgs(const ASTContext& C, unsigned NumArgs) {
1313  // No change, just return.
1314  if (NumArgs == getNumArgs()) return;
1315 
1316  // If shrinking # arguments, just delete the extras and forgot them.
1317  if (NumArgs < getNumArgs()) {
1318  this->NumArgs = NumArgs;
1319  return;
1320  }
1321 
1322  // Otherwise, we are growing the # arguments. New an bigger argument array.
1323  unsigned NumPreArgs = getNumPreArgs();
1324  Stmt **NewSubExprs = new (C) Stmt*[NumArgs+PREARGS_START+NumPreArgs];
1325  // Copy over args.
1326  for (unsigned i = 0; i != getNumArgs()+PREARGS_START+NumPreArgs; ++i)
1327  NewSubExprs[i] = SubExprs[i];
1328  // Null out new args.
1329  for (unsigned i = getNumArgs()+PREARGS_START+NumPreArgs;
1330  i != NumArgs+PREARGS_START+NumPreArgs; ++i)
1331  NewSubExprs[i] = nullptr;
1332 
1333  if (SubExprs) C.Deallocate(SubExprs);
1334  SubExprs = NewSubExprs;
1335  this->NumArgs = NumArgs;
1336 }
1337 
1338 /// getBuiltinCallee - If this is a call to a builtin, return the builtin ID. If
1339 /// not, return 0.
1340 unsigned CallExpr::getBuiltinCallee() const {
1341  // All simple function calls (e.g. func()) are implicitly cast to pointer to
1342  // function. As a result, we try and obtain the DeclRefExpr from the
1343  // ImplicitCastExpr.
1344  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
1345  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
1346  return 0;
1347 
1348  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
1349  if (!DRE)
1350  return 0;
1351 
1352  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
1353  if (!FDecl)
1354  return 0;
1355 
1356  if (!FDecl->getIdentifier())
1357  return 0;
1358 
1359  return FDecl->getBuiltinID();
1360 }
1361 
1363  if (unsigned BI = getBuiltinCallee())
1364  return Ctx.BuiltinInfo.isUnevaluated(BI);
1365  return false;
1366 }
1367 
1369  const Expr *Callee = getCallee();
1370  QualType CalleeType = Callee->getType();
1371  if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) {
1372  CalleeType = FnTypePtr->getPointeeType();
1373  } else if (const auto *BPT = CalleeType->getAs<BlockPointerType>()) {
1374  CalleeType = BPT->getPointeeType();
1375  } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) {
1376  if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens()))
1377  return Ctx.VoidTy;
1378 
1379  // This should never be overloaded and so should never return null.
1380  CalleeType = Expr::findBoundMemberType(Callee);
1381  }
1382 
1383  const FunctionType *FnType = CalleeType->castAs<FunctionType>();
1384  return FnType->getReturnType();
1385 }
1386 
1388  if (isa<CXXOperatorCallExpr>(this))
1389  return cast<CXXOperatorCallExpr>(this)->getBeginLoc();
1390 
1391  SourceLocation begin = getCallee()->getBeginLoc();
1392  if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
1393  begin = getArg(0)->getBeginLoc();
1394  return begin;
1395 }
1397  if (isa<CXXOperatorCallExpr>(this))
1398  return cast<CXXOperatorCallExpr>(this)->getEndLoc();
1399 
1400  SourceLocation end = getRParenLoc();
1401  if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
1402  end = getArg(getNumArgs() - 1)->getEndLoc();
1403  return end;
1404 }
1405 
1407  SourceLocation OperatorLoc,
1408  TypeSourceInfo *tsi,
1409  ArrayRef<OffsetOfNode> comps,
1410  ArrayRef<Expr*> exprs,
1411  SourceLocation RParenLoc) {
1412  void *Mem = C.Allocate(
1413  totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size()));
1414 
1415  return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs,
1416  RParenLoc);
1417 }
1418 
1420  unsigned numComps, unsigned numExprs) {
1421  void *Mem =
1422  C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs));
1423  return new (Mem) OffsetOfExpr(numComps, numExprs);
1424 }
1425 
1426 OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type,
1427  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1429  SourceLocation RParenLoc)
1430  : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary,
1431  /*TypeDependent=*/false,
1432  /*ValueDependent=*/tsi->getType()->isDependentType(),
1435  OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
1436  NumComps(comps.size()), NumExprs(exprs.size())
1437 {
1438  for (unsigned i = 0; i != comps.size(); ++i) {
1439  setComponent(i, comps[i]);
1440  }
1441 
1442  for (unsigned i = 0; i != exprs.size(); ++i) {
1443  if (exprs[i]->isTypeDependent() || exprs[i]->isValueDependent())
1444  ExprBits.ValueDependent = true;
1445  if (exprs[i]->containsUnexpandedParameterPack())
1446  ExprBits.ContainsUnexpandedParameterPack = true;
1447 
1448  setIndexExpr(i, exprs[i]);
1449  }
1450 }
1451 
1453  assert(getKind() == Field || getKind() == Identifier);
1454  if (getKind() == Field)
1455  return getField()->getIdentifier();
1456 
1457  return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask);
1458 }
1459 
1461  UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType,
1463  : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary,
1464  false, // Never type-dependent (C++ [temp.dep.expr]p3).
1465  // Value-dependent if the argument is type-dependent.
1468  OpLoc(op), RParenLoc(rp) {
1469  UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1470  UnaryExprOrTypeTraitExprBits.IsType = false;
1471  Argument.Ex = E;
1472 
1473  // Check to see if we are in the situation where alignof(decl) should be
1474  // dependent because decl's alignment is dependent.
1475  if (ExprKind == UETT_AlignOf || ExprKind == UETT_PreferredAlignOf) {
1477  E = E->IgnoreParens();
1478 
1479  const ValueDecl *D = nullptr;
1480  if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
1481  D = DRE->getDecl();
1482  else if (const auto *ME = dyn_cast<MemberExpr>(E))
1483  D = ME->getMemberDecl();
1484 
1485  if (D) {
1486  for (const auto *I : D->specific_attrs<AlignedAttr>()) {
1487  if (I->isAlignmentDependent()) {
1488  setValueDependent(true);
1490  break;
1491  }
1492  }
1493  }
1494  }
1495  }
1496 }
1497 
1499  const ASTContext &C, Expr *base, bool isarrow, SourceLocation OperatorLoc,
1500  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1501  ValueDecl *memberdecl, DeclAccessPair founddecl,
1502  DeclarationNameInfo nameinfo, const TemplateArgumentListInfo *targs,
1503  QualType ty, ExprValueKind vk, ExprObjectKind ok) {
1504 
1505  bool hasQualOrFound = (QualifierLoc ||
1506  founddecl.getDecl() != memberdecl ||
1507  founddecl.getAccess() != memberdecl->getAccess());
1508 
1509  bool HasTemplateKWAndArgsInfo = targs || TemplateKWLoc.isValid();
1510  std::size_t Size =
1512  TemplateArgumentLoc>(hasQualOrFound ? 1 : 0,
1513  HasTemplateKWAndArgsInfo ? 1 : 0,
1514  targs ? targs->size() : 0);
1515 
1516  void *Mem = C.Allocate(Size, alignof(MemberExpr));
1517  MemberExpr *E = new (Mem)
1518  MemberExpr(base, isarrow, OperatorLoc, memberdecl, nameinfo, ty, vk, ok);
1519 
1520  if (hasQualOrFound) {
1521  // FIXME: Wrong. We should be looking at the member declaration we found.
1522  if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1523  E->setValueDependent(true);
1524  E->setTypeDependent(true);
1525  E->setInstantiationDependent(true);
1526  }
1527  else if (QualifierLoc &&
1529  E->setInstantiationDependent(true);
1530 
1531  E->HasQualifierOrFoundDecl = true;
1532 
1533  MemberExprNameQualifier *NQ =
1534  E->getTrailingObjects<MemberExprNameQualifier>();
1535  NQ->QualifierLoc = QualifierLoc;
1536  NQ->FoundDecl = founddecl;
1537  }
1538 
1539  E->HasTemplateKWAndArgsInfo = (targs || TemplateKWLoc.isValid());
1540 
1541  if (targs) {
1542  bool Dependent = false;
1543  bool InstantiationDependent = false;
1544  bool ContainsUnexpandedParameterPack = false;
1545  E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1546  TemplateKWLoc, *targs, E->getTrailingObjects<TemplateArgumentLoc>(),
1547  Dependent, InstantiationDependent, ContainsUnexpandedParameterPack);
1548  if (InstantiationDependent)
1549  E->setInstantiationDependent(true);
1550  } else if (TemplateKWLoc.isValid()) {
1551  E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1552  TemplateKWLoc);
1553  }
1554 
1555  return E;
1556 }
1557 
1559  if (isImplicitAccess()) {
1560  if (hasQualifier())
1561  return getQualifierLoc().getBeginLoc();
1562  return MemberLoc;
1563  }
1564 
1565  // FIXME: We don't want this to happen. Rather, we should be able to
1566  // detect all kinds of implicit accesses more cleanly.
1567  SourceLocation BaseStartLoc = getBase()->getBeginLoc();
1568  if (BaseStartLoc.isValid())
1569  return BaseStartLoc;
1570  return MemberLoc;
1571 }
1573  SourceLocation EndLoc = getMemberNameInfo().getEndLoc();
1574  if (hasExplicitTemplateArgs())
1575  EndLoc = getRAngleLoc();
1576  else if (EndLoc.isInvalid())
1577  EndLoc = getBase()->getEndLoc();
1578  return EndLoc;
1579 }
1580 
1581 bool CastExpr::CastConsistency() const {
1582  switch (getCastKind()) {
1583  case CK_DerivedToBase:
1584  case CK_UncheckedDerivedToBase:
1585  case CK_DerivedToBaseMemberPointer:
1586  case CK_BaseToDerived:
1587  case CK_BaseToDerivedMemberPointer:
1588  assert(!path_empty() && "Cast kind should have a base path!");
1589  break;
1590 
1591  case CK_CPointerToObjCPointerCast:
1592  assert(getType()->isObjCObjectPointerType());
1593  assert(getSubExpr()->getType()->isPointerType());
1594  goto CheckNoBasePath;
1595 
1596  case CK_BlockPointerToObjCPointerCast:
1597  assert(getType()->isObjCObjectPointerType());
1598  assert(getSubExpr()->getType()->isBlockPointerType());
1599  goto CheckNoBasePath;
1600 
1601  case CK_ReinterpretMemberPointer:
1602  assert(getType()->isMemberPointerType());
1603  assert(getSubExpr()->getType()->isMemberPointerType());
1604  goto CheckNoBasePath;
1605 
1606  case CK_BitCast:
1607  // Arbitrary casts to C pointer types count as bitcasts.
1608  // Otherwise, we should only have block and ObjC pointer casts
1609  // here if they stay within the type kind.
1610  if (!getType()->isPointerType()) {
1611  assert(getType()->isObjCObjectPointerType() ==
1612  getSubExpr()->getType()->isObjCObjectPointerType());
1613  assert(getType()->isBlockPointerType() ==
1614  getSubExpr()->getType()->isBlockPointerType());
1615  }
1616  goto CheckNoBasePath;
1617 
1618  case CK_AnyPointerToBlockPointerCast:
1619  assert(getType()->isBlockPointerType());
1620  assert(getSubExpr()->getType()->isAnyPointerType() &&
1621  !getSubExpr()->getType()->isBlockPointerType());
1622  goto CheckNoBasePath;
1623 
1624  case CK_CopyAndAutoreleaseBlockObject:
1625  assert(getType()->isBlockPointerType());
1626  assert(getSubExpr()->getType()->isBlockPointerType());
1627  goto CheckNoBasePath;
1628 
1629  case CK_FunctionToPointerDecay:
1630  assert(getType()->isPointerType());
1631  assert(getSubExpr()->getType()->isFunctionType());
1632  goto CheckNoBasePath;
1633 
1634  case CK_AddressSpaceConversion:
1635  assert(getType()->isPointerType() || getType()->isBlockPointerType());
1636  assert(getSubExpr()->getType()->isPointerType() ||
1637  getSubExpr()->getType()->isBlockPointerType());
1638  assert(getType()->getPointeeType().getAddressSpace() !=
1639  getSubExpr()->getType()->getPointeeType().getAddressSpace());
1640  LLVM_FALLTHROUGH;
1641  // These should not have an inheritance path.
1642  case CK_Dynamic:
1643  case CK_ToUnion:
1644  case CK_ArrayToPointerDecay:
1645  case CK_NullToMemberPointer:
1646  case CK_NullToPointer:
1647  case CK_ConstructorConversion:
1648  case CK_IntegralToPointer:
1649  case CK_PointerToIntegral:
1650  case CK_ToVoid:
1651  case CK_VectorSplat:
1652  case CK_IntegralCast:
1653  case CK_BooleanToSignedIntegral:
1654  case CK_IntegralToFloating:
1655  case CK_FloatingToIntegral:
1656  case CK_FloatingCast:
1657  case CK_ObjCObjectLValueCast:
1658  case CK_FloatingRealToComplex:
1659  case CK_FloatingComplexToReal:
1660  case CK_FloatingComplexCast:
1661  case CK_FloatingComplexToIntegralComplex:
1662  case CK_IntegralRealToComplex:
1663  case CK_IntegralComplexToReal:
1664  case CK_IntegralComplexCast:
1665  case CK_IntegralComplexToFloatingComplex:
1666  case CK_ARCProduceObject:
1667  case CK_ARCConsumeObject:
1668  case CK_ARCReclaimReturnedObject:
1669  case CK_ARCExtendBlockObject:
1670  case CK_ZeroToOCLOpaqueType:
1671  case CK_IntToOCLSampler:
1672  case CK_FixedPointCast:
1673  assert(!getType()->isBooleanType() && "unheralded conversion to bool");
1674  goto CheckNoBasePath;
1675 
1676  case CK_Dependent:
1677  case CK_LValueToRValue:
1678  case CK_NoOp:
1679  case CK_AtomicToNonAtomic:
1680  case CK_NonAtomicToAtomic:
1681  case CK_PointerToBoolean:
1682  case CK_IntegralToBoolean:
1683  case CK_FloatingToBoolean:
1684  case CK_MemberPointerToBoolean:
1685  case CK_FloatingComplexToBoolean:
1686  case CK_IntegralComplexToBoolean:
1687  case CK_LValueBitCast: // -> bool&
1688  case CK_UserDefinedConversion: // operator bool()
1689  case CK_BuiltinFnToFnPtr:
1690  case CK_FixedPointToBoolean:
1691  CheckNoBasePath:
1692  assert(path_empty() && "Cast kind should not have a base path!");
1693  break;
1694  }
1695  return true;
1696 }
1697 
1699  switch (CK) {
1700 #define CAST_OPERATION(Name) case CK_##Name: return #Name;
1701 #include "clang/AST/OperationKinds.def"
1702  }
1703  llvm_unreachable("Unhandled cast kind!");
1704 }
1705 
1706 namespace {
1707  const Expr *skipImplicitTemporary(const Expr *E) {
1708  // Skip through reference binding to temporary.
1709  if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E))
1710  E = Materialize->GetTemporaryExpr();
1711 
1712  // Skip any temporary bindings; they're implicit.
1713  if (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
1714  E = Binder->getSubExpr();
1715 
1716  return E;
1717  }
1718 }
1719 
1721  const Expr *SubExpr = nullptr;
1722  const CastExpr *E = this;
1723  do {
1724  SubExpr = skipImplicitTemporary(E->getSubExpr());
1725 
1726  // Conversions by constructor and conversion functions have a
1727  // subexpression describing the call; strip it off.
1728  if (E->getCastKind() == CK_ConstructorConversion)
1729  SubExpr =
1730  skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr)->getArg(0));
1731  else if (E->getCastKind() == CK_UserDefinedConversion) {
1732  assert((isa<CXXMemberCallExpr>(SubExpr) ||
1733  isa<BlockExpr>(SubExpr)) &&
1734  "Unexpected SubExpr for CK_UserDefinedConversion.");
1735  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
1736  SubExpr = MCE->getImplicitObjectArgument();
1737  }
1738 
1739  // If the subexpression we're left with is an implicit cast, look
1740  // through that, too.
1741  } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr)));
1742 
1743  return const_cast<Expr*>(SubExpr);
1744 }
1745 
1747  const Expr *SubExpr = nullptr;
1748 
1749  for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)) {
1750  SubExpr = skipImplicitTemporary(E->getSubExpr());
1751 
1752  if (E->getCastKind() == CK_ConstructorConversion)
1753  return cast<CXXConstructExpr>(SubExpr)->getConstructor();
1754 
1755  if (E->getCastKind() == CK_UserDefinedConversion) {
1756  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
1757  return MCE->getMethodDecl();
1758  }
1759  }
1760 
1761  return nullptr;
1762 }
1763 
1764 CastExpr::BasePathSizeTy *CastExpr::BasePathSize() {
1765  assert(!path_empty());
1766  switch (getStmtClass()) {
1767 #define ABSTRACT_STMT(x)
1768 #define CASTEXPR(Type, Base) \
1769  case Stmt::Type##Class: \
1770  return static_cast<Type *>(this) \
1771  ->getTrailingObjects<CastExpr::BasePathSizeTy>();
1772 #define STMT(Type, Base)
1773 #include "clang/AST/StmtNodes.inc"
1774  default:
1775  llvm_unreachable("non-cast expressions not possible here");
1776  }
1777 }
1778 
1779 CXXBaseSpecifier **CastExpr::path_buffer() {
1780  switch (getStmtClass()) {
1781 #define ABSTRACT_STMT(x)
1782 #define CASTEXPR(Type, Base) \
1783  case Stmt::Type##Class: \
1784  return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>();
1785 #define STMT(Type, Base)
1786 #include "clang/AST/StmtNodes.inc"
1787  default:
1788  llvm_unreachable("non-cast expressions not possible here");
1789  }
1790 }
1791 
1793  QualType opType) {
1794  auto RD = unionType->castAs<RecordType>()->getDecl();
1795  return getTargetFieldForToUnionCast(RD, opType);
1796 }
1797 
1799  QualType OpType) {
1800  auto &Ctx = RD->getASTContext();
1801  RecordDecl::field_iterator Field, FieldEnd;
1802  for (Field = RD->field_begin(), FieldEnd = RD->field_end();
1803  Field != FieldEnd; ++Field) {
1804  if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) &&
1805  !Field->isUnnamedBitfield()) {
1806  return *Field;
1807  }
1808  }
1809  return nullptr;
1810 }
1811 
1813  CastKind Kind, Expr *Operand,
1814  const CXXCastPath *BasePath,
1815  ExprValueKind VK) {
1816  unsigned PathSize = (BasePath ? BasePath->size() : 0);
1817  void *Buffer =
1818  C.Allocate(totalSizeToAlloc<CastExpr::BasePathSizeTy, CXXBaseSpecifier *>(
1819  PathSize ? 1 : 0, PathSize));
1820  ImplicitCastExpr *E =
1821  new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, VK);
1822  if (PathSize)
1823  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
1824  E->getTrailingObjects<CXXBaseSpecifier *>());
1825  return E;
1826 }
1827 
1829  unsigned PathSize) {
1830  void *Buffer =
1831  C.Allocate(totalSizeToAlloc<CastExpr::BasePathSizeTy, CXXBaseSpecifier *>(
1832  PathSize ? 1 : 0, PathSize));
1833  return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize);
1834 }
1835 
1836 
1838  ExprValueKind VK, CastKind K, Expr *Op,
1839  const CXXCastPath *BasePath,
1840  TypeSourceInfo *WrittenTy,
1842  unsigned PathSize = (BasePath ? BasePath->size() : 0);
1843  void *Buffer =
1844  C.Allocate(totalSizeToAlloc<CastExpr::BasePathSizeTy, CXXBaseSpecifier *>(
1845  PathSize ? 1 : 0, PathSize));
1846  CStyleCastExpr *E =
1847  new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, R);
1848  if (PathSize)
1849  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
1850  E->getTrailingObjects<CXXBaseSpecifier *>());
1851  return E;
1852 }
1853 
1855  unsigned PathSize) {
1856  void *Buffer =
1857  C.Allocate(totalSizeToAlloc<CastExpr::BasePathSizeTy, CXXBaseSpecifier *>(
1858  PathSize ? 1 : 0, PathSize));
1859  return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize);
1860 }
1861 
1862 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1863 /// corresponds to, e.g. "<<=".
1865  switch (Op) {
1866 #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling;
1867 #include "clang/AST/OperationKinds.def"
1868  }
1869  llvm_unreachable("Invalid OpCode!");
1870 }
1871 
1874  switch (OO) {
1875  default: llvm_unreachable("Not an overloadable binary operator");
1876  case OO_Plus: return BO_Add;
1877  case OO_Minus: return BO_Sub;
1878  case OO_Star: return BO_Mul;
1879  case OO_Slash: return BO_Div;
1880  case OO_Percent: return BO_Rem;
1881  case OO_Caret: return BO_Xor;
1882  case OO_Amp: return BO_And;
1883  case OO_Pipe: return BO_Or;
1884  case OO_Equal: return BO_Assign;
1885  case OO_Spaceship: return BO_Cmp;
1886  case OO_Less: return BO_LT;
1887  case OO_Greater: return BO_GT;
1888  case OO_PlusEqual: return BO_AddAssign;
1889  case OO_MinusEqual: return BO_SubAssign;
1890  case OO_StarEqual: return BO_MulAssign;
1891  case OO_SlashEqual: return BO_DivAssign;
1892  case OO_PercentEqual: return BO_RemAssign;
1893  case OO_CaretEqual: return BO_XorAssign;
1894  case OO_AmpEqual: return BO_AndAssign;
1895  case OO_PipeEqual: return BO_OrAssign;
1896  case OO_LessLess: return BO_Shl;
1897  case OO_GreaterGreater: return BO_Shr;
1898  case OO_LessLessEqual: return BO_ShlAssign;
1899  case OO_GreaterGreaterEqual: return BO_ShrAssign;
1900  case OO_EqualEqual: return BO_EQ;
1901  case OO_ExclaimEqual: return BO_NE;
1902  case OO_LessEqual: return BO_LE;
1903  case OO_GreaterEqual: return BO_GE;
1904  case OO_AmpAmp: return BO_LAnd;
1905  case OO_PipePipe: return BO_LOr;
1906  case OO_Comma: return BO_Comma;
1907  case OO_ArrowStar: return BO_PtrMemI;
1908  }
1909 }
1910 
1912  static const OverloadedOperatorKind OverOps[] = {
1913  /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
1914  OO_Star, OO_Slash, OO_Percent,
1915  OO_Plus, OO_Minus,
1916  OO_LessLess, OO_GreaterGreater,
1917  OO_Spaceship,
1918  OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
1919  OO_EqualEqual, OO_ExclaimEqual,
1920  OO_Amp,
1921  OO_Caret,
1922  OO_Pipe,
1923  OO_AmpAmp,
1924  OO_PipePipe,
1925  OO_Equal, OO_StarEqual,
1926  OO_SlashEqual, OO_PercentEqual,
1927  OO_PlusEqual, OO_MinusEqual,
1928  OO_LessLessEqual, OO_GreaterGreaterEqual,
1929  OO_AmpEqual, OO_CaretEqual,
1930  OO_PipeEqual,
1931  OO_Comma
1932  };
1933  return OverOps[Opc];
1934 }
1935 
1937  Opcode Opc,
1938  Expr *LHS, Expr *RHS) {
1939  if (Opc != BO_Add)
1940  return false;
1941 
1942  // Check that we have one pointer and one integer operand.
1943  Expr *PExp;
1944  if (LHS->getType()->isPointerType()) {
1945  if (!RHS->getType()->isIntegerType())
1946  return false;
1947  PExp = LHS;
1948  } else if (RHS->getType()->isPointerType()) {
1949  if (!LHS->getType()->isIntegerType())
1950  return false;
1951  PExp = RHS;
1952  } else {
1953  return false;
1954  }
1955 
1956  // Check that the pointer is a nullptr.
1957  if (!PExp->IgnoreParenCasts()
1959  return false;
1960 
1961  // Check that the pointee type is char-sized.
1962  const PointerType *PTy = PExp->getType()->getAs<PointerType>();
1963  if (!PTy || !PTy->getPointeeType()->isCharType())
1964  return false;
1965 
1966  return true;
1967 }
1969  ArrayRef<Expr*> initExprs, SourceLocation rbraceloc)
1970  : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false,
1971  false, false),
1972  InitExprs(C, initExprs.size()),
1973  LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), AltForm(nullptr, true)
1974 {
1975  sawArrayRangeDesignator(false);
1976  for (unsigned I = 0; I != initExprs.size(); ++I) {
1977  if (initExprs[I]->isTypeDependent())
1978  ExprBits.TypeDependent = true;
1979  if (initExprs[I]->isValueDependent())
1980  ExprBits.ValueDependent = true;
1981  if (initExprs[I]->isInstantiationDependent())
1982  ExprBits.InstantiationDependent = true;
1983  if (initExprs[I]->containsUnexpandedParameterPack())
1984  ExprBits.ContainsUnexpandedParameterPack = true;
1985  }
1986 
1987  InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end());
1988 }
1989 
1990 void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) {
1991  if (NumInits > InitExprs.size())
1992  InitExprs.reserve(C, NumInits);
1993 }
1994 
1995 void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) {
1996  InitExprs.resize(C, NumInits, nullptr);
1997 }
1998 
1999 Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) {
2000  if (Init >= InitExprs.size()) {
2001  InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr);
2002  setInit(Init, expr);
2003  return nullptr;
2004  }
2005 
2006  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
2007  setInit(Init, expr);
2008  return Result;
2009 }
2010 
2012  assert(!hasArrayFiller() && "Filler already set!");
2013  ArrayFillerOrUnionFieldInit = filler;
2014  // Fill out any "holes" in the array due to designated initializers.
2015  Expr **inits = getInits();
2016  for (unsigned i = 0, e = getNumInits(); i != e; ++i)
2017  if (inits[i] == nullptr)
2018  inits[i] = filler;
2019 }
2020 
2022  if (getNumInits() != 1)
2023  return false;
2024  const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
2025  if (!AT || !AT->getElementType()->isIntegerType())
2026  return false;
2027  // It is possible for getInit() to return null.
2028  const Expr *Init = getInit(0);
2029  if (!Init)
2030  return false;
2031  Init = Init->IgnoreParens();
2032  return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
2033 }
2034 
2036  assert(isSemanticForm() && "syntactic form never semantically transparent");
2037 
2038  // A glvalue InitListExpr is always just sugar.
2039  if (isGLValue()) {
2040  assert(getNumInits() == 1 && "multiple inits in glvalue init list");
2041  return true;
2042  }
2043 
2044  // Otherwise, we're sugar if and only if we have exactly one initializer that
2045  // is of the same type.
2046  if (getNumInits() != 1 || !getInit(0))
2047  return false;
2048 
2049  // Don't confuse aggregate initialization of a struct X { X &x; }; with a
2050  // transparent struct copy.
2051  if (!getInit(0)->isRValue() && getType()->isRecordType())
2052  return false;
2053 
2054  return getType().getCanonicalType() ==
2056 }
2057 
2059  assert(isSyntacticForm() && "only test syntactic form as zero initializer");
2060 
2061  if (LangOpts.CPlusPlus || getNumInits() != 1) {
2062  return false;
2063  }
2064 
2065  const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0));
2066  return Lit && Lit->getValue() == 0;
2067 }
2068 
2070  if (InitListExpr *SyntacticForm = getSyntacticForm())
2071  return SyntacticForm->getBeginLoc();
2072  SourceLocation Beg = LBraceLoc;
2073  if (Beg.isInvalid()) {
2074  // Find the first non-null initializer.
2075  for (InitExprsTy::const_iterator I = InitExprs.begin(),
2076  E = InitExprs.end();
2077  I != E; ++I) {
2078  if (Stmt *S = *I) {
2079  Beg = S->getBeginLoc();
2080  break;
2081  }
2082  }
2083  }
2084  return Beg;
2085 }
2086 
2088  if (InitListExpr *SyntacticForm = getSyntacticForm())
2089  return SyntacticForm->getEndLoc();
2090  SourceLocation End = RBraceLoc;
2091  if (End.isInvalid()) {
2092  // Find the first non-null initializer from the end.
2093  for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
2094  E = InitExprs.rend();
2095  I != E; ++I) {
2096  if (Stmt *S = *I) {
2097  End = S->getEndLoc();
2098  break;
2099  }
2100  }
2101  }
2102  return End;
2103 }
2104 
2105 /// getFunctionType - Return the underlying function type for this block.
2106 ///
2108  // The block pointer is never sugared, but the function type might be.
2109  return cast<BlockPointerType>(getType())
2110  ->getPointeeType()->castAs<FunctionProtoType>();
2111 }
2112 
2114  return TheBlock->getCaretLocation();
2115 }
2116 const Stmt *BlockExpr::getBody() const {
2117  return TheBlock->getBody();
2118 }
2120  return TheBlock->getBody();
2121 }
2122 
2123 
2124 //===----------------------------------------------------------------------===//
2125 // Generic Expression Routines
2126 //===----------------------------------------------------------------------===//
2127 
2128 /// isUnusedResultAWarning - Return true if this immediate expression should
2129 /// be warned about if the result is unused. If so, fill in Loc and Ranges
2130 /// with location to warn on and the source range[s] to report with the
2131 /// warning.
2133  SourceRange &R1, SourceRange &R2,
2134  ASTContext &Ctx) const {
2135  // Don't warn if the expr is type dependent. The type could end up
2136  // instantiating to void.
2137  if (isTypeDependent())
2138  return false;
2139 
2140  switch (getStmtClass()) {
2141  default:
2142  if (getType()->isVoidType())
2143  return false;
2144  WarnE = this;
2145  Loc = getExprLoc();
2146  R1 = getSourceRange();
2147  return true;
2148  case ParenExprClass:
2149  return cast<ParenExpr>(this)->getSubExpr()->
2150  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2151  case GenericSelectionExprClass:
2152  return cast<GenericSelectionExpr>(this)->getResultExpr()->
2153  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2154  case CoawaitExprClass:
2155  case CoyieldExprClass:
2156  return cast<CoroutineSuspendExpr>(this)->getResumeExpr()->
2157  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2158  case ChooseExprClass:
2159  return cast<ChooseExpr>(this)->getChosenSubExpr()->
2160  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2161  case UnaryOperatorClass: {
2162  const UnaryOperator *UO = cast<UnaryOperator>(this);
2163 
2164  switch (UO->getOpcode()) {
2165  case UO_Plus:
2166  case UO_Minus:
2167  case UO_AddrOf:
2168  case UO_Not:
2169  case UO_LNot:
2170  case UO_Deref:
2171  break;
2172  case UO_Coawait:
2173  // This is just the 'operator co_await' call inside the guts of a
2174  // dependent co_await call.
2175  case UO_PostInc:
2176  case UO_PostDec:
2177  case UO_PreInc:
2178  case UO_PreDec: // ++/--
2179  return false; // Not a warning.
2180  case UO_Real:
2181  case UO_Imag:
2182  // accessing a piece of a volatile complex is a side-effect.
2183  if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
2184  .isVolatileQualified())
2185  return false;
2186  break;
2187  case UO_Extension:
2188  return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2189  }
2190  WarnE = this;
2191  Loc = UO->getOperatorLoc();
2192  R1 = UO->getSubExpr()->getSourceRange();
2193  return true;
2194  }
2195  case BinaryOperatorClass: {
2196  const BinaryOperator *BO = cast<BinaryOperator>(this);
2197  switch (BO->getOpcode()) {
2198  default:
2199  break;
2200  // Consider the RHS of comma for side effects. LHS was checked by
2201  // Sema::CheckCommaOperands.
2202  case BO_Comma:
2203  // ((foo = <blah>), 0) is an idiom for hiding the result (and
2204  // lvalue-ness) of an assignment written in a macro.
2205  if (IntegerLiteral *IE =
2206  dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
2207  if (IE->getValue() == 0)
2208  return false;
2209  return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2210  // Consider '||', '&&' to have side effects if the LHS or RHS does.
2211  case BO_LAnd:
2212  case BO_LOr:
2213  if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) ||
2214  !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
2215  return false;
2216  break;
2217  }
2218  if (BO->isAssignmentOp())
2219  return false;
2220  WarnE = this;
2221  Loc = BO->getOperatorLoc();
2222  R1 = BO->getLHS()->getSourceRange();
2223  R2 = BO->getRHS()->getSourceRange();
2224  return true;
2225  }
2226  case CompoundAssignOperatorClass:
2227  case VAArgExprClass:
2228  case AtomicExprClass:
2229  return false;
2230 
2231  case ConditionalOperatorClass: {
2232  // If only one of the LHS or RHS is a warning, the operator might
2233  // be being used for control flow. Only warn if both the LHS and
2234  // RHS are warnings.
2235  const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
2236  if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
2237  return false;
2238  if (!Exp->getLHS())
2239  return true;
2240  return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2241  }
2242 
2243  case MemberExprClass:
2244  WarnE = this;
2245  Loc = cast<MemberExpr>(this)->getMemberLoc();
2246  R1 = SourceRange(Loc, Loc);
2247  R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
2248  return true;
2249 
2250  case ArraySubscriptExprClass:
2251  WarnE = this;
2252  Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
2253  R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
2254  R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
2255  return true;
2256 
2257  case CXXOperatorCallExprClass: {
2258  // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator
2259  // overloads as there is no reasonable way to define these such that they
2260  // have non-trivial, desirable side-effects. See the -Wunused-comparison
2261  // warning: operators == and != are commonly typo'ed, and so warning on them
2262  // provides additional value as well. If this list is updated,
2263  // DiagnoseUnusedComparison should be as well.
2264  const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this);
2265  switch (Op->getOperator()) {
2266  default:
2267  break;
2268  case OO_EqualEqual:
2269  case OO_ExclaimEqual:
2270  case OO_Less:
2271  case OO_Greater:
2272  case OO_GreaterEqual:
2273  case OO_LessEqual:
2274  if (Op->getCallReturnType(Ctx)->isReferenceType() ||
2275  Op->getCallReturnType(Ctx)->isVoidType())
2276  break;
2277  WarnE = this;
2278  Loc = Op->getOperatorLoc();
2279  R1 = Op->getSourceRange();
2280  return true;
2281  }
2282 
2283  // Fallthrough for generic call handling.
2284  LLVM_FALLTHROUGH;
2285  }
2286  case CallExprClass:
2287  case CXXMemberCallExprClass:
2288  case UserDefinedLiteralClass: {
2289  // If this is a direct call, get the callee.
2290  const CallExpr *CE = cast<CallExpr>(this);
2291  if (const Decl *FD = CE->getCalleeDecl()) {
2292  const FunctionDecl *Func = dyn_cast<FunctionDecl>(FD);
2293  bool HasWarnUnusedResultAttr = Func ? Func->hasUnusedResultAttr()
2294  : FD->hasAttr<WarnUnusedResultAttr>();
2295 
2296  // If the callee has attribute pure, const, or warn_unused_result, warn
2297  // about it. void foo() { strlen("bar"); } should warn.
2298  //
2299  // Note: If new cases are added here, DiagnoseUnusedExprResult should be
2300  // updated to match for QoI.
2301  if (HasWarnUnusedResultAttr ||
2302  FD->hasAttr<PureAttr>() || FD->hasAttr<ConstAttr>()) {
2303  WarnE = this;
2304  Loc = CE->getCallee()->getBeginLoc();
2305  R1 = CE->getCallee()->getSourceRange();
2306 
2307  if (unsigned NumArgs = CE->getNumArgs())
2308  R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2309  CE->getArg(NumArgs - 1)->getEndLoc());
2310  return true;
2311  }
2312  }
2313  return false;
2314  }
2315 
2316  // If we don't know precisely what we're looking at, let's not warn.
2317  case UnresolvedLookupExprClass:
2318  case CXXUnresolvedConstructExprClass:
2319  return false;
2320 
2321  case CXXTemporaryObjectExprClass:
2322  case CXXConstructExprClass: {
2323  if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) {
2324  if (Type->hasAttr<WarnUnusedAttr>()) {
2325  WarnE = this;
2326  Loc = getBeginLoc();
2327  R1 = getSourceRange();
2328  return true;
2329  }
2330  }
2331  return false;
2332  }
2333 
2334  case ObjCMessageExprClass: {
2335  const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
2336  if (Ctx.getLangOpts().ObjCAutoRefCount &&
2337  ME->isInstanceMessage() &&
2338  !ME->getType()->isVoidType() &&
2339  ME->getMethodFamily() == OMF_init) {
2340  WarnE = this;
2341  Loc = getExprLoc();
2342  R1 = ME->getSourceRange();
2343  return true;
2344  }
2345 
2346  if (const ObjCMethodDecl *MD = ME->getMethodDecl())
2347  if (MD->hasAttr<WarnUnusedResultAttr>()) {
2348  WarnE = this;
2349  Loc = getExprLoc();
2350  return true;
2351  }
2352 
2353  return false;
2354  }
2355 
2356  case ObjCPropertyRefExprClass:
2357  WarnE = this;
2358  Loc = getExprLoc();
2359  R1 = getSourceRange();
2360  return true;
2361 
2362  case PseudoObjectExprClass: {
2363  const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
2364 
2365  // Only complain about things that have the form of a getter.
2366  if (isa<UnaryOperator>(PO->getSyntacticForm()) ||
2367  isa<BinaryOperator>(PO->getSyntacticForm()))
2368  return false;
2369 
2370  WarnE = this;
2371  Loc = getExprLoc();
2372  R1 = getSourceRange();
2373  return true;
2374  }
2375 
2376  case StmtExprClass: {
2377  // Statement exprs don't logically have side effects themselves, but are
2378  // sometimes used in macros in ways that give them a type that is unused.
2379  // For example ({ blah; foo(); }) will end up with a type if foo has a type.
2380  // however, if the result of the stmt expr is dead, we don't want to emit a
2381  // warning.
2382  const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
2383  if (!CS->body_empty()) {
2384  if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
2385  return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2386  if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back()))
2387  if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt()))
2388  return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2389  }
2390 
2391  if (getType()->isVoidType())
2392  return false;
2393  WarnE = this;
2394  Loc = cast<StmtExpr>(this)->getLParenLoc();
2395  R1 = getSourceRange();
2396  return true;
2397  }
2398  case CXXFunctionalCastExprClass:
2399  case CStyleCastExprClass: {
2400  // Ignore an explicit cast to void unless the operand is a non-trivial
2401  // volatile lvalue.
2402  const CastExpr *CE = cast<CastExpr>(this);
2403  if (CE->getCastKind() == CK_ToVoid) {
2404  if (CE->getSubExpr()->isGLValue() &&
2405  CE->getSubExpr()->getType().isVolatileQualified()) {
2406  const DeclRefExpr *DRE =
2407  dyn_cast<DeclRefExpr>(CE->getSubExpr()->IgnoreParens());
2408  if (!(DRE && isa<VarDecl>(DRE->getDecl()) &&
2409  cast<VarDecl>(DRE->getDecl())->hasLocalStorage()) &&
2410  !isa<CallExpr>(CE->getSubExpr()->IgnoreParens())) {
2411  return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc,
2412  R1, R2, Ctx);
2413  }
2414  }
2415  return false;
2416  }
2417 
2418  // If this is a cast to a constructor conversion, check the operand.
2419  // Otherwise, the result of the cast is unused.
2420  if (CE->getCastKind() == CK_ConstructorConversion)
2421  return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2422 
2423  WarnE = this;
2424  if (const CXXFunctionalCastExpr *CXXCE =
2425  dyn_cast<CXXFunctionalCastExpr>(this)) {
2426  Loc = CXXCE->getBeginLoc();
2427  R1 = CXXCE->getSubExpr()->getSourceRange();
2428  } else {
2429  const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this);
2430  Loc = CStyleCE->getLParenLoc();
2431  R1 = CStyleCE->getSubExpr()->getSourceRange();
2432  }
2433  return true;
2434  }
2435  case ImplicitCastExprClass: {
2436  const CastExpr *ICE = cast<ImplicitCastExpr>(this);
2437 
2438  // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect.
2439  if (ICE->getCastKind() == CK_LValueToRValue &&
2441  return false;
2442 
2443  return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2444  }
2445  case CXXDefaultArgExprClass:
2446  return (cast<CXXDefaultArgExpr>(this)
2447  ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
2448  case CXXDefaultInitExprClass:
2449  return (cast<CXXDefaultInitExpr>(this)
2450  ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
2451 
2452  case CXXNewExprClass:
2453  // FIXME: In theory, there might be new expressions that don't have side
2454  // effects (e.g. a placement new with an uninitialized POD).
2455  case CXXDeleteExprClass:
2456  return false;
2457  case MaterializeTemporaryExprClass:
2458  return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr()
2459  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2460  case CXXBindTemporaryExprClass:
2461  return cast<CXXBindTemporaryExpr>(this)->getSubExpr()
2462  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2463  case ExprWithCleanupsClass:
2464  return cast<ExprWithCleanups>(this)->getSubExpr()
2465  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2466  }
2467 }
2468 
2469 /// isOBJCGCCandidate - Check if an expression is objc gc'able.
2470 /// returns true, if it is; false otherwise.
2472  const Expr *E = IgnoreParens();
2473  switch (E->getStmtClass()) {
2474  default:
2475  return false;
2476  case ObjCIvarRefExprClass:
2477  return true;
2478  case Expr::UnaryOperatorClass:
2479  return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2480  case ImplicitCastExprClass:
2481  return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2482  case MaterializeTemporaryExprClass:
2483  return cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr()
2484  ->isOBJCGCCandidate(Ctx);
2485  case CStyleCastExprClass:
2486  return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2487  case DeclRefExprClass: {
2488  const Decl *D = cast<DeclRefExpr>(E)->getDecl();
2489 
2490  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2491  if (VD->hasGlobalStorage())
2492  return true;
2493  QualType T = VD->getType();
2494  // dereferencing to a pointer is always a gc'able candidate,
2495  // unless it is __weak.
2496  return T->isPointerType() &&
2497  (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak);
2498  }
2499  return false;
2500  }
2501  case MemberExprClass: {
2502  const MemberExpr *M = cast<MemberExpr>(E);
2503  return M->getBase()->isOBJCGCCandidate(Ctx);
2504  }
2505  case ArraySubscriptExprClass:
2506  return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx);
2507  }
2508 }
2509 
2511  if (isTypeDependent())
2512  return false;
2513  return ClassifyLValue(Ctx) == Expr::LV_MemberFunction;
2514 }
2515 
2517  assert(expr->hasPlaceholderType(BuiltinType::BoundMember));
2518 
2519  // Bound member expressions are always one of these possibilities:
2520  // x->m x.m x->*y x.*y
2521  // (possibly parenthesized)
2522 
2523  expr = expr->IgnoreParens();
2524  if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) {
2525  assert(isa<CXXMethodDecl>(mem->getMemberDecl()));
2526  return mem->getMemberDecl()->getType();
2527  }
2528 
2529  if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) {
2530  QualType type = op->getRHS()->getType()->castAs<MemberPointerType>()
2531  ->getPointeeType();
2532  assert(type->isFunctionType());
2533  return type;
2534  }
2535 
2536  assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr));
2537  return QualType();
2538 }
2539 
2541  Expr* E = this;
2542  while (true) {
2543  if (ParenExpr* P = dyn_cast<ParenExpr>(E)) {
2544  E = P->getSubExpr();
2545  continue;
2546  }
2547  if (UnaryOperator* P = dyn_cast<UnaryOperator>(E)) {
2548  if (P->getOpcode() == UO_Extension) {
2549  E = P->getSubExpr();
2550  continue;
2551  }
2552  }
2553  if (GenericSelectionExpr* P = dyn_cast<GenericSelectionExpr>(E)) {
2554  if (!P->isResultDependent()) {
2555  E = P->getResultExpr();
2556  continue;
2557  }
2558  }
2559  if (ChooseExpr* P = dyn_cast<ChooseExpr>(E)) {
2560  if (!P->isConditionDependent()) {
2561  E = P->getChosenSubExpr();
2562  continue;
2563  }
2564  }
2565  return E;
2566  }
2567 }
2568 
2569 /// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr
2570 /// or CastExprs or ImplicitCastExprs, returning their operand.
2572  Expr *E = this;
2573  while (true) {
2574  E = E->IgnoreParens();
2575  if (CastExpr *P = dyn_cast<CastExpr>(E)) {
2576  E = P->getSubExpr();
2577  continue;
2578  }
2579  if (MaterializeTemporaryExpr *Materialize
2580  = dyn_cast<MaterializeTemporaryExpr>(E)) {
2581  E = Materialize->GetTemporaryExpr();
2582  continue;
2583  }
2585  = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
2586  E = NTTP->getReplacement();
2587  continue;
2588  }
2589  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
2590  E = CE->getSubExpr();
2591  continue;
2592  }
2593  return E;
2594  }
2595 }
2596 
2598  Expr *E = this;
2599  while (true) {
2600  if (CastExpr *P = dyn_cast<CastExpr>(E)) {
2601  E = P->getSubExpr();
2602  continue;
2603  }
2604  if (MaterializeTemporaryExpr *Materialize
2605  = dyn_cast<MaterializeTemporaryExpr>(E)) {
2606  E = Materialize->GetTemporaryExpr();
2607  continue;
2608  }
2610  = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
2611  E = NTTP->getReplacement();
2612  continue;
2613  }
2614  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
2615  E = CE->getSubExpr();
2616  continue;
2617  }
2618  return E;
2619  }
2620 }
2621 
2622 /// IgnoreParenLValueCasts - Ignore parentheses and lvalue-to-rvalue
2623 /// casts. This is intended purely as a temporary workaround for code
2624 /// that hasn't yet been rewritten to do the right thing about those
2625 /// casts, and may disappear along with the last internal use.
2627  Expr *E = this;
2628  while (true) {
2629  E = E->IgnoreParens();
2630  if (CastExpr *P = dyn_cast<CastExpr>(E)) {
2631  if (P->getCastKind() == CK_LValueToRValue) {
2632  E = P->getSubExpr();
2633  continue;
2634  }
2635  } else if (MaterializeTemporaryExpr *Materialize
2636  = dyn_cast<MaterializeTemporaryExpr>(E)) {
2637  E = Materialize->GetTemporaryExpr();
2638  continue;
2639  } else if (SubstNonTypeTemplateParmExpr *NTTP
2640  = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
2641  E = NTTP->getReplacement();
2642  continue;
2643  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
2644  E = CE->getSubExpr();
2645  continue;
2646  }
2647  break;
2648  }
2649  return E;
2650 }
2651 
2653  Expr *E = this;
2654  while (true) {
2655  E = E->IgnoreParens();
2656  if (CastExpr *CE = dyn_cast<CastExpr>(E)) {
2657  if (CE->getCastKind() == CK_DerivedToBase ||
2658  CE->getCastKind() == CK_UncheckedDerivedToBase ||
2659  CE->getCastKind() == CK_NoOp) {
2660  E = CE->getSubExpr();
2661  continue;
2662  }
2663  }
2664 
2665  return E;
2666  }
2667 }
2668 
2670  Expr *E = this;
2671  while (true) {
2672  E = E->IgnoreParens();
2673  if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E)) {
2674  E = P->getSubExpr();
2675  continue;
2676  }
2677  if (MaterializeTemporaryExpr *Materialize
2678  = dyn_cast<MaterializeTemporaryExpr>(E)) {
2679  E = Materialize->GetTemporaryExpr();
2680  continue;
2681  }
2683  = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
2684  E = NTTP->getReplacement();
2685  continue;
2686  }
2687  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(E)) {
2688  E = CE->getSubExpr();
2689  continue;
2690  }
2691  return E;
2692  }
2693 }
2694 
2696  if (CXXMemberCallExpr *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
2697  if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl()))
2698  return MCE->getImplicitObjectArgument();
2699  }
2700  return this;
2701 }
2702 
2703 /// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
2704 /// value (including ptr->int casts of the same size). Strip off any
2705 /// ParenExpr or CastExprs, returning their operand.
2707  Expr *E = this;
2708  while (true) {
2709  E = E->IgnoreParens();
2710 
2711  if (CastExpr *P = dyn_cast<CastExpr>(E)) {
2712  // We ignore integer <-> casts that are of the same width, ptr<->ptr and
2713  // ptr<->int casts of the same width. We also ignore all identity casts.
2714  Expr *SE = P->getSubExpr();
2715 
2716  if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) {
2717  E = SE;
2718  continue;
2719  }
2720 
2721  if ((E->getType()->isPointerType() ||
2722  E->getType()->isIntegralType(Ctx)) &&
2723  (SE->getType()->isPointerType() ||
2724  SE->getType()->isIntegralType(Ctx)) &&
2725  Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) {
2726  E = SE;
2727  continue;
2728  }
2729  }
2730 
2732  = dyn_cast<SubstNonTypeTemplateParmExpr>(E)) {
2733  E = NTTP->getReplacement();
2734  continue;
2735  }
2736 
2737  return E;
2738  }
2739 }
2740 
2742  const Expr *E = this;
2743  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
2744  E = M->GetTemporaryExpr();
2745 
2746  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
2747  E = ICE->getSubExprAsWritten();
2748 
2749  return isa<CXXDefaultArgExpr>(E);
2750 }
2751 
2752 /// Skip over any no-op casts and any temporary-binding
2753 /// expressions.
2755  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
2756  E = M->GetTemporaryExpr();
2757 
2758  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2759  if (ICE->getCastKind() == CK_NoOp)
2760  E = ICE->getSubExpr();
2761  else
2762  break;
2763  }
2764 
2765  while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
2766  E = BE->getSubExpr();
2767 
2768  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2769  if (ICE->getCastKind() == CK_NoOp)
2770  E = ICE->getSubExpr();
2771  else
2772  break;
2773  }
2774 
2775  return E->IgnoreParens();
2776 }
2777 
2778 /// isTemporaryObject - Determines if this expression produces a
2779 /// temporary of the given class type.
2780 bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const {
2781  if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy)))
2782  return false;
2783 
2785 
2786  // Temporaries are by definition pr-values of class type.
2787  if (!E->Classify(C).isPRValue()) {
2788  // In this context, property reference is a message call and is pr-value.
2789  if (!isa<ObjCPropertyRefExpr>(E))
2790  return false;
2791  }
2792 
2793  // Black-list a few cases which yield pr-values of class type that don't
2794  // refer to temporaries of that type:
2795 
2796  // - implicit derived-to-base conversions
2797  if (isa<ImplicitCastExpr>(E)) {
2798  switch (cast<ImplicitCastExpr>(E)->getCastKind()) {
2799  case CK_DerivedToBase:
2800  case CK_UncheckedDerivedToBase:
2801  return false;
2802  default:
2803  break;
2804  }
2805  }
2806 
2807  // - member expressions (all)
2808  if (isa<MemberExpr>(E))
2809  return false;
2810 
2811  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
2812  if (BO->isPtrMemOp())
2813  return false;
2814 
2815  // - opaque values (all)
2816  if (isa<OpaqueValueExpr>(E))
2817  return false;
2818 
2819  return true;
2820 }
2821 
2823  const Expr *E = this;
2824 
2825  // Strip away parentheses and casts we don't care about.
2826  while (true) {
2827  if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) {
2828  E = Paren->getSubExpr();
2829  continue;
2830  }
2831 
2832  if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2833  if (ICE->getCastKind() == CK_NoOp ||
2834  ICE->getCastKind() == CK_LValueToRValue ||
2835  ICE->getCastKind() == CK_DerivedToBase ||
2836  ICE->getCastKind() == CK_UncheckedDerivedToBase) {
2837  E = ICE->getSubExpr();
2838  continue;
2839  }
2840  }
2841 
2842  if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) {
2843  if (UnOp->getOpcode() == UO_Extension) {
2844  E = UnOp->getSubExpr();
2845  continue;
2846  }
2847  }
2848 
2849  if (const MaterializeTemporaryExpr *M
2850  = dyn_cast<MaterializeTemporaryExpr>(E)) {
2851  E = M->GetTemporaryExpr();
2852  continue;
2853  }
2854 
2855  break;
2856  }
2857 
2858  if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E))
2859  return This->isImplicit();
2860 
2861  return false;
2862 }
2863 
2864 /// hasAnyTypeDependentArguments - Determines if any of the expressions
2865 /// in Exprs is type-dependent.
2867  for (unsigned I = 0; I < Exprs.size(); ++I)
2868  if (Exprs[I]->isTypeDependent())
2869  return true;
2870 
2871  return false;
2872 }
2873 
2874 bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
2875  const Expr **Culprit) const {
2876  // This function is attempting whether an expression is an initializer
2877  // which can be evaluated at compile-time. It very closely parallels
2878  // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it
2879  // will lead to unexpected results. Like ConstExprEmitter, it falls back
2880  // to isEvaluatable most of the time.
2881  //
2882  // If we ever capture reference-binding directly in the AST, we can
2883  // kill the second parameter.
2884 
2885  if (IsForRef) {
2887  if (EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects)
2888  return true;
2889  if (Culprit)
2890  *Culprit = this;
2891  return false;
2892  }
2893 
2894  switch (getStmtClass()) {
2895  default: break;
2896  case StringLiteralClass:
2897  case ObjCEncodeExprClass:
2898  return true;
2899  case CXXTemporaryObjectExprClass:
2900  case CXXConstructExprClass: {
2901  const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
2902 
2903  if (CE->getConstructor()->isTrivial() &&
2905  // Trivial default constructor
2906  if (!CE->getNumArgs()) return true;
2907 
2908  // Trivial copy constructor
2909  assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument");
2910  return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit);
2911  }
2912 
2913  break;
2914  }
2915  case CompoundLiteralExprClass: {
2916  // This handles gcc's extension that allows global initializers like
2917  // "struct x {int x;} x = (struct x) {};".
2918  // FIXME: This accepts other cases it shouldn't!
2919  const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
2920  return Exp->isConstantInitializer(Ctx, false, Culprit);
2921  }
2922  case DesignatedInitUpdateExprClass: {
2923  const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this);
2924  return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) &&
2925  DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit);
2926  }
2927  case InitListExprClass: {
2928  const InitListExpr *ILE = cast<InitListExpr>(this);
2929  if (ILE->getType()->isArrayType()) {
2930  unsigned numInits = ILE->getNumInits();
2931  for (unsigned i = 0; i < numInits; i++) {
2932  if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit))
2933  return false;
2934  }
2935  return true;
2936  }
2937 
2938  if (ILE->getType()->isRecordType()) {
2939  unsigned ElementNo = 0;
2940  RecordDecl *RD = ILE->getType()->getAs<RecordType>()->getDecl();
2941  for (const auto *Field : RD->fields()) {
2942  // If this is a union, skip all the fields that aren't being initialized.
2943  if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field)
2944  continue;
2945 
2946  // Don't emit anonymous bitfields, they just affect layout.
2947  if (Field->isUnnamedBitfield())
2948  continue;
2949 
2950  if (ElementNo < ILE->getNumInits()) {
2951  const Expr *Elt = ILE->getInit(ElementNo++);
2952  if (Field->isBitField()) {
2953  // Bitfields have to evaluate to an integer.
2954  llvm::APSInt ResultTmp;
2955  if (!Elt->EvaluateAsInt(ResultTmp, Ctx)) {
2956  if (Culprit)
2957  *Culprit = Elt;
2958  return false;
2959  }
2960  } else {
2961  bool RefType = Field->getType()->isReferenceType();
2962  if (!Elt->isConstantInitializer(Ctx, RefType, Culprit))
2963  return false;
2964  }
2965  }
2966  }
2967  return true;
2968  }
2969 
2970  break;
2971  }
2972  case ImplicitValueInitExprClass:
2973  case NoInitExprClass:
2974  return true;
2975  case ParenExprClass:
2976  return cast<ParenExpr>(this)->getSubExpr()
2977  ->isConstantInitializer(Ctx, IsForRef, Culprit);
2978  case GenericSelectionExprClass:
2979  return cast<GenericSelectionExpr>(this)->getResultExpr()
2980  ->isConstantInitializer(Ctx, IsForRef, Culprit);
2981  case ChooseExprClass:
2982  if (cast<ChooseExpr>(this)->isConditionDependent()) {
2983  if (Culprit)
2984  *Culprit = this;
2985  return false;
2986  }
2987  return cast<ChooseExpr>(this)->getChosenSubExpr()
2988  ->isConstantInitializer(Ctx, IsForRef, Culprit);
2989  case UnaryOperatorClass: {
2990  const UnaryOperator* Exp = cast<UnaryOperator>(this);
2991  if (Exp->getOpcode() == UO_Extension)
2992  return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
2993  break;
2994  }
2995  case CXXFunctionalCastExprClass:
2996  case CXXStaticCastExprClass:
2997  case ImplicitCastExprClass:
2998  case CStyleCastExprClass:
2999  case ObjCBridgedCastExprClass:
3000  case CXXDynamicCastExprClass:
3001  case CXXReinterpretCastExprClass:
3002  case CXXConstCastExprClass: {
3003  const CastExpr *CE = cast<CastExpr>(this);
3004 
3005  // Handle misc casts we want to ignore.
3006  if (CE->getCastKind() == CK_NoOp ||
3007  CE->getCastKind() == CK_LValueToRValue ||
3008  CE->getCastKind() == CK_ToUnion ||
3009  CE->getCastKind() == CK_ConstructorConversion ||
3010  CE->getCastKind() == CK_NonAtomicToAtomic ||
3011  CE->getCastKind() == CK_AtomicToNonAtomic ||
3012  CE->getCastKind() == CK_IntToOCLSampler)
3013  return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3014 
3015  break;
3016  }
3017  case MaterializeTemporaryExprClass:
3018  return cast<MaterializeTemporaryExpr>(this)->GetTemporaryExpr()
3019  ->isConstantInitializer(Ctx, false, Culprit);
3020 
3021  case SubstNonTypeTemplateParmExprClass:
3022  return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement()
3023  ->isConstantInitializer(Ctx, false, Culprit);
3024  case CXXDefaultArgExprClass:
3025  return cast<CXXDefaultArgExpr>(this)->getExpr()
3026  ->isConstantInitializer(Ctx, false, Culprit);
3027  case CXXDefaultInitExprClass:
3028  return cast<CXXDefaultInitExpr>(this)->getExpr()
3029  ->isConstantInitializer(Ctx, false, Culprit);
3030  }
3031  // Allow certain forms of UB in constant initializers: signed integer
3032  // overflow and floating-point division by zero. We'll give a warning on
3033  // these, but they're common enough that we have to accept them.
3035  return true;
3036  if (Culprit)
3037  *Culprit = this;
3038  return false;
3039 }
3040 
3042  const FunctionDecl* FD = getDirectCallee();
3043  if (!FD || (FD->getBuiltinID() != Builtin::BI__assume &&
3044  FD->getBuiltinID() != Builtin::BI__builtin_assume))
3045  return false;
3046 
3047  const Expr* Arg = getArg(0);
3048  bool ArgVal;
3049  return !Arg->isValueDependent() &&
3050  Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal;
3051 }
3052 
3053 namespace {
3054  /// Look for any side effects within a Stmt.
3055  class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> {
3057  const bool IncludePossibleEffects;
3058  bool HasSideEffects;
3059 
3060  public:
3061  explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible)
3062  : Inherited(Context),
3063  IncludePossibleEffects(IncludePossible), HasSideEffects(false) { }
3064 
3065  bool hasSideEffects() const { return HasSideEffects; }
3066 
3067  void VisitExpr(const Expr *E) {
3068  if (!HasSideEffects &&
3069  E->HasSideEffects(Context, IncludePossibleEffects))
3070  HasSideEffects = true;
3071  }
3072  };
3073 }
3074 
3076  bool IncludePossibleEffects) const {
3077  // In circumstances where we care about definite side effects instead of
3078  // potential side effects, we want to ignore expressions that are part of a
3079  // macro expansion as a potential side effect.
3080  if (!IncludePossibleEffects && getExprLoc().isMacroID())
3081  return false;
3082 
3084  return IncludePossibleEffects;
3085 
3086  switch (getStmtClass()) {
3087  case NoStmtClass:
3088  #define ABSTRACT_STMT(Type)
3089  #define STMT(Type, Base) case Type##Class:
3090  #define EXPR(Type, Base)
3091  #include "clang/AST/StmtNodes.inc"
3092  llvm_unreachable("unexpected Expr kind");
3093 
3094  case DependentScopeDeclRefExprClass:
3095  case CXXUnresolvedConstructExprClass:
3096  case CXXDependentScopeMemberExprClass:
3097  case UnresolvedLookupExprClass:
3098  case UnresolvedMemberExprClass:
3099  case PackExpansionExprClass:
3100  case SubstNonTypeTemplateParmPackExprClass:
3101  case FunctionParmPackExprClass:
3102  case TypoExprClass:
3103  case CXXFoldExprClass:
3104  llvm_unreachable("shouldn't see dependent / unresolved nodes here");
3105 
3106  case DeclRefExprClass:
3107  case ObjCIvarRefExprClass:
3108  case PredefinedExprClass:
3109  case IntegerLiteralClass:
3110  case FixedPointLiteralClass:
3111  case FloatingLiteralClass:
3112  case ImaginaryLiteralClass:
3113  case StringLiteralClass:
3114  case CharacterLiteralClass:
3115  case OffsetOfExprClass:
3116  case ImplicitValueInitExprClass:
3117  case UnaryExprOrTypeTraitExprClass:
3118  case AddrLabelExprClass:
3119  case GNUNullExprClass:
3120  case ArrayInitIndexExprClass:
3121  case NoInitExprClass:
3122  case CXXBoolLiteralExprClass:
3123  case CXXNullPtrLiteralExprClass:
3124  case CXXThisExprClass:
3125  case CXXScalarValueInitExprClass:
3126  case TypeTraitExprClass:
3127  case ArrayTypeTraitExprClass:
3128  case ExpressionTraitExprClass:
3129  case CXXNoexceptExprClass:
3130  case SizeOfPackExprClass:
3131  case ObjCStringLiteralClass:
3132  case ObjCEncodeExprClass:
3133  case ObjCBoolLiteralExprClass:
3134  case ObjCAvailabilityCheckExprClass:
3135  case CXXUuidofExprClass:
3136  case OpaqueValueExprClass:
3137  // These never have a side-effect.
3138  return false;
3139 
3140  case ConstantExprClass:
3141  // FIXME: Move this into the "return false;" block above.
3142  return cast<ConstantExpr>(this)->getSubExpr()->HasSideEffects(
3143  Ctx, IncludePossibleEffects);
3144 
3145  case CallExprClass:
3146  case CXXOperatorCallExprClass:
3147  case CXXMemberCallExprClass:
3148  case CUDAKernelCallExprClass:
3149  case UserDefinedLiteralClass: {
3150  // We don't know a call definitely has side effects, except for calls
3151  // to pure/const functions that definitely don't.
3152  // If the call itself is considered side-effect free, check the operands.
3153  const Decl *FD = cast<CallExpr>(this)->getCalleeDecl();
3154  bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>());
3155  if (IsPure || !IncludePossibleEffects)
3156  break;
3157  return true;
3158  }
3159 
3160  case BlockExprClass:
3161  case CXXBindTemporaryExprClass:
3162  if (!IncludePossibleEffects)
3163  break;
3164  return true;
3165 
3166  case MSPropertyRefExprClass:
3167  case MSPropertySubscriptExprClass:
3168  case CompoundAssignOperatorClass:
3169  case VAArgExprClass:
3170  case AtomicExprClass:
3171  case CXXThrowExprClass:
3172  case CXXNewExprClass:
3173  case CXXDeleteExprClass:
3174  case CoawaitExprClass:
3175  case DependentCoawaitExprClass:
3176  case CoyieldExprClass:
3177  // These always have a side-effect.
3178  return true;
3179 
3180  case StmtExprClass: {
3181  // StmtExprs have a side-effect if any substatement does.
3182  SideEffectFinder Finder(Ctx, IncludePossibleEffects);
3183  Finder.Visit(cast<StmtExpr>(this)->getSubStmt());
3184  return Finder.hasSideEffects();
3185  }
3186 
3187  case ExprWithCleanupsClass:
3188  if (IncludePossibleEffects)
3189  if (cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects())
3190  return true;
3191  break;
3192 
3193  case ParenExprClass:
3194  case ArraySubscriptExprClass:
3195  case OMPArraySectionExprClass:
3196  case MemberExprClass:
3197  case ConditionalOperatorClass:
3198  case BinaryConditionalOperatorClass:
3199  case CompoundLiteralExprClass:
3200  case ExtVectorElementExprClass:
3201  case DesignatedInitExprClass:
3202  case DesignatedInitUpdateExprClass:
3203  case ArrayInitLoopExprClass:
3204  case ParenListExprClass:
3205  case CXXPseudoDestructorExprClass:
3206  case CXXStdInitializerListExprClass:
3207  case SubstNonTypeTemplateParmExprClass:
3208  case MaterializeTemporaryExprClass:
3209  case ShuffleVectorExprClass:
3210  case ConvertVectorExprClass:
3211  case AsTypeExprClass:
3212  // These have a side-effect if any subexpression does.
3213  break;
3214 
3215  case UnaryOperatorClass:
3216  if (cast<UnaryOperator>(this)->isIncrementDecrementOp())
3217  return true;
3218  break;
3219 
3220  case BinaryOperatorClass:
3221  if (cast<BinaryOperator>(this)->isAssignmentOp())
3222  return true;
3223  break;
3224 
3225  case InitListExprClass:
3226  // FIXME: The children for an InitListExpr doesn't include the array filler.
3227  if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller())
3228  if (E->HasSideEffects(Ctx, IncludePossibleEffects))
3229  return true;
3230  break;
3231 
3232  case GenericSelectionExprClass:
3233  return cast<GenericSelectionExpr>(this)->getResultExpr()->
3234  HasSideEffects(Ctx, IncludePossibleEffects);
3235 
3236  case ChooseExprClass:
3237  return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects(
3238  Ctx, IncludePossibleEffects);
3239 
3240  case CXXDefaultArgExprClass:
3241  return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(
3242  Ctx, IncludePossibleEffects);
3243 
3244  case CXXDefaultInitExprClass: {
3245  const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField();
3246  if (const Expr *E = FD->getInClassInitializer())
3247  return E->HasSideEffects(Ctx, IncludePossibleEffects);
3248  // If we've not yet parsed the initializer, assume it has side-effects.
3249  return true;
3250  }
3251 
3252  case CXXDynamicCastExprClass: {
3253  // A dynamic_cast expression has side-effects if it can throw.
3254  const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this);
3255  if (DCE->getTypeAsWritten()->isReferenceType() &&
3256  DCE->getCastKind() == CK_Dynamic)
3257  return true;
3258  }
3259  LLVM_FALLTHROUGH;
3260  case ImplicitCastExprClass:
3261  case CStyleCastExprClass:
3262  case CXXStaticCastExprClass:
3263  case CXXReinterpretCastExprClass:
3264  case CXXConstCastExprClass:
3265  case CXXFunctionalCastExprClass: {
3266  // While volatile reads are side-effecting in both C and C++, we treat them
3267  // as having possible (not definite) side-effects. This allows idiomatic
3268  // code to behave without warning, such as sizeof(*v) for a volatile-
3269  // qualified pointer.
3270  if (!IncludePossibleEffects)
3271  break;
3272 
3273  const CastExpr *CE = cast<CastExpr>(this);
3274  if (CE->getCastKind() == CK_LValueToRValue &&
3276  return true;
3277  break;
3278  }
3279 
3280  case CXXTypeidExprClass:
3281  // typeid might throw if its subexpression is potentially-evaluated, so has
3282  // side-effects in that case whether or not its subexpression does.
3283  return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated();
3284 
3285  case CXXConstructExprClass:
3286  case CXXTemporaryObjectExprClass: {
3287  const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
3288  if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects)
3289  return true;
3290  // A trivial constructor does not add any side-effects of its own. Just look
3291  // at its arguments.
3292  break;
3293  }
3294 
3295  case CXXInheritedCtorInitExprClass: {
3296  const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this);
3297  if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects)
3298  return true;
3299  break;
3300  }
3301 
3302  case LambdaExprClass: {
3303  const LambdaExpr *LE = cast<LambdaExpr>(this);
3304  for (Expr *E : LE->capture_inits())
3305  if (E->HasSideEffects(Ctx, IncludePossibleEffects))
3306  return true;
3307  return false;
3308  }
3309 
3310  case PseudoObjectExprClass: {
3311  // Only look for side-effects in the semantic form, and look past
3312  // OpaqueValueExpr bindings in that form.
3313  const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
3315  E = PO->semantics_end();
3316  I != E; ++I) {
3317  const Expr *Subexpr = *I;
3318  if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr))
3319  Subexpr = OVE->getSourceExpr();
3320  if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects))
3321  return true;
3322  }
3323  return false;
3324  }
3325 
3326  case ObjCBoxedExprClass:
3327  case ObjCArrayLiteralClass:
3328  case ObjCDictionaryLiteralClass:
3329  case ObjCSelectorExprClass:
3330  case ObjCProtocolExprClass:
3331  case ObjCIsaExprClass:
3332  case ObjCIndirectCopyRestoreExprClass:
3333  case ObjCSubscriptRefExprClass:
3334  case ObjCBridgedCastExprClass:
3335  case ObjCMessageExprClass:
3336  case ObjCPropertyRefExprClass:
3337  // FIXME: Classify these cases better.
3338  if (IncludePossibleEffects)
3339  return true;
3340  break;
3341  }
3342 
3343  // Recurse to children.
3344  for (const Stmt *SubStmt : children())
3345  if (SubStmt &&
3346  cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects))
3347  return true;
3348 
3349  return false;
3350 }
3351 
3352 namespace {
3353  /// Look for a call to a non-trivial function within an expression.
3354  class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder>
3355  {
3357 
3358  bool NonTrivial;
3359 
3360  public:
3361  explicit NonTrivialCallFinder(const ASTContext &Context)
3362  : Inherited(Context), NonTrivial(false) { }
3363 
3364  bool hasNonTrivialCall() const { return NonTrivial; }
3365 
3366  void VisitCallExpr(const CallExpr *E) {
3367  if (const CXXMethodDecl *Method
3368  = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) {
3369  if (Method->isTrivial()) {
3370  // Recurse to children of the call.
3371  Inherited::VisitStmt(E);
3372  return;
3373  }
3374  }
3375 
3376  NonTrivial = true;
3377  }
3378 
3379  void VisitCXXConstructExpr(const CXXConstructExpr *E) {
3380  if (E->getConstructor()->isTrivial()) {
3381  // Recurse to children of the call.
3382  Inherited::VisitStmt(E);
3383  return;
3384  }
3385 
3386  NonTrivial = true;
3387  }
3388 
3389  void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
3390  if (E->getTemporary()->getDestructor()->isTrivial()) {
3391  Inherited::VisitStmt(E);
3392  return;
3393  }
3394 
3395  NonTrivial = true;
3396  }
3397  };
3398 }
3399 
3400 bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const {
3401  NonTrivialCallFinder Finder(Ctx);
3402  Finder.Visit(this);
3403  return Finder.hasNonTrivialCall();
3404 }
3405 
3406 /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null
3407 /// pointer constant or not, as well as the specific kind of constant detected.
3408 /// Null pointer constants can be integer constant expressions with the
3409 /// value zero, casts of zero to void*, nullptr (C++0X), or __null
3410 /// (a GNU extension).
3414  if (isValueDependent() &&
3415  (!Ctx.getLangOpts().CPlusPlus11 || Ctx.getLangOpts().MSVCCompat)) {
3416  switch (NPC) {
3418  llvm_unreachable("Unexpected value dependent expression!");
3420  if (isTypeDependent() || getType()->isIntegralType(Ctx))
3421  return NPCK_ZeroExpression;
3422  else
3423  return NPCK_NotNull;
3424 
3426  return NPCK_NotNull;
3427  }
3428  }
3429 
3430  // Strip off a cast to void*, if it exists. Except in C++.
3431  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
3432  if (!Ctx.getLangOpts().CPlusPlus) {
3433  // Check that it is a cast to void*.
3434  if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
3435  QualType Pointee = PT->getPointeeType();
3436  // Only (void*)0 or equivalent are treated as nullptr. If pointee type
3437  // has non-default address space it is not treated as nullptr.
3438  // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
3439  // since it cannot be assigned to a pointer to constant address space.
3440  bool PointeeHasDefaultAS =
3441  Pointee.getAddressSpace() == LangAS::Default ||
3442  (Ctx.getLangOpts().OpenCLVersion >= 200 &&
3443  Pointee.getAddressSpace() == LangAS::opencl_generic) ||
3444  (Ctx.getLangOpts().OpenCL &&
3445  Ctx.getLangOpts().OpenCLVersion < 200 &&
3447 
3448  if (PointeeHasDefaultAS && Pointee->isVoidType() && // to void*
3449  CE->getSubExpr()->getType()->isIntegerType()) // from int.
3450  return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3451  }
3452  }
3453  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
3454  // Ignore the ImplicitCastExpr type entirely.
3455  return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3456  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
3457  // Accept ((void*)0) as a null pointer constant, as many other
3458  // implementations do.
3459  return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3460  } else if (const GenericSelectionExpr *GE =
3461  dyn_cast<GenericSelectionExpr>(this)) {
3462  if (GE->isResultDependent())
3463  return NPCK_NotNull;
3464  return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC);
3465  } else if (const ChooseExpr *CE = dyn_cast<ChooseExpr>(this)) {
3466  if (CE->isConditionDependent())
3467  return NPCK_NotNull;
3468  return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC);
3469  } else if (const CXXDefaultArgExpr *DefaultArg
3470  = dyn_cast<CXXDefaultArgExpr>(this)) {
3471  // See through default argument expressions.
3472  return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
3473  } else if (const CXXDefaultInitExpr *DefaultInit
3474  = dyn_cast<CXXDefaultInitExpr>(this)) {
3475  // See through default initializer expressions.
3476  return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC);
3477  } else if (isa<GNUNullExpr>(this)) {
3478  // The GNU __null extension is always a null pointer constant.
3479  return NPCK_GNUNull;
3480  } else if (const MaterializeTemporaryExpr *M
3481  = dyn_cast<MaterializeTemporaryExpr>(this)) {
3482  return M->GetTemporaryExpr()->isNullPointerConstant(Ctx, NPC);
3483  } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) {
3484  if (const Expr *Source = OVE->getSourceExpr())
3485  return Source->isNullPointerConstant(Ctx, NPC);
3486  }
3487 
3488  // C++11 nullptr_t is always a null pointer constant.
3489  if (getType()->isNullPtrType())
3490  return NPCK_CXX11_nullptr;
3491 
3492  if (const RecordType *UT = getType()->getAsUnionType())
3493  if (!Ctx.getLangOpts().CPlusPlus11 &&
3494  UT && UT->getDecl()->hasAttr<TransparentUnionAttr>())
3495  if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){
3496  const Expr *InitExpr = CLE->getInitializer();
3497  if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr))
3498  return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC);
3499  }
3500  // This expression must be an integer type.
3501  if (!getType()->isIntegerType() ||
3502  (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType()))
3503  return NPCK_NotNull;
3504 
3505  if (Ctx.getLangOpts().CPlusPlus11) {
3506  // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with
3507  // value zero or a prvalue of type std::nullptr_t.
3508  // Microsoft mode permits C++98 rules reflecting MSVC behavior.
3509  const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this);
3510  if (Lit && !Lit->getValue())
3511  return NPCK_ZeroLiteral;
3512  else if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx))
3513  return NPCK_NotNull;
3514  } else {
3515  // If we have an integer constant expression, we need to *evaluate* it and
3516  // test for the value 0.
3517  if (!isIntegerConstantExpr(Ctx))
3518  return NPCK_NotNull;
3519  }
3520 
3521  if (EvaluateKnownConstInt(Ctx) != 0)
3522  return NPCK_NotNull;
3523 
3524  if (isa<IntegerLiteral>(this))
3525  return NPCK_ZeroLiteral;
3526  return NPCK_ZeroExpression;
3527 }
3528 
3529 /// If this expression is an l-value for an Objective C
3530 /// property, find the underlying property reference expression.
3532  const Expr *E = this;
3533  while (true) {
3534  assert((E->getValueKind() == VK_LValue &&
3535  E->getObjectKind() == OK_ObjCProperty) &&
3536  "expression is not a property reference");
3537  E = E->IgnoreParenCasts();
3538  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
3539  if (BO->getOpcode() == BO_Comma) {
3540  E = BO->getRHS();
3541  continue;
3542  }
3543  }
3544 
3545  break;
3546  }
3547 
3548  return cast<ObjCPropertyRefExpr>(E);
3549 }
3550 
3551 bool Expr::isObjCSelfExpr() const {
3552  const Expr *E = IgnoreParenImpCasts();
3553 
3554  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
3555  if (!DRE)
3556  return false;
3557 
3558  const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl());
3559  if (!Param)
3560  return false;
3561 
3562  const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext());
3563  if (!M)
3564  return false;
3565 
3566  return M->getSelfDecl() == Param;
3567 }
3568 
3570  Expr *E = this->IgnoreParens();
3571 
3572  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3573  if (ICE->getCastKind() == CK_LValueToRValue ||
3574  (ICE->getValueKind() != VK_RValue && ICE->getCastKind() == CK_NoOp))
3575  E = ICE->getSubExpr()->IgnoreParens();
3576  else
3577  break;
3578  }
3579 
3580  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
3581  if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
3582  if (Field->isBitField())
3583  return Field;
3584 
3585  if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) {
3586  FieldDecl *Ivar = IvarRef->getDecl();
3587  if (Ivar->isBitField())
3588  return Ivar;
3589  }
3590 
3591  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) {
3592  if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
3593  if (Field->isBitField())
3594  return Field;
3595 
3596  if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl()))
3597  if (Expr *E = BD->getBinding())
3598  return E->getSourceBitField();
3599  }
3600 
3601  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) {
3602  if (BinOp->isAssignmentOp() && BinOp->getLHS())
3603  return BinOp->getLHS()->getSourceBitField();
3604 
3605  if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS())
3606  return BinOp->getRHS()->getSourceBitField();
3607  }
3608 
3609  if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E))
3610  if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp())
3611  return UnOp->getSubExpr()->getSourceBitField();
3612 
3613  return nullptr;
3614 }
3615 
3617  // FIXME: Why do we not just look at the ObjectKind here?
3618  const Expr *E = this->IgnoreParens();
3619 
3620  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3621  if (ICE->getValueKind() != VK_RValue &&
3622  ICE->getCastKind() == CK_NoOp)
3623  E = ICE->getSubExpr()->IgnoreParens();
3624  else
3625  break;
3626  }
3627 
3628  if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E))
3629  return ASE->getBase()->getType()->isVectorType();
3630 
3631  if (isa<ExtVectorElementExpr>(E))
3632  return true;
3633 
3634  if (auto *DRE = dyn_cast<DeclRefExpr>(E))
3635  if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl()))
3636  if (auto *E = BD->getBinding())
3637  return E->refersToVectorElement();
3638 
3639  return false;
3640 }
3641 
3643  const Expr *E = this->IgnoreParenImpCasts();
3644 
3645  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
3646  if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
3647  if (VD->getStorageClass() == SC_Register &&
3648  VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
3649  return true;
3650 
3651  return false;
3652 }
3653 
3654 /// isArrow - Return true if the base expression is a pointer to vector,
3655 /// return false if the base expression is a vector.
3657  return getBase()->getType()->isPointerType();
3658 }
3659 
3661  if (const VectorType *VT = getType()->getAs<VectorType>())
3662  return VT->getNumElements();
3663  return 1;
3664 }
3665 
3666 /// containsDuplicateElements - Return true if any element access is repeated.
3668  // FIXME: Refactor this code to an accessor on the AST node which returns the
3669  // "type" of component access, and share with code below and in Sema.
3670  StringRef Comp = Accessor->getName();
3671 
3672  // Halving swizzles do not contain duplicate elements.
3673  if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
3674  return false;
3675 
3676  // Advance past s-char prefix on hex swizzles.
3677  if (Comp[0] == 's' || Comp[0] == 'S')
3678  Comp = Comp.substr(1);
3679 
3680  for (unsigned i = 0, e = Comp.size(); i != e; ++i)
3681  if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos)
3682  return true;
3683 
3684  return false;
3685 }
3686 
3687 /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
3689  SmallVectorImpl<uint32_t> &Elts) const {
3690  StringRef Comp = Accessor->getName();
3691  bool isNumericAccessor = false;
3692  if (Comp[0] == 's' || Comp[0] == 'S') {
3693  Comp = Comp.substr(1);
3694  isNumericAccessor = true;
3695  }
3696 
3697  bool isHi = Comp == "hi";
3698  bool isLo = Comp == "lo";
3699  bool isEven = Comp == "even";
3700  bool isOdd = Comp == "odd";
3701 
3702  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
3703  uint64_t Index;
3704 
3705  if (isHi)
3706  Index = e + i;
3707  else if (isLo)
3708  Index = i;
3709  else if (isEven)
3710  Index = 2 * i;
3711  else if (isOdd)
3712  Index = 2 * i + 1;
3713  else
3714  Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor);
3715 
3716  Elts.push_back(Index);
3717  }
3718 }
3719 
3721  QualType Type, SourceLocation BLoc,
3722  SourceLocation RP)
3723  : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary,
3724  Type->isDependentType(), Type->isDependentType(),
3725  Type->isInstantiationDependentType(),
3727  BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size())
3728 {
3729  SubExprs = new (C) Stmt*[args.size()];
3730  for (unsigned i = 0; i != args.size(); i++) {
3731  if (args[i]->isTypeDependent())
3732  ExprBits.TypeDependent = true;
3733  if (args[i]->isValueDependent())
3734  ExprBits.ValueDependent = true;
3735  if (args[i]->isInstantiationDependent())
3736  ExprBits.InstantiationDependent = true;
3737  if (args[i]->containsUnexpandedParameterPack())
3738  ExprBits.ContainsUnexpandedParameterPack = true;
3739 
3740  SubExprs[i] = args[i];
3741  }
3742 }
3743 
3745  if (SubExprs) C.Deallocate(SubExprs);
3746 
3747  this->NumExprs = Exprs.size();
3748  SubExprs = new (C) Stmt*[NumExprs];
3749  memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size());
3750 }
3751 
3753  SourceLocation GenericLoc, Expr *ControllingExpr,
3754  ArrayRef<TypeSourceInfo*> AssocTypes,
3755  ArrayRef<Expr*> AssocExprs,
3756  SourceLocation DefaultLoc,
3757  SourceLocation RParenLoc,
3758  bool ContainsUnexpandedParameterPack,
3759  unsigned ResultIndex)
3760  : Expr(GenericSelectionExprClass,
3761  AssocExprs[ResultIndex]->getType(),
3762  AssocExprs[ResultIndex]->getValueKind(),
3763  AssocExprs[ResultIndex]->getObjectKind(),
3764  AssocExprs[ResultIndex]->isTypeDependent(),
3765  AssocExprs[ResultIndex]->isValueDependent(),
3766  AssocExprs[ResultIndex]->isInstantiationDependent(),
3767  ContainsUnexpandedParameterPack),
3768  AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]),
3769  SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]),
3770  NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
3771  GenericLoc(GenericLoc), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
3772  SubExprs[CONTROLLING] = ControllingExpr;
3773  assert(AssocTypes.size() == AssocExprs.size());
3774  std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes);
3775  std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR);
3776 }
3777 
3779  SourceLocation GenericLoc, Expr *ControllingExpr,
3780  ArrayRef<TypeSourceInfo*> AssocTypes,
3781  ArrayRef<Expr*> AssocExprs,
3782  SourceLocation DefaultLoc,
3783  SourceLocation RParenLoc,
3784  bool ContainsUnexpandedParameterPack)
3785  : Expr(GenericSelectionExprClass,
3786  Context.DependentTy,
3787  VK_RValue,
3788  OK_Ordinary,
3789  /*isTypeDependent=*/true,
3790  /*isValueDependent=*/true,
3791  /*isInstantiationDependent=*/true,
3792  ContainsUnexpandedParameterPack),
3793  AssocTypes(new (Context) TypeSourceInfo*[AssocTypes.size()]),
3794  SubExprs(new (Context) Stmt*[END_EXPR+AssocExprs.size()]),
3795  NumAssocs(AssocExprs.size()), ResultIndex(-1U), GenericLoc(GenericLoc),
3796  DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
3797  SubExprs[CONTROLLING] = ControllingExpr;
3798  assert(AssocTypes.size() == AssocExprs.size());
3799  std::copy(AssocTypes.begin(), AssocTypes.end(), this->AssocTypes);
3800  std::copy(AssocExprs.begin(), AssocExprs.end(), SubExprs+END_EXPR);
3801 }
3802 
3803 //===----------------------------------------------------------------------===//
3804 // DesignatedInitExpr
3805 //===----------------------------------------------------------------------===//
3806 
3808  assert(Kind == FieldDesignator && "Only valid on a field designator");
3809  if (Field.NameOrField & 0x01)
3810  return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
3811  else
3812  return getField()->getIdentifier();
3813 }
3814 
3815 DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty,
3816  llvm::ArrayRef<Designator> Designators,
3817  SourceLocation EqualOrColonLoc,
3818  bool GNUSyntax,
3819  ArrayRef<Expr*> IndexExprs,
3820  Expr *Init)
3821  : Expr(DesignatedInitExprClass, Ty,
3822  Init->getValueKind(), Init->getObjectKind(),
3823  Init->isTypeDependent(), Init->isValueDependent(),
3824  Init->isInstantiationDependent(),
3826  EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
3827  NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) {
3828  this->Designators = new (C) Designator[NumDesignators];
3829 
3830  // Record the initializer itself.
3831  child_iterator Child = child_begin();
3832  *Child++ = Init;
3833 
3834  // Copy the designators and their subexpressions, computing
3835  // value-dependence along the way.
3836  unsigned IndexIdx = 0;
3837  for (unsigned I = 0; I != NumDesignators; ++I) {
3838  this->Designators[I] = Designators[I];
3839 
3840  if (this->Designators[I].isArrayDesignator()) {
3841  // Compute type- and value-dependence.
3842  Expr *Index = IndexExprs[IndexIdx];
3843  if (Index->isTypeDependent() || Index->isValueDependent())
3844  ExprBits.TypeDependent = ExprBits.ValueDependent = true;
3845  if (Index->isInstantiationDependent())
3846  ExprBits.InstantiationDependent = true;
3847  // Propagate unexpanded parameter packs.
3849  ExprBits.ContainsUnexpandedParameterPack = true;
3850 
3851  // Copy the index expressions into permanent storage.
3852  *Child++ = IndexExprs[IndexIdx++];
3853  } else if (this->Designators[I].isArrayRangeDesignator()) {
3854  // Compute type- and value-dependence.
3855  Expr *Start = IndexExprs[IndexIdx];
3856  Expr *End = IndexExprs[IndexIdx + 1];
3857  if (Start->isTypeDependent() || Start->isValueDependent() ||
3858  End->isTypeDependent() || End->isValueDependent()) {
3859  ExprBits.TypeDependent = ExprBits.ValueDependent = true;
3860  ExprBits.InstantiationDependent = true;
3861  } else if (Start->isInstantiationDependent() ||
3862  End->isInstantiationDependent()) {
3863  ExprBits.InstantiationDependent = true;
3864  }
3865 
3866  // Propagate unexpanded parameter packs.
3867  if (Start->containsUnexpandedParameterPack() ||
3869  ExprBits.ContainsUnexpandedParameterPack = true;
3870 
3871  // Copy the start/end expressions into permanent storage.
3872  *Child++ = IndexExprs[IndexIdx++];
3873  *Child++ = IndexExprs[IndexIdx++];
3874  }
3875  }
3876 
3877  assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions");
3878 }
3879 
3882  llvm::ArrayRef<Designator> Designators,
3883  ArrayRef<Expr*> IndexExprs,
3884  SourceLocation ColonOrEqualLoc,
3885  bool UsesColonSyntax, Expr *Init) {
3886  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
3887  alignof(DesignatedInitExpr));
3888  return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators,
3889  ColonOrEqualLoc, UsesColonSyntax,
3890  IndexExprs, Init);
3891 }
3892 
3894  unsigned NumIndexExprs) {
3895  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1),
3896  alignof(DesignatedInitExpr));
3897  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
3898 }
3899 
3901  const Designator *Desigs,
3902  unsigned NumDesigs) {
3903  Designators = new (C) Designator[NumDesigs];
3904  NumDesignators = NumDesigs;
3905  for (unsigned I = 0; I != NumDesigs; ++I)
3906  Designators[I] = Desigs[I];
3907 }
3908 
3910  DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this);
3911  if (size() == 1)
3912  return DIE->getDesignator(0)->getSourceRange();
3913  return SourceRange(DIE->getDesignator(0)->getBeginLoc(),
3914  DIE->getDesignator(size() - 1)->getEndLoc());
3915 }
3916 
3918  SourceLocation StartLoc;
3919  auto *DIE = const_cast<DesignatedInitExpr *>(this);
3920  Designator &First = *DIE->getDesignator(0);
3921  if (First.isFieldDesignator()) {
3922  if (GNUSyntax)
3924  else
3926  } else
3927  StartLoc =
3929  return StartLoc;
3930 }
3931 
3933  return getInit()->getEndLoc();
3934 }
3935 
3937  assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
3938  return getSubExpr(D.ArrayOrRange.Index + 1);
3939 }
3940 
3942  assert(D.Kind == Designator::ArrayRangeDesignator &&
3943  "Requires array range designator");
3944  return getSubExpr(D.ArrayOrRange.Index + 1);
3945 }
3946 
3948  assert(D.Kind == Designator::ArrayRangeDesignator &&
3949  "Requires array range designator");
3950  return getSubExpr(D.ArrayOrRange.Index + 2);
3951 }
3952 
3953 /// Replaces the designator at index @p Idx with the series
3954 /// of designators in [First, Last).
3956  const Designator *First,
3957  const Designator *Last) {
3958  unsigned NumNewDesignators = Last - First;
3959  if (NumNewDesignators == 0) {
3960  std::copy_backward(Designators + Idx + 1,
3961  Designators + NumDesignators,
3962  Designators + Idx);
3963  --NumNewDesignators;
3964  return;
3965  } else if (NumNewDesignators == 1) {
3966  Designators[Idx] = *First;
3967  return;
3968  }
3969 
3970  Designator *NewDesignators
3971  = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
3972  std::copy(Designators, Designators + Idx, NewDesignators);
3973  std::copy(First, Last, NewDesignators + Idx);
3974  std::copy(Designators + Idx + 1, Designators + NumDesignators,
3975  NewDesignators + Idx + NumNewDesignators);
3976  Designators = NewDesignators;
3977  NumDesignators = NumDesignators - 1 + NumNewDesignators;
3978 }
3979 
3981  SourceLocation lBraceLoc, Expr *baseExpr, SourceLocation rBraceLoc)
3982  : Expr(DesignatedInitUpdateExprClass, baseExpr->getType(), VK_RValue,
3984  BaseAndUpdaterExprs[0] = baseExpr;
3985 
3986  InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc);
3987  ILE->setType(baseExpr->getType());
3988  BaseAndUpdaterExprs[1] = ILE;
3989 }
3990 
3992  return getBase()->getBeginLoc();
3993 }
3994 
3996  return getBase()->getEndLoc();
3997 }
3998 
4000  ArrayRef<Expr*> exprs,
4001  SourceLocation rparenloc)
4002  : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary,
4003  false, false, false, false),
4004  NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) {
4005  Exprs = new (C) Stmt*[exprs.size()];
4006  for (unsigned i = 0; i != exprs.size(); ++i) {
4007  if (exprs[i]->isTypeDependent())
4008  ExprBits.TypeDependent = true;
4009  if (exprs[i]->isValueDependent())
4010  ExprBits.ValueDependent = true;
4011  if (exprs[i]->isInstantiationDependent())
4012  ExprBits.InstantiationDependent = true;
4013  if (exprs[i]->containsUnexpandedParameterPack())
4014  ExprBits.ContainsUnexpandedParameterPack = true;
4015 
4016  Exprs[i] = exprs[i];
4017  }
4018 }
4019 
4021  if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e))
4022  e = ewc->getSubExpr();
4023  if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e))
4024  e = m->GetTemporaryExpr();
4025  e = cast<CXXConstructExpr>(e)->getArg(0);
4026  while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
4027  e = ice->getSubExpr();
4028  return cast<OpaqueValueExpr>(e);
4029 }
4030 
4032  EmptyShell sh,
4033  unsigned numSemanticExprs) {
4034  void *buffer =
4035  Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs),
4036  alignof(PseudoObjectExpr));
4037  return new(buffer) PseudoObjectExpr(sh, numSemanticExprs);
4038 }
4039 
4040 PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
4041  : Expr(PseudoObjectExprClass, shell) {
4042  PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1;
4043 }
4044 
4046  ArrayRef<Expr*> semantics,
4047  unsigned resultIndex) {
4048  assert(syntax && "no syntactic expression!");
4049  assert(semantics.size() && "no semantic expressions!");
4050 
4051  QualType type;
4052  ExprValueKind VK;
4053  if (resultIndex == NoResult) {
4054  type = C.VoidTy;
4055  VK = VK_RValue;
4056  } else {
4057  assert(resultIndex < semantics.size());
4058  type = semantics[resultIndex]->getType();
4059  VK = semantics[resultIndex]->getValueKind();
4060  assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary);
4061  }
4062 
4063  void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1),
4064  alignof(PseudoObjectExpr));
4065  return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics,
4066  resultIndex);
4067 }
4068 
4069 PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK,
4070  Expr *syntax, ArrayRef<Expr*> semantics,
4071  unsigned resultIndex)
4072  : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary,
4073  /*filled in at end of ctor*/ false, false, false, false) {
4074  PseudoObjectExprBits.NumSubExprs = semantics.size() + 1;
4075  PseudoObjectExprBits.ResultIndex = resultIndex + 1;
4076 
4077  for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) {
4078  Expr *E = (i == 0 ? syntax : semantics[i-1]);
4079  getSubExprsBuffer()[i] = E;
4080 
4081  if (E->isTypeDependent())
4082  ExprBits.TypeDependent = true;
4083  if (E->isValueDependent())
4084  ExprBits.ValueDependent = true;
4086  ExprBits.InstantiationDependent = true;
4088  ExprBits.ContainsUnexpandedParameterPack = true;
4089 
4090  if (isa<OpaqueValueExpr>(E))
4091  assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr &&
4092  "opaque-value semantic expressions for pseudo-object "
4093  "operations must have sources");
4094  }
4095 }
4096 
4097 //===----------------------------------------------------------------------===//
4098 // Child Iterators for iterating over subexpressions/substatements
4099 //===----------------------------------------------------------------------===//
4100 
4101 // UnaryExprOrTypeTraitExpr
4103  const_child_range CCR =
4104  const_cast<const UnaryExprOrTypeTraitExpr *>(this)->children();
4105  return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end()));
4106 }
4107 
4109  // If this is of a type and the type is a VLA type (and not a typedef), the
4110  // size expression of the VLA needs to be treated as an executable expression.
4111  // Why isn't this weirdness documented better in StmtIterator?
4112  if (isArgumentType()) {
4113  if (const VariableArrayType *T =
4114  dyn_cast<VariableArrayType>(getArgumentType().getTypePtr()))
4117  }
4118  return const_child_range(&Argument.Ex, &Argument.Ex + 1);
4119 }
4120 
4122  QualType t, AtomicOp op, SourceLocation RP)
4123  : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary,
4124  false, false, false, false),
4125  NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op)
4126 {
4127  assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions");
4128  for (unsigned i = 0; i != args.size(); i++) {
4129  if (args[i]->isTypeDependent())
4130  ExprBits.TypeDependent = true;
4131  if (args[i]->isValueDependent())
4132  ExprBits.ValueDependent = true;
4133  if (args[i]->isInstantiationDependent())
4134  ExprBits.InstantiationDependent = true;
4135  if (args[i]->containsUnexpandedParameterPack())
4136  ExprBits.ContainsUnexpandedParameterPack = true;
4137 
4138  SubExprs[i] = args[i];
4139  }
4140 }
4141 
4143  switch (Op) {
4144  case AO__c11_atomic_init:
4145  case AO__opencl_atomic_init:
4146  case AO__c11_atomic_load:
4147  case AO__atomic_load_n:
4148  return 2;
4149 
4150  case AO__opencl_atomic_load:
4151  case AO__c11_atomic_store:
4152  case AO__c11_atomic_exchange:
4153  case AO__atomic_load:
4154  case AO__atomic_store:
4155  case AO__atomic_store_n:
4156  case AO__atomic_exchange_n:
4157  case AO__c11_atomic_fetch_add:
4158  case AO__c11_atomic_fetch_sub:
4159  case AO__c11_atomic_fetch_and:
4160  case AO__c11_atomic_fetch_or:
4161  case AO__c11_atomic_fetch_xor:
4162  case AO__atomic_fetch_add:
4163  case AO__atomic_fetch_sub:
4164  case AO__atomic_fetch_and:
4165  case AO__atomic_fetch_or:
4166  case AO__atomic_fetch_xor:
4167  case AO__atomic_fetch_nand:
4168  case AO__atomic_add_fetch:
4169  case AO__atomic_sub_fetch:
4170  case AO__atomic_and_fetch:
4171  case AO__atomic_or_fetch:
4172  case AO__atomic_xor_fetch:
4173  case AO__atomic_nand_fetch:
4174  case AO__atomic_fetch_min:
4175  case AO__atomic_fetch_max:
4176  return 3;
4177 
4178  case AO__opencl_atomic_store:
4179  case AO__opencl_atomic_exchange:
4180  case AO__opencl_atomic_fetch_add:
4181  case AO__opencl_atomic_fetch_sub:
4182  case AO__opencl_atomic_fetch_and:
4183  case AO__opencl_atomic_fetch_or:
4184  case AO__opencl_atomic_fetch_xor:
4185  case AO__opencl_atomic_fetch_min:
4186  case AO__opencl_atomic_fetch_max:
4187  case AO__atomic_exchange:
4188  return 4;
4189 
4190  case AO__c11_atomic_compare_exchange_strong:
4191  case AO__c11_atomic_compare_exchange_weak:
4192  return 5;
4193 
4194  case AO__opencl_atomic_compare_exchange_strong:
4195  case AO__opencl_atomic_compare_exchange_weak:
4196  case AO__atomic_compare_exchange:
4197  case AO__atomic_compare_exchange_n:
4198  return 6;
4199  }
4200  llvm_unreachable("unknown atomic op");
4201 }
4202 
4204  auto T = getPtr()->getType()->castAs<PointerType>()->getPointeeType();
4205  if (auto AT = T->getAs<AtomicType>())
4206  return AT->getValueType();
4207  return T;
4208 }
4209 
4211  unsigned ArraySectionCount = 0;
4212  while (auto *OASE = dyn_cast<OMPArraySectionExpr>(Base->IgnoreParens())) {
4213  Base = OASE->getBase();
4214  ++ArraySectionCount;
4215  }
4216  while (auto *ASE =
4217  dyn_cast<ArraySubscriptExpr>(Base->IgnoreParenImpCasts())) {
4218  Base = ASE->getBase();
4219  ++ArraySectionCount;
4220  }
4221  Base = Base->IgnoreParenImpCasts();
4222  auto OriginalTy = Base->getType();
4223  if (auto *DRE = dyn_cast<DeclRefExpr>(Base))
4224  if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
4225  OriginalTy = PVD->getOriginalType().getNonReferenceType();
4226 
4227  for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
4228  if (OriginalTy->isAnyPointerType())
4229  OriginalTy = OriginalTy->getPointeeType();
4230  else {
4231  assert (OriginalTy->isArrayType());
4232  OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
4233  }
4234  }
4235  return OriginalTy;
4236 }
child_iterator child_begin()
Definition: Stmt.h:673
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:577
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:78
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4190
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Represents a single C99 designator.
Definition: Expr.h:4395
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
void setValueDependent(bool VD)
Set whether this expression is value-dependent or not.
Definition: Expr.h:152
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:451
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1196
Represents a function declaration or definition.
Definition: Decl.h:1732
Expr * getArrayIndex(const Designator &D) const
Definition: Expr.cpp:3936
Stmt * body_back()
Definition: Stmt.h:844
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:550
bool hasAttr(attr::Kind AK) const
Determine whether this type had the specified attribute applied to it (looking through top-level type...
Definition: Type.cpp:1622
static void computeDeclRefDependence(const ASTContext &Ctx, NamedDecl *D, QualType T, bool &TypeDependent, bool &ValueDependent, bool &InstantiationDependent)
Compute the type-, value-, and instantiation-dependence of a declaration reference based on the decla...
Definition: Expr.cpp:236
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:6577
Expr * getLHS() const
Definition: Expr.h:3528
StringRef Identifier
Definition: Format.cpp:1636
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
Definition: Expr.h:5231
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
Definition: Lexer.h:77
SourceLocation getRParenLoc() const
Definition: Expr.h:2508
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2011
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition: Expr.cpp:2107
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2543
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:3917
QualType getPointeeType() const
Definition: Type.h:2556
A (possibly-)qualified type.
Definition: Type.h:642
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
bool isArrayType() const
Definition: Type.h:6331
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:2441
static StringLiteral * CreateEmpty(const ASTContext &C, unsigned NumStrs)
Construct an empty string literal.
Definition: Expr.cpp:939
const DeclarationNameLoc & getInfo() const
Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
Definition: Expr.h:110
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c.h:68
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:868
unsigned FieldLoc
The location of the field name in the designated initializer.
Definition: Expr.h:4372
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4134
Stmt - This represents one statement.
Definition: Stmt.h:66
DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc, Expr *baseExprs, SourceLocation rBraceLoc)
Definition: Expr.cpp:3980
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:2429
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3361
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:1101
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:497
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition: Expr.h:472
Defines the SourceManager interface.
bool hasNonTrivialCall(const ASTContext &Ctx) const
Determine whether this expression involves a call to any function that is not trivial.
Definition: Expr.cpp:3400
bool isRecordType() const
Definition: Type.h:6355
reverse_iterator rbegin()
Definition: ASTVector.h:103
Expr * getBase() const
Definition: Expr.h:2644
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:270
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:6517
void setSemantics(const llvm::fltSemantics &Sem)
Set the APFloat semantics this literal uses.
Definition: Expr.cpp:862
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
bool hasUnusedResultAttr() const
Returns true if this function or its return type has the warn_unused_result attribute.
Definition: Decl.h:2323
FloatingLiteralBitfields FloatingLiteralBits
Definition: Stmt.h:505
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition: Expr.cpp:3688
void setType(QualType t)
Definition: Expr.h:129
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic, and whose semantics are that of the sole contained initializer)?
Definition: Expr.cpp:2035
Defines the C++ template declaration subclasses.
Opcode getOpcode() const
Definition: Expr.h:3234
StringRef P
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
Definition: Expr.h:377
iterator insert(const ASTContext &C, iterator I, const T &Elt)
Definition: ASTVector.h:219
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:1819
NamedDecl * getDecl() const
The base class of the type hierarchy.
Definition: Type.h:1415
bool isSemanticForm() const
Definition: Expr.h:4236
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:663
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2818
DeclRefExprBitfields DeclRefExprBits
Definition: Stmt.h:507
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1262
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
SourceLocation getLParenLoc() const
Definition: Expr.h:3156
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:699
QualType adjustStringLiteralBaseType(QualType StrLTy) const
A container of type source information.
Definition: Decl.h:86
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition: Expr.cpp:3667
static StringLiteral * Create(const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:914
CallExpr(const ASTContext &C, StmtClass SC, Expr *fn, ArrayRef< Expr *> preargs, ArrayRef< Expr *> args, QualType t, ExprValueKind VK, SourceLocation rparenloc)
Definition: Expr.cpp:1221
unsigned getCharWidth() const
Definition: TargetInfo.h:370
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2478
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
Definition: ExprCXX.h:4068
Expr * ignoreParenBaseCasts() LLVM_READONLY
Ignore parentheses and derived-to-base casts.
Definition: Expr.cpp:2652
QualType getElementType() const
Definition: Type.h:2853
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:456
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
Definition: Expr.cpp:1419
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
Definition: Expr.cpp:4020
Represents a variable declaration or definition.
Definition: Decl.h:812
const ObjCPropertyRefExpr * getObjCProperty() const
If this expression is an l-value for an Objective C property, find the underlying property reference ...
Definition: Expr.cpp:3531
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:2804
bool isEnumeralType() const
Definition: Type.h:6359
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6716
MangleContext * createMangleContext()
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type...
Definition: Type.h:6788
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
Definition: Expr.cpp:1995
void setInit(unsigned Init, Expr *expr)
Definition: Expr.h:4144
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
Definition: Expr.cpp:492
size_type size() const
Definition: ASTVector.h:109
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
Definition: Expr.cpp:2058
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
static DeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Construct an empty declaration reference expression.
Definition: Expr.cpp:436
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Definition: ExprCXX.h:3033
static bool isAssignmentOp(Opcode Opc)
Definition: Expr.h:3316
Defines the clang::Expr interface and subclasses for C++ expressions.
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition: Expr.cpp:3569
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:1158
Represents a struct/union/class.
Definition: Decl.h:3589
Represents a C99 designated initializer expression.
Definition: Expr.h:4320
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:297
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
unsigned GetStringLength() const
const Expr * getBestDynamicClassTypeExpr() const
Get the inner expression that determines the best dynamic class.
Definition: Expr.cpp:38
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:255
StmtIterator cast_away_const(const ConstStmtIterator &RHS)
Definition: StmtIterator.h:152
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
A C++ nested-name-specifier augmented with source location information.
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
Used for GCC&#39;s __alignof.
Definition: TypeTraits.h:107
unsigned getChar32Width() const
getChar32Width/Align - Return the size of &#39;char32_t&#39; for this target, in bits.
Definition: TargetInfo.h:553
bool isCharType() const
Definition: Type.cpp:1779
field_range fields() const
Definition: Decl.h:3780
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:280
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
Definition: Decl.h:2575
void setNumArgs(const ASTContext &C, unsigned NumArgs)
setNumArgs - This changes the number of arguments present in this call.
Definition: Expr.cpp:1312
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr *> IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:3881
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:97
bool isReferenceType() const
Definition: Type.h:6294
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr)
Definition: Expr.cpp:392
Expr * getSubExpr()
Definition: Expr.h:2942
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
Definition: Expr.cpp:3656
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:6630
NestedNameSpecifierLoc QualifierLoc
The nested-name-specifier that qualifies the name, including source-location information.
Definition: Expr.h:2545
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:110
struct FieldDesignator Field
A field designator, e.g., ".x".
Definition: Expr.h:4405
const Expr *const * const_semantics_iterator
Definition: Expr.h:5254
ShuffleVectorExpr(const ASTContext &C, ArrayRef< Expr *> args, QualType Type, SourceLocation BLoc, SourceLocation RP)
Definition: Expr.cpp:3720
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:508
StringRef getOpcodeStr() const
Definition: Expr.h:3253
bool isGLValue() const
Definition: Expr.h:252
Describes an C or C++ initializer list.
Definition: Expr.h:4086
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:540
bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx) const
EvaluateAsBooleanCondition - Return true if this is a constant which we can fold and convert to a boo...
void setValue(const ASTContext &C, const llvm::APInt &Val)
Definition: Expr.h:1298
BinaryOperatorKind
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
Definition: Expr.cpp:800
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:2653
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:3932
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1371
Base object ctor.
Definition: ABI.h:27
A convenient class for passing around template argument information.
Definition: TemplateBase.h:552
uint32_t Offset
Definition: CacheTokens.cpp:43
Qualifiers::GC getObjCGCAttrKind(QualType Ty) const
Return one of the GCNone, Weak or Strong Objective-C garbage collection attributes.
Expr * getPtr() const
Definition: Expr.h:5353
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
Definition: Type.h:6765
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:405
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
Definition: Expr.h:708
unsigned getNumPreArgs() const
Definition: Expr.h:2403
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:1837
static bool isRecordType(QualType T)
semantics_iterator semantics_end()
Definition: Expr.h:5261
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3193
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:6128
child_range children()
Definition: Expr.h:4269
bool isBoundMemberFunction(ASTContext &Ctx) const
Returns true if this expression is a bound member function.
Definition: Expr.cpp:2510
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
Definition: Expr.cpp:2571
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
Definition: Type.h:1002
field_iterator field_begin() const
Definition: Decl.cpp:4146
SourceLocation getCaretLocation() const
Definition: Expr.cpp:2113
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token...
Definition: Lexer.h:349
static bool isBooleanType(QualType Ty)
An adjustment to be made to the temporary created when emitting a reference binding, which accesses a particular subobject of that temporary.
Definition: Expr.h:61
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:2877
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1217
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1236
bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const
isCXX98IntegralConstantExpr - Return true if this expression is an integral constant expression in C+...
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1611
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1478
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value &#39;V&#39; and type &#39;type&#39;.
Definition: Expr.cpp:778
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:167
An ordinary object is located at an address in memory.
Definition: Specifiers.h:126
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4040
Represents an ObjC class declaration.
Definition: DeclObjC.h:1164
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:1902
Expression is a GNU-style __null constant.
Definition: Expr.h:703
StmtClass
Definition: Stmt.h:68
const Stmt * getBody() const
Definition: Expr.cpp:2116
A binding in a decomposition declaration.
Definition: DeclCXX.h:3789
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
Definition: Builtins.h:128
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1063
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1186
void setIntValue(const ASTContext &C, const llvm::APInt &Val)
Definition: Expr.cpp:749
bool isObjCSelfExpr() const
Check if this expression is the ObjC &#39;self&#39; implicit parameter.
Definition: Expr.cpp:3551
ParenListExpr(const ASTContext &C, SourceLocation lparenloc, ArrayRef< Expr *> exprs, SourceLocation rparenloc)
Definition: Expr.cpp:3999
Represents the this expression in C++.
Definition: ExprCXX.h:966
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, Expr *LHS, Expr *RHS)
Definition: Expr.cpp:1936
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:644
PredefinedExprBitfields PredefinedExprBits
Definition: Stmt.h:503
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition: Expr.h:3114
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const
Returns true if this is a call to a builtin which does not evaluate side-effects within its arguments...
Definition: Expr.cpp:1362
bool hasAttr() const
Definition: DeclBase.h:531
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:3483
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:664
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:806
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1605
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3686
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
Expr * IgnoreParenNoopCasts(ASTContext &Ctx) LLVM_READONLY
IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the value (including ptr->int ...
Definition: Expr.cpp:2706
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1325
CastKind
CastKind - The kind of operation required for a conversion.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
Definition: Expr.cpp:1812
Specifies that the expression should never be value-dependent.
Definition: Expr.h:710
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
Definition: Expr.h:2194
iterator end()
Definition: ASTVector.h:99
InitListExpr * getUpdater() const
Definition: Expr.h:4672
ConstantExpr - An expression that occurs in a constant context.
Definition: Expr.h:903
void outputString(raw_ostream &OS) const
Definition: Expr.cpp:952
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
ConstStmtIterator const_child_iterator
Definition: Stmt.h:661
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
Definition: Expr.cpp:3075
Exposes information about the current target.
Definition: TargetInfo.h:54
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:136
void setString(const ASTContext &C, StringRef Str, StringKind Kind, bool IsPascal)
Sets the string data to the given string data.
Definition: Expr.cpp:1048
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function)...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:636
This represents one expression.
Definition: Expr.h:106
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
Definition: Expr.cpp:3900
SourceLocation End
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:107
std::string Label
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1452
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1572
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6779
void setTypeDependent(bool TD)
Set whether this expression is type-dependent or not.
Definition: Expr.h:170
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2700
unsigned getNumInits() const
Definition: Expr.h:4116
const Expr * getCallee() const
Definition: Expr.h:2412
const Expr * skipRValueSubobjectAdjustments() const
Definition: Expr.h:859
field_iterator field_end() const
Definition: Decl.h:3783
child_range children()
Definition: Expr.h:4861
DeclContext * getDeclContext()
Definition: DeclBase.h:427
ExprBitfields ExprBits
Definition: Stmt.h:502
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode. ...
Definition: Expr.cpp:1201
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:834
Represents the type decltype(expr) (C++11).
Definition: Type.h:4232
ArrayRef< Expr * > inits()
Definition: Expr.h:4126
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition: Expr.h:714
Extra data stored in some MemberExpr objects.
Definition: Expr.h:2542
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type...
Definition: Expr.cpp:2780
Base object dtor.
Definition: ABI.h:37
QualType getType() const
Definition: Expr.h:128
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1751
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, IdentKind IK, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:483
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:904
InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef< Expr *> initExprs, SourceLocation rbraceloc)
Definition: Expr.cpp:1968
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1720
UnaryOperator - This represents the unary-expression&#39;s (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Definition: Expr.h:1871
unsigned Index
Location of the first index expression within the designated initializer expression&#39;s list of subexpr...
Definition: Expr.h:4379
Represents a GCC generic vector type.
Definition: Type.h:3174
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:4496
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:3870
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1081
Allow UB that we can give a value, but not arbitrary unmodeled side effects.
Definition: Expr.h:596
ValueDecl * getDecl()
Definition: Expr.h:1119
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1405
The result type of a method or function.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2020
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr.cast]), which uses the syntax (Type)expr.
Definition: Expr.h:3125
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:406
reverse_iterator rend()
Definition: ASTVector.h:105
do v
Definition: arm_acle.h:78
const SourceManager & SM
Definition: Format.cpp:1490
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition: opencl-c.h:90
SourceRange getSourceRange() const
Definition: ExprCXX.h:137
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:293
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:412
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition: Expr.cpp:1340
unsigned getWCharWidth() const
getWCharWidth/Align - Return the size of &#39;wchar_t&#39; for this target, in bits.
Definition: TargetInfo.h:543
RecordDecl * getDecl() const
Definition: Type.h:4366
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
Definition: ExprCXX.h:126
Expr * IgnoreCasts() LLVM_READONLY
Ignore casts. Strip off any CastExprs, returning their operand.
Definition: Expr.cpp:2597
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1873
const llvm::fltSemantics & getSemantics() const
Return the APFloat semantics this literal uses.
Definition: Expr.cpp:844
Expr * IgnoreConversionOperator() LLVM_READONLY
IgnoreConversionOperator - Ignore conversion operator.
Definition: Expr.cpp:2695
AtomicExpr(SourceLocation BLoc, ArrayRef< Expr *> args, QualType t, AtomicOp op, SourceLocation RP)
Definition: Expr.cpp:4121
unsigned DotLoc
The location of the &#39;.&#39; in the designated initializer.
Definition: Expr.h:4369
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
Definition: Expr.h:2202
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:343
void ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last)
Replaces the designator at index Idx with the series of designators in [First, Last).
Definition: Expr.cpp:3955
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:939
Expr * getBase() const
Definition: Expr.h:4669
static StringRef getIdentKindName(IdentKind IK)
Definition: Expr.cpp:499
#define false
Definition: stdbool.h:33
Kind
QualType getCanonicalType() const
Definition: Type.h:6097
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:5187
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on a template...
Definition: Expr.h:191
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant...
Definition: Expr.cpp:3412
Encodes a location in the source.
QualType getReturnType() const
Definition: Type.h:3617
SourceLocation getOperatorLoc() const
Definition: Expr.h:3231
PseudoObjectExprBitfields PseudoObjectExprBits
Definition: Stmt.h:511
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:6174
Expression is not a Null pointer constant.
Definition: Expr.h:687
Expr * getSubExpr() const
Definition: Expr.h:1898
CastKind getCastKind() const
Definition: Expr.h:2936
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
Definition: Expr.cpp:1792
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1322
unsigned getChar16Width() const
getChar16Width/Align - Return the size of &#39;char16_t&#39; for this target, in bits.
Definition: TargetInfo.h:548
Represents a call to a member function that may be written either with member call syntax (e...
Definition: ExprCXX.h:164
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:376
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda&#39;s captures.
Definition: ExprCXX.h:1745
static QualType getUnderlyingType(const SubRegion *R)
unsigned int BasePathSizeTy
Definition: Expr.h:2879
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Definition: Decl.h:2717
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:3992
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:124
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr *> exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1406
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:1751
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2041
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2422
std::string getValueAsString(unsigned Radix) const
Definition: Expr.cpp:808
static std::string ComputeName(IdentKind IK, const Decl *CurrentDecl)
Definition: Expr.cpp:523
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2273
Specifies that a value-dependent expression should be considered to never be a null pointer constant...
Definition: Expr.h:718
CanQualType VoidTy
Definition: ASTContext.h:1025
Expr * updateInit(const ASTContext &C, unsigned Init, Expr *expr)
Updates the initializer at index Init with the new expression expr, and returns the old expression at...
Definition: Expr.cpp:1999
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1396
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:149
AccessSpecifier getAccess() const
bool isKnownToHaveBooleanValue() const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Definition: Expr.cpp:135
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1366
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3011
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Definition: Expr.cpp:2516
Expr ** getInits()
Retrieve the set of initializers.
Definition: Expr.h:4119
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition: Expr.cpp:3616
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Definition: Expr.cpp:3893
Used for C&#39;s _Alignof and C++&#39;s alignof.
Definition: TypeTraits.h:101
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
Definition: Expr.cpp:63
Expr * getArrayRangeStart(const Designator &D) const
Definition: Expr.cpp:3941
const ObjCMethodDecl * getMethodDecl() const
Definition: ExprObjC.h:1303
bool isVectorType() const
Definition: Type.h:6367
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1374
unsigned LBracketLoc
The location of the &#39;[&#39; starting the array range designator.
Definition: Expr.h:4381
Expr * getArrayFiller()
If this initializer list initializes an array with more elements than there are initializers in the l...
Definition: Expr.h:4180
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
Definition: CharInfo.h:140
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:4257
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2302
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2091
static MemberExpr * Create(const ASTContext &C, Expr *base, bool isarrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *memberdecl, DeclAccessPair founddecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *targs, QualType ty, ExprValueKind VK, ExprObjectKind OK)
Definition: Expr.cpp:1498
A placeholder type used to construct an empty shell of a type, that will be filled in later (e...
Definition: Stmt.h:541
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:216
Expr * getLHS() const
Definition: Expr.h:3237
A POD class for pairing a NamedDecl* with an access specifier.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:678
Represents a C11 generic selection.
Definition: Expr.h:4898
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:2087
SourceRange getDesignatorsSourceRange() const
Definition: Expr.cpp:3909
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1035
Dataflow Directional Tag Classes.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:2069
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1733
UnaryOperatorKind
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1261
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:571
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:168
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:106
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
Decl * getReferencedDeclOfCallee()
Definition: Expr.cpp:1285
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
Definition: Expr.cpp:1277
A field designator, e.g., ".x".
Definition: Expr.h:4359
void setExprs(const ASTContext &C, ArrayRef< Expr *> Exprs)
Definition: Expr.cpp:3744
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
AccessSpecifier getAccess() const
Definition: DeclBase.h:462
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:3415
StmtClass getStmtClass() const
Definition: Stmt.h:594
const char * getCastKindName() const
Definition: Expr.h:2940
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Definition: DeclCXX.h:2166
bool isBooleanType() const
Definition: Type.h:6643
Expression is a Null pointer constant built from a zero integer expression that is not a simple...
Definition: Expr.h:694
void resize(const ASTContext &C, unsigned N, const T &NV)
Definition: ASTVector.h:341
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr *> semantic, unsigned resultIndex)
Definition: Expr.cpp:4045
void setInstantiationDependent(bool ID)
Set whether this expression is instantiation-dependent or not.
Definition: Expr.h:196
const T * const_iterator
Definition: ASTVector.h:86
Expression is a C++11 nullptr.
Definition: Expr.h:700
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:2762
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition: Expr.cpp:3660
semantics_iterator semantics_begin()
Definition: Expr.h:5255
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1368
ConstEvaluatedExprVisitor - This class visits &#39;const Expr *&#39;s.
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3091
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Definition: DeclBase.h:2016
Expr * IgnoreParenImpCasts() LLVM_READONLY
IgnoreParenImpCasts - Ignore parentheses and implicit casts.
Definition: Expr.cpp:2669
Expr * getArrayRangeEnd(const Designator &D) const
Definition: Expr.cpp:3947
llvm::APInt getValue() const
Definition: Expr.h:1297
unsigned getNumSubExprs() const
Definition: Expr.h:5386
Decl * getCalleeDecl()
Definition: Expr.cpp:1281
Pointer to a block type.
Definition: Type.h:2645
GenericSelectionExpr(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo *> AssocTypes, ArrayRef< Expr *> AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Definition: Expr.cpp:3752
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:3991
bool isStringLiteralInit() const
Definition: Expr.cpp:2021
struct ArrayOrRangeDesignator ArrayOrRange
An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
Definition: Expr.h:4407
unsigned getIntWidth(QualType T) const
Not an overloaded operator.
Definition: OperatorKinds.h:23
bool isIncompleteArrayType() const
Definition: Type.h:6339
bool HasSideEffects
Whether the evaluated expression has side effects.
Definition: Expr.h:544
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4356
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:450
bool body_empty() const
Definition: Stmt.h:833
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2284
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6564
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
isConstantInitializer - Returns true if this expression can be emitted to IR as a constant...
Definition: Expr.cpp:2874
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:1837
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:3995
bool isFunctionType() const
Definition: Type.h:6278
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: Expr.cpp:1828
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Ignore parentheses and lvalue casts.
Definition: Expr.cpp:2626
Opcode getOpcode() const
Definition: Expr.h:1895
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1388
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes...
Definition: Expr.cpp:1746
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition: Stmt.h:506
Represents a base class of a C++ class.
Definition: DeclCXX.h:192
iterator begin()
Definition: ASTVector.h:97
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2079
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:513
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2262
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Definition: DeclBase.h:513
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1134
A template argument list.
Definition: DeclTemplate.h:210
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize)
Definition: Expr.cpp:1854
static const Expr * skipTemporaryBindingsNoOpCastsAndParens(const Expr *E)
Skip over any no-op casts and any temporary-binding expressions.
Definition: Expr.cpp:2754
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition: Expr.cpp:3642
bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
isUnusedResultAWarning - Return true if this immediate expression should be warned about if the resul...
Definition: Expr.cpp:2132
void reserve(const ASTContext &C, unsigned N)
Definition: ASTVector.h:173
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Expression is a Null pointer constant built from a literal zero.
Definition: Expr.h:697
void Deallocate(void *Ptr) const
Definition: ASTContext.h:684
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:2554
CallingConv getCallConv() const
Definition: Type.h:3627
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
bool isVoidType() const
Definition: Type.h:6530
bool isSyntacticForm() const
Definition: Expr.h:4240
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
Definition: Decl.cpp:2981
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition: Expr.cpp:4210
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:3878
static bool hasAnyTypeDependentArguments(ArrayRef< Expr *> Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
Definition: Expr.cpp:2866
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr.type.conv]).
Definition: ExprCXX.h:1494
Expr * getRHS() const
Definition: Expr.h:3529
bool isPRValue() const
Definition: Expr.h:355
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:567
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Definition: Expr.h:214
bool isRValue() const
Definition: Expr.h:250
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:268
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to &#39;this&#39; in C++.
Definition: Expr.cpp:2822
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1570
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2372
bool isBuiltinAssumeFalse(const ASTContext &Ctx) const
Return true if this is a call to __assume() or __builtin_assume() with a non-value-dependent constant...
Definition: Expr.cpp:3041
Designator * getDesignator(unsigned Idx)
Definition: Expr.h:4531
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
Definition: Expr.cpp:1990
uint64_t Width
Definition: ASTContext.h:143
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:954
DeclAccessPair FoundDecl
The DeclAccessPair through which the MemberDecl was found due to name qualifiers. ...
Definition: Expr.h:2549
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2085
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: ASTVector.h:88
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1558
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1036
bool isUnion() const
Definition: Decl.h:3248
Expr * getRHS() const
Definition: Expr.h:3239
bool isPointerType() const
Definition: Type.h:6282
CallExprBitfields CallExprBits
Definition: Stmt.h:509
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:1911
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:4198
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:2741
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
Definition: Expr.cpp:2471
QualType getType() const
Definition: Decl.h:647
#define true
Definition: stdbool.h:32
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:114
unsigned getNumArgs() const
Definition: ExprCXX.h:1385
A trivial tuple used to represent a source range.
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to...
Definition: Expr.cpp:1177
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1387
This represents a decl that may have a name.
Definition: Decl.h:248
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type, member-designator).
Definition: Expr.h:2089
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2977
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:4502
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:3338
QualType getValueType() const
Definition: Expr.cpp:4203
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
Definition: Expr.cpp:882
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition: ExprObjC.h:1195
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3042
const LangOptions & getLangOpts() const
Definition: ASTContext.h:716
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Definition: DeclObjC.h:2491
IdentifierInfo * getFieldName() const
Definition: Expr.cpp:3807
This class handles loading and caching of source files into memory.
InitListExpr * getSyntacticForm() const
Definition: Expr.h:4243
Defines enum values for all the target-independent builtin functions.
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant()...
Definition: Expr.h:685
QualType getType() const
Return the type wrapped by this type source info.
Definition: Decl.h:97
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
Definition: Expr.cpp:2540
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
SourceRange getSourceRange() const LLVM_READONLY
Definition: Expr.h:4505