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