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