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