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