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