clang  19.0.0git
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/Expr.h"
14 #include "clang/AST/APValue.h"
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/Attr.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclObjC.h"
20 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/ExprCXX.h"
24 #include "clang/AST/IgnoreExpr.h"
25 #include "clang/AST/Mangle.h"
26 #include "clang/AST/RecordLayout.h"
27 #include "clang/AST/StmtVisitor.h"
28 #include "clang/Basic/Builtins.h"
29 #include "clang/Basic/CharInfo.h"
31 #include "clang/Basic/TargetInfo.h"
32 #include "clang/Lex/Lexer.h"
34 #include "clang/Lex/Preprocessor.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/Format.h"
37 #include "llvm/Support/raw_ostream.h"
38 #include <algorithm>
39 #include <cstring>
40 #include <optional>
41 using namespace clang;
42 
44  const Expr *E = this;
45  while (true) {
46  E = E->IgnoreParenBaseCasts();
47 
48  // Follow the RHS of a comma operator.
49  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
50  if (BO->getOpcode() == BO_Comma) {
51  E = BO->getRHS();
52  continue;
53  }
54  }
55 
56  // Step into initializer for materialized temporaries.
57  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
58  E = MTE->getSubExpr();
59  continue;
60  }
61 
62  break;
63  }
64 
65  return E;
66 }
67 
69  const Expr *E = getBestDynamicClassTypeExpr();
70  QualType DerivedType = E->getType();
71  if (const PointerType *PTy = DerivedType->getAs<PointerType>())
72  DerivedType = PTy->getPointeeType();
73 
74  if (DerivedType->isDependentType())
75  return nullptr;
76 
77  const RecordType *Ty = DerivedType->castAs<RecordType>();
78  Decl *D = Ty->getDecl();
79  return cast<CXXRecordDecl>(D);
80 }
81 
84  SmallVectorImpl<SubobjectAdjustment> &Adjustments) const {
85  const Expr *E = this;
86  while (true) {
87  E = E->IgnoreParens();
88 
89  if (const auto *CE = dyn_cast<CastExpr>(E)) {
90  if ((CE->getCastKind() == CK_DerivedToBase ||
91  CE->getCastKind() == CK_UncheckedDerivedToBase) &&
92  E->getType()->isRecordType()) {
93  E = CE->getSubExpr();
94  const auto *Derived =
95  cast<CXXRecordDecl>(E->getType()->castAs<RecordType>()->getDecl());
96  Adjustments.push_back(SubobjectAdjustment(CE, Derived));
97  continue;
98  }
99 
100  if (CE->getCastKind() == CK_NoOp) {
101  E = CE->getSubExpr();
102  continue;
103  }
104  } else if (const auto *ME = dyn_cast<MemberExpr>(E)) {
105  if (!ME->isArrow()) {
106  assert(ME->getBase()->getType()->getAsRecordDecl());
107  if (const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
108  if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
109  E = ME->getBase();
110  Adjustments.push_back(SubobjectAdjustment(Field));
111  continue;
112  }
113  }
114  }
115  } else if (const auto *BO = dyn_cast<BinaryOperator>(E)) {
116  if (BO->getOpcode() == BO_PtrMemD) {
117  assert(BO->getRHS()->isPRValue());
118  E = BO->getLHS();
119  const auto *MPT = BO->getRHS()->getType()->getAs<MemberPointerType>();
120  Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS()));
121  continue;
122  }
123  if (BO->getOpcode() == BO_Comma) {
124  CommaLHSs.push_back(BO->getLHS());
125  E = BO->getRHS();
126  continue;
127  }
128  }
129 
130  // Nothing changed.
131  break;
132  }
133  return E;
134 }
135 
136 bool Expr::isKnownToHaveBooleanValue(bool Semantic) const {
137  const Expr *E = IgnoreParens();
138 
139  // If this value has _Bool type, it is obvious 0/1.
140  if (E->getType()->isBooleanType()) return true;
141  // If this is a non-scalar-integer type, we don't care enough to try.
142  if (!E->getType()->isIntegralOrEnumerationType()) return false;
143 
144  if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
145  switch (UO->getOpcode()) {
146  case UO_Plus:
147  return UO->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
148  case UO_LNot:
149  return true;
150  default:
151  return false;
152  }
153  }
154 
155  // Only look through implicit casts. If the user writes
156  // '(int) (a && b)' treat it as an arbitrary int.
157  // FIXME: Should we look through any cast expression in !Semantic mode?
158  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
159  return CE->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
160 
161  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
162  switch (BO->getOpcode()) {
163  default: return false;
164  case BO_LT: // Relational operators.
165  case BO_GT:
166  case BO_LE:
167  case BO_GE:
168  case BO_EQ: // Equality operators.
169  case BO_NE:
170  case BO_LAnd: // AND operator.
171  case BO_LOr: // Logical OR operator.
172  return true;
173 
174  case BO_And: // Bitwise AND operator.
175  case BO_Xor: // Bitwise XOR operator.
176  case BO_Or: // Bitwise OR operator.
177  // Handle things like (x==2)|(y==12).
178  return BO->getLHS()->isKnownToHaveBooleanValue(Semantic) &&
179  BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
180 
181  case BO_Comma:
182  case BO_Assign:
183  return BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
184  }
185  }
186 
187  if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E))
188  return CO->getTrueExpr()->isKnownToHaveBooleanValue(Semantic) &&
189  CO->getFalseExpr()->isKnownToHaveBooleanValue(Semantic);
190 
191  if (isa<ObjCBoolLiteralExpr>(E))
192  return true;
193 
194  if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
195  return OVE->getSourceExpr()->isKnownToHaveBooleanValue(Semantic);
196 
197  if (const FieldDecl *FD = E->getSourceBitField())
198  if (!Semantic && FD->getType()->isUnsignedIntegerType() &&
199  !FD->getBitWidth()->isValueDependent() &&
200  FD->getBitWidthValue(FD->getASTContext()) == 1)
201  return true;
202 
203  return false;
204 }
205 
207  ASTContext &Ctx,
208  LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
209  bool IgnoreTemplateOrMacroSubstitution) const {
210  const Expr *E = IgnoreParens();
211  const Decl *D = nullptr;
212 
213  if (const auto *ME = dyn_cast<MemberExpr>(E))
214  D = ME->getMemberDecl();
215  else if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
216  D = DRE->getDecl();
217  else if (const auto *IRE = dyn_cast<ObjCIvarRefExpr>(E))
218  D = IRE->getDecl();
219 
220  return Decl::isFlexibleArrayMemberLike(Ctx, D, E->getType(),
221  StrictFlexArraysLevel,
222  IgnoreTemplateOrMacroSubstitution);
223 }
224 
225 const ValueDecl *
227  Expr::EvalResult Eval;
228 
229  if (EvaluateAsConstantExpr(Eval, Context)) {
230  APValue &Value = Eval.Val;
231 
232  if (Value.isMemberPointer())
233  return Value.getMemberPointerDecl();
234 
235  if (Value.isLValue() && Value.getLValueOffset().isZero())
236  return Value.getLValueBase().dyn_cast<const ValueDecl *>();
237  }
238 
239  return nullptr;
240 }
241 
242 // Amusing macro metaprogramming hack: check whether a class provides
243 // a more specific implementation of getExprLoc().
244 //
245 // See also Stmt.cpp:{getBeginLoc(),getEndLoc()}.
246 namespace {
247  /// This implementation is used when a class provides a custom
248  /// implementation of getExprLoc.
249  template <class E, class T>
250  SourceLocation getExprLocImpl(const Expr *expr,
251  SourceLocation (T::*v)() const) {
252  return static_cast<const E*>(expr)->getExprLoc();
253  }
254 
255  /// This implementation is used when a class doesn't provide
256  /// a custom implementation of getExprLoc. Overload resolution
257  /// should pick it over the implementation above because it's
258  /// more specialized according to function template partial ordering.
259  template <class E>
260  SourceLocation getExprLocImpl(const Expr *expr,
261  SourceLocation (Expr::*v)() const) {
262  return static_cast<const E *>(expr)->getBeginLoc();
263  }
264 }
265 
267  if (isa<EnumType>(getType()))
268  return getType();
269  if (const auto *ECD = getEnumConstantDecl()) {
270  const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
271  if (ED->isCompleteDefinition())
272  return Ctx.getTypeDeclType(ED);
273  }
274  return getType();
275 }
276 
278  switch (getStmtClass()) {
279  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
280 #define ABSTRACT_STMT(type)
281 #define STMT(type, base) \
282  case Stmt::type##Class: break;
283 #define EXPR(type, base) \
284  case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc);
285 #include "clang/AST/StmtNodes.inc"
286  }
287  llvm_unreachable("unknown expression kind");
288 }
289 
290 //===----------------------------------------------------------------------===//
291 // Primary Expressions.
292 //===----------------------------------------------------------------------===//
293 
298  "Invalid StorageKind Value");
299  (void)Kind;
300 }
301 
303  switch (Value.getKind()) {
304  case APValue::None:
307  case APValue::Int:
308  if (!Value.getInt().needsCleanup())
310  [[fallthrough]];
311  default:
313  }
314 }
315 
318  if (T->isIntegralOrEnumerationType() && Context.getTypeInfo(T).Width <= 64)
321 }
322 
323 ConstantExpr::ConstantExpr(Expr *SubExpr, ConstantResultStorageKind StorageKind,
324  bool IsImmediateInvocation)
325  : FullExpr(ConstantExprClass, SubExpr) {
326  ConstantExprBits.ResultKind = llvm::to_underlying(StorageKind);
327  ConstantExprBits.APValueKind = APValue::None;
328  ConstantExprBits.IsUnsigned = false;
329  ConstantExprBits.BitWidth = 0;
330  ConstantExprBits.HasCleanup = false;
331  ConstantExprBits.IsImmediateInvocation = IsImmediateInvocation;
332 
333  if (StorageKind == ConstantResultStorageKind::APValue)
334  ::new (getTrailingObjects<APValue>()) APValue();
335 }
336 
338  ConstantResultStorageKind StorageKind,
339  bool IsImmediateInvocation) {
340  assert(!isa<ConstantExpr>(E));
341  AssertResultStorageKind(StorageKind);
342 
343  unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
344  StorageKind == ConstantResultStorageKind::APValue,
345  StorageKind == ConstantResultStorageKind::Int64);
346  void *Mem = Context.Allocate(Size, alignof(ConstantExpr));
347  return new (Mem) ConstantExpr(E, StorageKind, IsImmediateInvocation);
348 }
349 
351  const APValue &Result) {
352  ConstantResultStorageKind StorageKind = getStorageKind(Result);
353  ConstantExpr *Self = Create(Context, E, StorageKind);
354  Self->SetResult(Result, Context);
355  return Self;
356 }
357 
358 ConstantExpr::ConstantExpr(EmptyShell Empty,
359  ConstantResultStorageKind StorageKind)
360  : FullExpr(ConstantExprClass, Empty) {
361  ConstantExprBits.ResultKind = llvm::to_underlying(StorageKind);
362 
363  if (StorageKind == ConstantResultStorageKind::APValue)
364  ::new (getTrailingObjects<APValue>()) APValue();
365 }
366 
368  ConstantResultStorageKind StorageKind) {
369  AssertResultStorageKind(StorageKind);
370 
371  unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
372  StorageKind == ConstantResultStorageKind::APValue,
373  StorageKind == ConstantResultStorageKind::Int64);
374  void *Mem = Context.Allocate(Size, alignof(ConstantExpr));
375  return new (Mem) ConstantExpr(EmptyShell(), StorageKind);
376 }
377 
379  assert((unsigned)getStorageKind(Value) <= ConstantExprBits.ResultKind &&
380  "Invalid storage for this value kind");
381  ConstantExprBits.APValueKind = Value.getKind();
382  switch (getResultStorageKind()) {
384  return;
386  Int64Result() = *Value.getInt().getRawData();
387  ConstantExprBits.BitWidth = Value.getInt().getBitWidth();
388  ConstantExprBits.IsUnsigned = Value.getInt().isUnsigned();
389  return;
391  if (!ConstantExprBits.HasCleanup && Value.needsCleanup()) {
392  ConstantExprBits.HasCleanup = true;
393  Context.addDestruction(&APValueResult());
394  }
395  APValueResult() = std::move(Value);
396  return;
397  }
398  llvm_unreachable("Invalid ResultKind Bits");
399 }
400 
402  switch (getResultStorageKind()) {
404  return APValueResult().getInt();
406  return llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
407  ConstantExprBits.IsUnsigned);
408  default:
409  llvm_unreachable("invalid Accessor");
410  }
411 }
412 
414 
415  switch (getResultStorageKind()) {
417  return APValueResult();
419  return APValue(
420  llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
421  ConstantExprBits.IsUnsigned));
423  if (ConstantExprBits.APValueKind == APValue::Indeterminate)
425  return APValue();
426  }
427  llvm_unreachable("invalid ResultKind");
428 }
429 
430 DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
431  bool RefersToEnclosingVariableOrCapture, QualType T,
433  const DeclarationNameLoc &LocInfo,
434  NonOdrUseReason NOUR)
435  : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D), DNLoc(LocInfo) {
436  DeclRefExprBits.HasQualifier = false;
437  DeclRefExprBits.HasTemplateKWAndArgsInfo = false;
438  DeclRefExprBits.HasFoundDecl = false;
439  DeclRefExprBits.HadMultipleCandidates = false;
440  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
441  RefersToEnclosingVariableOrCapture;
442  DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
443  DeclRefExprBits.NonOdrUseReason = NOUR;
444  DeclRefExprBits.IsImmediateEscalating = false;
445  DeclRefExprBits.Loc = L;
446  setDependence(computeDependence(this, Ctx));
447 }
448 
449 DeclRefExpr::DeclRefExpr(const ASTContext &Ctx,
450  NestedNameSpecifierLoc QualifierLoc,
451  SourceLocation TemplateKWLoc, ValueDecl *D,
452  bool RefersToEnclosingVariableOrCapture,
453  const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
454  const TemplateArgumentListInfo *TemplateArgs,
456  : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D),
457  DNLoc(NameInfo.getInfo()) {
458  DeclRefExprBits.Loc = NameInfo.getLoc();
459  DeclRefExprBits.HasQualifier = QualifierLoc ? 1 : 0;
460  if (QualifierLoc)
461  new (getTrailingObjects<NestedNameSpecifierLoc>())
462  NestedNameSpecifierLoc(QualifierLoc);
463  DeclRefExprBits.HasFoundDecl = FoundD ? 1 : 0;
464  if (FoundD)
465  *getTrailingObjects<NamedDecl *>() = FoundD;
466  DeclRefExprBits.HasTemplateKWAndArgsInfo
467  = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0;
468  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
469  RefersToEnclosingVariableOrCapture;
470  DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
471  DeclRefExprBits.NonOdrUseReason = NOUR;
472  if (TemplateArgs) {
474  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
475  TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
476  Deps);
477  assert(!(Deps & TemplateArgumentDependence::Dependent) &&
478  "built a DeclRefExpr with dependent template args");
479  } else if (TemplateKWLoc.isValid()) {
480  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
481  TemplateKWLoc);
482  }
483  DeclRefExprBits.IsImmediateEscalating = false;
484  DeclRefExprBits.HadMultipleCandidates = 0;
485  setDependence(computeDependence(this, Ctx));
486 }
487 
489  NestedNameSpecifierLoc QualifierLoc,
490  SourceLocation TemplateKWLoc, ValueDecl *D,
491  bool RefersToEnclosingVariableOrCapture,
492  SourceLocation NameLoc, QualType T,
493  ExprValueKind VK, NamedDecl *FoundD,
494  const TemplateArgumentListInfo *TemplateArgs,
495  NonOdrUseReason NOUR) {
496  return Create(Context, QualifierLoc, TemplateKWLoc, D,
497  RefersToEnclosingVariableOrCapture,
498  DeclarationNameInfo(D->getDeclName(), NameLoc),
499  T, VK, FoundD, TemplateArgs, NOUR);
500 }
501 
503  NestedNameSpecifierLoc QualifierLoc,
504  SourceLocation TemplateKWLoc, ValueDecl *D,
505  bool RefersToEnclosingVariableOrCapture,
506  const DeclarationNameInfo &NameInfo,
508  NamedDecl *FoundD,
509  const TemplateArgumentListInfo *TemplateArgs,
510  NonOdrUseReason NOUR) {
511  // Filter out cases where the found Decl is the same as the value refenenced.
512  if (D == FoundD)
513  FoundD = nullptr;
514 
515  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
516  std::size_t Size =
517  totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
519  QualifierLoc ? 1 : 0, FoundD ? 1 : 0,
520  HasTemplateKWAndArgsInfo ? 1 : 0,
521  TemplateArgs ? TemplateArgs->size() : 0);
522 
523  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
524  return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D,
525  RefersToEnclosingVariableOrCapture, NameInfo,
526  FoundD, TemplateArgs, T, VK, NOUR);
527 }
528 
530  bool HasQualifier,
531  bool HasFoundDecl,
532  bool HasTemplateKWAndArgsInfo,
533  unsigned NumTemplateArgs) {
534  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
535  std::size_t Size =
536  totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
538  HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo,
539  NumTemplateArgs);
540  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
541  return new (Mem) DeclRefExpr(EmptyShell());
542 }
543 
545  D = NewD;
546  if (getType()->isUndeducedType())
547  setType(NewD->getType());
549 }
550 
552  if (hasQualifier())
553  return getQualifierLoc().getBeginLoc();
554  return getNameInfo().getBeginLoc();
555 }
558  return getRAngleLoc();
559  return getNameInfo().getEndLoc();
560 }
561 
562 SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(SourceLocation OpLoc,
563  SourceLocation LParen,
564  SourceLocation RParen,
565  QualType ResultTy,
566  TypeSourceInfo *TSI)
567  : Expr(SYCLUniqueStableNameExprClass, ResultTy, VK_PRValue, OK_Ordinary),
568  OpLoc(OpLoc), LParen(LParen), RParen(RParen) {
569  setTypeSourceInfo(TSI);
571 }
572 
573 SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(EmptyShell Empty,
574  QualType ResultTy)
575  : Expr(SYCLUniqueStableNameExprClass, ResultTy, VK_PRValue, OK_Ordinary) {}
576 
579  SourceLocation LParen, SourceLocation RParen,
580  TypeSourceInfo *TSI) {
581  QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst());
582  return new (Ctx)
583  SYCLUniqueStableNameExpr(OpLoc, LParen, RParen, ResultTy, TSI);
584 }
585 
588  QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst());
589  return new (Ctx) SYCLUniqueStableNameExpr(EmptyShell(), ResultTy);
590 }
591 
595 }
596 
597 static std::optional<unsigned>
599  if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
600  if (RD->isLambda())
601  return RD->getDeviceLambdaManglingNumber();
602  return std::nullopt;
603 }
604 
606  QualType Ty) {
607  std::unique_ptr<MangleContext> Ctx{ItaniumMangleContext::create(
608  Context, Context.getDiagnostics(), UniqueStableNameDiscriminator)};
609 
610  std::string Buffer;
611  Buffer.reserve(128);
612  llvm::raw_string_ostream Out(Buffer);
613  Ctx->mangleCanonicalTypeName(Ty, Out);
614 
615  return Out.str();
616 }
617 
618 SYCLUniqueStableIdExpr::SYCLUniqueStableIdExpr(EmptyShell Empty,
619  QualType ResultTy)
620  : Expr(SYCLUniqueStableIdExprClass, ResultTy, VK_PRValue, OK_Ordinary) {}
621 
622 SYCLUniqueStableIdExpr::SYCLUniqueStableIdExpr(SourceLocation OpLoc,
623  SourceLocation LParen,
624  SourceLocation RParen,
625  QualType ResultTy, Expr *E)
626  : Expr(SYCLUniqueStableIdExprClass, ResultTy, VK_PRValue, OK_Ordinary),
627  OpLoc(OpLoc), LParen(LParen), RParen(RParen), DRE(E) {
629 }
630 
632  SourceLocation OpLoc,
633  SourceLocation LParen,
634  SourceLocation RParen,
635  Expr *E) {
636  QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst());
637  return new (Ctx) SYCLUniqueStableIdExpr(OpLoc, LParen, RParen, ResultTy, E);
638 }
639 
642  QualType ResultTy = Ctx.getPointerType(Ctx.CharTy.withConst());
643  return new (Ctx) SYCLUniqueStableIdExpr(EmptyShell(), ResultTy);
644 }
645 
646 std::string SYCLUniqueStableIdExpr::ComputeName(ASTContext &Context) const {
647  assert(!isInstantiationDependent() &&
648  "Can't compute name of uninstantiated value");
649 
650  auto *DR = cast<DeclRefExpr>(getExpr()->IgnoreUnlessSpelledInSource());
651  auto *VD = cast<VarDecl>(DR->getDecl());
652 
653  return ComputeName(Context, VD);
654 }
655 
657  const VarDecl *VD) {
658  std::unique_ptr<MangleContext> Ctx{ItaniumMangleContext::create(
659  Context, Context.getDiagnostics(), UniqueStableNameDiscriminator)};
660 
661  std::string Buffer;
662  Buffer.reserve(128);
663  llvm::raw_string_ostream Out(Buffer);
664  Ctx->mangleName(GlobalDecl{VD}, Out);
665 
666  if (VD->isExternallyVisible())
667  return Out.str();
668 
669  return Context.getLangOpts().SYCLUniquePrefix + "___" + Out.str();
670 }
671 
672 PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy,
673  PredefinedIdentKind IK, bool IsTransparent,
674  StringLiteral *SL)
675  : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary) {
676  PredefinedExprBits.Kind = llvm::to_underlying(IK);
677  assert((getIdentKind() == IK) &&
678  "IdentKind do not fit in PredefinedExprBitfields!");
679  bool HasFunctionName = SL != nullptr;
680  PredefinedExprBits.HasFunctionName = HasFunctionName;
681  PredefinedExprBits.IsTransparent = IsTransparent;
682  PredefinedExprBits.Loc = L;
683  if (HasFunctionName)
684  setFunctionName(SL);
686 }
687 
688 PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName)
689  : Expr(PredefinedExprClass, Empty) {
690  PredefinedExprBits.HasFunctionName = HasFunctionName;
691 }
692 
694  QualType FNTy, PredefinedIdentKind IK,
695  bool IsTransparent, StringLiteral *SL) {
696  bool HasFunctionName = SL != nullptr;
697  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
698  alignof(PredefinedExpr));
699  return new (Mem) PredefinedExpr(L, FNTy, IK, IsTransparent, SL);
700 }
701 
703  bool HasFunctionName) {
704  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
705  alignof(PredefinedExpr));
706  return new (Mem) PredefinedExpr(EmptyShell(), HasFunctionName);
707 }
708 
710  switch (IK) {
712  return "__func__";
714  return "__FUNCTION__";
716  return "__FUNCDNAME__";
718  return "L__FUNCTION__";
720  return "__PRETTY_FUNCTION__";
722  return "__FUNCSIG__";
724  return "L__FUNCSIG__";
726  break;
727  }
728  llvm_unreachable("Unknown ident kind for PredefinedExpr");
729 }
730 
731 // FIXME: Maybe this should use DeclPrinter with a special "print predefined
732 // expr" policy instead.
734  const Decl *CurrentDecl,
735  bool ForceElaboratedPrinting) {
736  ASTContext &Context = CurrentDecl->getASTContext();
737 
738  if (IK == PredefinedIdentKind::FuncDName) {
739  if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
740  std::unique_ptr<MangleContext> MC;
741  MC.reset(Context.createMangleContext());
742 
743  if (MC->shouldMangleDeclName(ND)) {
744  SmallString<256> Buffer;
745  llvm::raw_svector_ostream Out(Buffer);
746  GlobalDecl GD;
747  if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND))
748  GD = GlobalDecl(CD, Ctor_Base);
749  else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND))
750  GD = GlobalDecl(DD, Dtor_Base);
751  else if (ND->hasAttr<CUDAGlobalAttr>())
752  GD = GlobalDecl(cast<FunctionDecl>(ND));
753  else
754  GD = GlobalDecl(ND);
755  MC->mangleName(GD, Out);
756 
757  if (!Buffer.empty() && Buffer.front() == '\01')
758  return std::string(Buffer.substr(1));
759  return std::string(Buffer);
760  }
761  return std::string(ND->getIdentifier()->getName());
762  }
763  return "";
764  }
765  if (isa<BlockDecl>(CurrentDecl)) {
766  // For blocks we only emit something if it is enclosed in a function
767  // For top-level block we'd like to include the name of variable, but we
768  // don't have it at this point.
769  auto DC = CurrentDecl->getDeclContext();
770  if (DC->isFileContext())
771  return "";
772 
773  SmallString<256> Buffer;
774  llvm::raw_svector_ostream Out(Buffer);
775  if (auto *DCBlock = dyn_cast<BlockDecl>(DC))
776  // For nested blocks, propagate up to the parent.
777  Out << ComputeName(IK, DCBlock);
778  else if (auto *DCDecl = dyn_cast<Decl>(DC))
779  Out << ComputeName(IK, DCDecl) << "_block_invoke";
780  return std::string(Out.str());
781  }
782  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
783  const auto &LO = Context.getLangOpts();
784  bool IsFuncOrFunctionInNonMSVCCompatEnv =
785  ((IK == PredefinedIdentKind::Func ||
787  !LO.MSVCCompat);
788  bool IsLFunctionInMSVCCommpatEnv =
789  IK == PredefinedIdentKind::LFunction && LO.MSVCCompat;
790  bool IsFuncOrFunctionOrLFunctionOrFuncDName =
795  if ((ForceElaboratedPrinting &&
796  (IsFuncOrFunctionInNonMSVCCompatEnv || IsLFunctionInMSVCCommpatEnv)) ||
797  (!ForceElaboratedPrinting && IsFuncOrFunctionOrLFunctionOrFuncDName))
798  return FD->getNameAsString();
799 
800  SmallString<256> Name;
801  llvm::raw_svector_ostream Out(Name);
802 
803  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
804  if (MD->isVirtual() && IK != PredefinedIdentKind::PrettyFunctionNoVirtual)
805  Out << "virtual ";
806  if (MD->isStatic())
807  Out << "static ";
808  }
809 
810  class PrettyCallbacks final : public PrintingCallbacks {
811  public:
812  PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
813  std::string remapPath(StringRef Path) const override {
814  SmallString<128> p(Path);
815  LO.remapPathPrefix(p);
816  return std::string(p);
817  }
818 
819  private:
820  const LangOptions &LO;
821  };
822  PrintingPolicy Policy(Context.getLangOpts());
823  PrettyCallbacks PrettyCB(Context.getLangOpts());
824  Policy.Callbacks = &PrettyCB;
825  if (IK == PredefinedIdentKind::Function && ForceElaboratedPrinting)
826  Policy.SuppressTagKeyword = !LO.MSVCCompat;
827  std::string Proto;
828  llvm::raw_string_ostream POut(Proto);
829 
830  const FunctionDecl *Decl = FD;
831  if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
832  Decl = Pattern;
833  const FunctionType *AFT = Decl->getType()->getAs<FunctionType>();
834  const FunctionProtoType *FT = nullptr;
835  if (FD->hasWrittenPrototype())
836  FT = dyn_cast<FunctionProtoType>(AFT);
837 
838  if (IK == PredefinedIdentKind::FuncSig ||
840  switch (AFT->getCallConv()) {
841  case CC_C: POut << "__cdecl "; break;
842  case CC_X86StdCall: POut << "__stdcall "; break;
843  case CC_X86FastCall: POut << "__fastcall "; break;
844  case CC_X86ThisCall: POut << "__thiscall "; break;
845  case CC_X86VectorCall: POut << "__vectorcall "; break;
846  case CC_X86RegCall: POut << "__regcall "; break;
847  // Only bother printing the conventions that MSVC knows about.
848  default: break;
849  }
850  }
851 
852  FD->printQualifiedName(POut, Policy);
853 
854  if (IK == PredefinedIdentKind::Function) {
855  POut.flush();
856  Out << Proto;
857  return std::string(Name);
858  }
859 
860  POut << "(";
861  if (FT) {
862  for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
863  if (i) POut << ", ";
864  POut << Decl->getParamDecl(i)->getType().stream(Policy);
865  }
866 
867  if (FT->isVariadic()) {
868  if (FD->getNumParams()) POut << ", ";
869  POut << "...";
870  } else if ((IK == PredefinedIdentKind::FuncSig ||
872  !Context.getLangOpts().CPlusPlus) &&
873  !Decl->getNumParams()) {
874  POut << "void";
875  }
876  }
877  POut << ")";
878 
879  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
880  assert(FT && "We must have a written prototype in this case.");
881  if (FT->isConst())
882  POut << " const";
883  if (FT->isVolatile())
884  POut << " volatile";
885  RefQualifierKind Ref = MD->getRefQualifier();
886  if (Ref == RQ_LValue)
887  POut << " &";
888  else if (Ref == RQ_RValue)
889  POut << " &&";
890  }
891 
893  SpecsTy Specs;
894  const DeclContext *Ctx = FD->getDeclContext();
895  while (Ctx && isa<NamedDecl>(Ctx)) {
897  = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
898  if (Spec && !Spec->isExplicitSpecialization())
899  Specs.push_back(Spec);
900  Ctx = Ctx->getParent();
901  }
902 
903  std::string TemplateParams;
904  llvm::raw_string_ostream TOut(TemplateParams);
905  for (const ClassTemplateSpecializationDecl *D : llvm::reverse(Specs)) {
906  const TemplateParameterList *Params =
907  D->getSpecializedTemplate()->getTemplateParameters();
908  const TemplateArgumentList &Args = D->getTemplateArgs();
909  assert(Params->size() == Args.size());
910  for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) {
911  StringRef Param = Params->getParam(i)->getName();
912  if (Param.empty()) continue;
913  TOut << Param << " = ";
914  Args.get(i).print(Policy, TOut,
916  Policy, Params, i));
917  TOut << ", ";
918  }
919  }
920 
922  = FD->getTemplateSpecializationInfo();
923  if (FSI && !FSI->isExplicitSpecialization()) {
924  const TemplateParameterList* Params
926  const TemplateArgumentList* Args = FSI->TemplateArguments;
927  assert(Params->size() == Args->size());
928  for (unsigned i = 0, e = Params->size(); i != e; ++i) {
929  StringRef Param = Params->getParam(i)->getName();
930  if (Param.empty()) continue;
931  TOut << Param << " = ";
932  Args->get(i).print(Policy, TOut, /*IncludeType*/ true);
933  TOut << ", ";
934  }
935  }
936 
937  TOut.flush();
938  if (!TemplateParams.empty()) {
939  // remove the trailing comma and space
940  TemplateParams.resize(TemplateParams.size() - 2);
941  POut << " [" << TemplateParams << "]";
942  }
943 
944  POut.flush();
945 
946  // Print "auto" for all deduced return types. This includes C++1y return
947  // type deduction and lambdas. For trailing return types resolve the
948  // decltype expression. Otherwise print the real type when this is
949  // not a constructor or destructor.
950  if (isa<CXXMethodDecl>(FD) &&
951  cast<CXXMethodDecl>(FD)->getParent()->isLambda())
952  Proto = "auto " + Proto;
953  else if (FT && FT->getReturnType()->getAs<DecltypeType>())
954  FT->getReturnType()
955  ->getAs<DecltypeType>()
957  .getAsStringInternal(Proto, Policy);
958  else if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
959  AFT->getReturnType().getAsStringInternal(Proto, Policy);
960 
961  Out << Proto;
962 
963  return std::string(Name);
964  }
965  if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) {
966  for (const DeclContext *DC = CD->getParent(); DC; DC = DC->getParent())
967  // Skip to its enclosing function or method, but not its enclosing
968  // CapturedDecl.
969  if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) {
970  const Decl *D = Decl::castFromDeclContext(DC);
971  return ComputeName(IK, D);
972  }
973  llvm_unreachable("CapturedDecl not inside a function or method");
974  }
975  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
976  SmallString<256> Name;
977  llvm::raw_svector_ostream Out(Name);
978  Out << (MD->isInstanceMethod() ? '-' : '+');
979  Out << '[';
980 
981  // For incorrect code, there might not be an ObjCInterfaceDecl. Do
982  // a null check to avoid a crash.
983  if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
984  Out << *ID;
985 
986  if (const ObjCCategoryImplDecl *CID =
987  dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext()))
988  Out << '(' << *CID << ')';
989 
990  Out << ' ';
991  MD->getSelector().print(Out);
992  Out << ']';
993 
994  return std::string(Name);
995  }
996  if (isa<TranslationUnitDecl>(CurrentDecl) &&
998  // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string.
999  return "top level";
1000  }
1001  return "";
1002 }
1003 
1005  const llvm::APInt &Val) {
1006  if (hasAllocation())
1007  C.Deallocate(pVal);
1008 
1009  BitWidth = Val.getBitWidth();
1010  unsigned NumWords = Val.getNumWords();
1011  const uint64_t* Words = Val.getRawData();
1012  if (NumWords > 1) {
1013  pVal = new (C) uint64_t[NumWords];
1014  std::copy(Words, Words + NumWords, pVal);
1015  } else if (NumWords == 1)
1016  VAL = Words[0];
1017  else
1018  VAL = 0;
1019 }
1020 
1021 IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V,
1023  : Expr(IntegerLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l) {
1024  assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
1025  assert(V.getBitWidth() == C.getIntWidth(type) &&
1026  "Integer type is not the correct size for constant.");
1027  setValue(C, V);
1029 }
1030 
1034  return new (C) IntegerLiteral(C, V, type, l);
1035 }
1036 
1039  return new (C) IntegerLiteral(Empty);
1040 }
1041 
1042 FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V,
1044  unsigned Scale)
1045  : Expr(FixedPointLiteralClass, type, VK_PRValue, OK_Ordinary), Loc(l),
1046  Scale(Scale) {
1047  assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral");
1048  assert(V.getBitWidth() == C.getTypeInfo(type).Width &&
1049  "Fixed point type is not the correct size for constant.");
1050  setValue(C, V);
1052 }
1053 
1055  const llvm::APInt &V,
1056  QualType type,
1057  SourceLocation l,
1058  unsigned Scale) {
1059  return new (C) FixedPointLiteral(C, V, type, l, Scale);
1060 }
1061 
1063  EmptyShell Empty) {
1064  return new (C) FixedPointLiteral(Empty);
1065 }
1066 
1067 std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
1068  // Currently the longest decimal number that can be printed is the max for an
1069  // unsigned long _Accum: 4294967295.99999999976716935634613037109375
1070  // which is 43 characters.
1071  SmallString<64> S;
1073  S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale);
1074  return std::string(S);
1075 }
1076 
1078  raw_ostream &OS) {
1079  switch (Kind) {
1081  break; // no prefix.
1083  OS << 'L';
1084  break;
1086  OS << "u8";
1087  break;
1089  OS << 'u';
1090  break;
1092  OS << 'U';
1093  break;
1094  }
1095 
1096  StringRef Escaped = escapeCStyle<EscapeChar::Single>(Val);
1097  if (!Escaped.empty()) {
1098  OS << "'" << Escaped << "'";
1099  } else {
1100  // A character literal might be sign-extended, which
1101  // would result in an invalid \U escape sequence.
1102  // FIXME: multicharacter literals such as '\xFF\xFF\xFF\xFF'
1103  // are not correctly handled.
1104  if ((Val & ~0xFFu) == ~0xFFu && Kind == CharacterLiteralKind::Ascii)
1105  Val &= 0xFFu;
1106  if (Val < 256 && isPrintable((unsigned char)Val))
1107  OS << "'" << (char)Val << "'";
1108  else if (Val < 256)
1109  OS << "'\\x" << llvm::format("%02x", Val) << "'";
1110  else if (Val <= 0xFFFF)
1111  OS << "'\\u" << llvm::format("%04x", Val) << "'";
1112  else
1113  OS << "'\\U" << llvm::format("%08x", Val) << "'";
1114  }
1115 }
1116 
1117 FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V,
1118  bool isexact, QualType Type, SourceLocation L)
1119  : Expr(FloatingLiteralClass, Type, VK_PRValue, OK_Ordinary), Loc(L) {
1120  setSemantics(V.getSemantics());
1121  FloatingLiteralBits.IsExact = isexact;
1122  setValue(C, V);
1124 }
1125 
1126 FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty)
1127  : Expr(FloatingLiteralClass, Empty) {
1128  setRawSemantics(llvm::APFloatBase::S_IEEEhalf);
1129  FloatingLiteralBits.IsExact = false;
1130 }
1131 
1134  bool isexact, QualType Type, SourceLocation L) {
1135  return new (C) FloatingLiteral(C, V, isexact, Type, L);
1136 }
1137 
1140  return new (C) FloatingLiteral(C, Empty);
1141 }
1142 
1143 /// getValueAsApproximateDouble - This returns the value as an inaccurate
1144 /// double. Note that this may cause loss of precision, but is useful for
1145 /// debugging dumps, etc.
1147  llvm::APFloat V = getValue();
1148  bool ignored;
1149  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
1150  &ignored);
1151  return V.convertToDouble();
1152 }
1153 
1154 unsigned StringLiteral::mapCharByteWidth(TargetInfo const &Target,
1155  StringLiteralKind SK) {
1156  unsigned CharByteWidth = 0;
1157  switch (SK) {
1160  CharByteWidth = Target.getCharWidth();
1161  break;
1163  CharByteWidth = Target.getWCharWidth();
1164  break;
1166  CharByteWidth = Target.getChar16Width();
1167  break;
1169  CharByteWidth = Target.getChar32Width();
1170  break;
1172  return sizeof(char); // Host;
1173  }
1174  assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple");
1175  CharByteWidth /= 8;
1176  assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
1177  "The only supported character byte widths are 1,2 and 4!");
1178  return CharByteWidth;
1179 }
1180 
1181 StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str,
1182  StringLiteralKind Kind, bool Pascal, QualType Ty,
1183  const SourceLocation *Loc,
1184  unsigned NumConcatenated)
1185  : Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary) {
1186 
1187  unsigned Length = Str.size();
1188 
1189  StringLiteralBits.Kind = llvm::to_underlying(Kind);
1190  StringLiteralBits.NumConcatenated = NumConcatenated;
1191 
1193  assert(Ctx.getAsConstantArrayType(Ty) &&
1194  "StringLiteral must be of constant array type!");
1195  unsigned CharByteWidth = mapCharByteWidth(Ctx.getTargetInfo(), Kind);
1196  unsigned ByteLength = Str.size();
1197  assert((ByteLength % CharByteWidth == 0) &&
1198  "The size of the data must be a multiple of CharByteWidth!");
1199 
1200  // Avoid the expensive division. The compiler should be able to figure it
1201  // out by itself. However as of clang 7, even with the appropriate
1202  // llvm_unreachable added just here, it is not able to do so.
1203  switch (CharByteWidth) {
1204  case 1:
1205  Length = ByteLength;
1206  break;
1207  case 2:
1208  Length = ByteLength / 2;
1209  break;
1210  case 4:
1211  Length = ByteLength / 4;
1212  break;
1213  default:
1214  llvm_unreachable("Unsupported character width!");
1215  }
1216 
1217  StringLiteralBits.CharByteWidth = CharByteWidth;
1218  StringLiteralBits.IsPascal = Pascal;
1219  } else {
1220  assert(!Pascal && "Can't make an unevaluated Pascal string");
1221  StringLiteralBits.CharByteWidth = 1;
1222  StringLiteralBits.IsPascal = false;
1223  }
1224 
1225  *getTrailingObjects<unsigned>() = Length;
1226 
1227  // Initialize the trailing array of SourceLocation.
1228  // This is safe since SourceLocation is POD-like.
1229  std::memcpy(getTrailingObjects<SourceLocation>(), Loc,
1230  NumConcatenated * sizeof(SourceLocation));
1231 
1232  // Initialize the trailing array of char holding the string data.
1233  std::memcpy(getTrailingObjects<char>(), Str.data(), Str.size());
1234 
1236 }
1237 
1238 StringLiteral::StringLiteral(EmptyShell Empty, unsigned NumConcatenated,
1239  unsigned Length, unsigned CharByteWidth)
1240  : Expr(StringLiteralClass, Empty) {
1241  StringLiteralBits.CharByteWidth = CharByteWidth;
1242  StringLiteralBits.NumConcatenated = NumConcatenated;
1243  *getTrailingObjects<unsigned>() = Length;
1244 }
1245 
1247  StringLiteralKind Kind, bool Pascal,
1248  QualType Ty, const SourceLocation *Loc,
1249  unsigned NumConcatenated) {
1250  void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1251  1, NumConcatenated, Str.size()),
1252  alignof(StringLiteral));
1253  return new (Mem)
1254  StringLiteral(Ctx, Str, Kind, Pascal, Ty, Loc, NumConcatenated);
1255 }
1256 
1258  unsigned NumConcatenated,
1259  unsigned Length,
1260  unsigned CharByteWidth) {
1261  void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1262  1, NumConcatenated, Length * CharByteWidth),
1263  alignof(StringLiteral));
1264  return new (Mem)
1265  StringLiteral(EmptyShell(), NumConcatenated, Length, CharByteWidth);
1266 }
1267 
1268 void StringLiteral::outputString(raw_ostream &OS) const {
1269  switch (getKind()) {
1272  break; // no prefix.
1274  OS << 'L';
1275  break;
1277  OS << "u8";
1278  break;
1280  OS << 'u';
1281  break;
1283  OS << 'U';
1284  break;
1285  }
1286  OS << '"';
1287  static const char Hex[] = "0123456789ABCDEF";
1288 
1289  unsigned LastSlashX = getLength();
1290  for (unsigned I = 0, N = getLength(); I != N; ++I) {
1291  uint32_t Char = getCodeUnit(I);
1292  StringRef Escaped = escapeCStyle<EscapeChar::Double>(Char);
1293  if (Escaped.empty()) {
1294  // FIXME: Convert UTF-8 back to codepoints before rendering.
1295 
1296  // Convert UTF-16 surrogate pairs back to codepoints before rendering.
1297  // Leave invalid surrogates alone; we'll use \x for those.
1298  if (getKind() == StringLiteralKind::UTF16 && I != N - 1 &&
1299  Char >= 0xd800 && Char <= 0xdbff) {
1300  uint32_t Trail = getCodeUnit(I + 1);
1301  if (Trail >= 0xdc00 && Trail <= 0xdfff) {
1302  Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00);
1303  ++I;
1304  }
1305  }
1306 
1307  if (Char > 0xff) {
1308  // If this is a wide string, output characters over 0xff using \x
1309  // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a
1310  // codepoint: use \x escapes for invalid codepoints.
1311  if (getKind() == StringLiteralKind::Wide ||
1312  (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) {
1313  // FIXME: Is this the best way to print wchar_t?
1314  OS << "\\x";
1315  int Shift = 28;
1316  while ((Char >> Shift) == 0)
1317  Shift -= 4;
1318  for (/**/; Shift >= 0; Shift -= 4)
1319  OS << Hex[(Char >> Shift) & 15];
1320  LastSlashX = I;
1321  continue;
1322  }
1323 
1324  if (Char > 0xffff)
1325  OS << "\\U00"
1326  << Hex[(Char >> 20) & 15]
1327  << Hex[(Char >> 16) & 15];
1328  else
1329  OS << "\\u";
1330  OS << Hex[(Char >> 12) & 15]
1331  << Hex[(Char >> 8) & 15]
1332  << Hex[(Char >> 4) & 15]
1333  << Hex[(Char >> 0) & 15];
1334  continue;
1335  }
1336 
1337  // If we used \x... for the previous character, and this character is a
1338  // hexadecimal digit, prevent it being slurped as part of the \x.
1339  if (LastSlashX + 1 == I) {
1340  switch (Char) {
1341  case '0': case '1': case '2': case '3': case '4':
1342  case '5': case '6': case '7': case '8': case '9':
1343  case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1344  case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1345  OS << "\"\"";
1346  }
1347  }
1348 
1349  assert(Char <= 0xff &&
1350  "Characters above 0xff should already have been handled.");
1351 
1352  if (isPrintable(Char))
1353  OS << (char)Char;
1354  else // Output anything hard as an octal escape.
1355  OS << '\\'
1356  << (char)('0' + ((Char >> 6) & 7))
1357  << (char)('0' + ((Char >> 3) & 7))
1358  << (char)('0' + ((Char >> 0) & 7));
1359  } else {
1360  // Handle some common non-printable cases to make dumps prettier.
1361  OS << Escaped;
1362  }
1363  }
1364  OS << '"';
1365 }
1366 
1367 /// getLocationOfByte - Return a source location that points to the specified
1368 /// byte of this string literal.
1369 ///
1370 /// Strings are amazingly complex. They can be formed from multiple tokens and
1371 /// can have escape sequences in them in addition to the usual trigraph and
1372 /// escaped newline business. This routine handles this complexity.
1373 ///
1374 /// The *StartToken sets the first token to be searched in this function and
1375 /// the *StartTokenByteOffset is the byte offset of the first token. Before
1376 /// returning, it updates the *StartToken to the TokNo of the token being found
1377 /// and sets *StartTokenByteOffset to the byte offset of the token in the
1378 /// string.
1379 /// Using these two parameters can reduce the time complexity from O(n^2) to
1380 /// O(n) if one wants to get the location of byte for all the tokens in a
1381 /// string.
1382 ///
1385  const LangOptions &Features,
1386  const TargetInfo &Target, unsigned *StartToken,
1387  unsigned *StartTokenByteOffset) const {
1388  assert((getKind() == StringLiteralKind::Ordinary ||
1391  "Only narrow string literals are currently supported");
1392 
1393  // Loop over all of the tokens in this string until we find the one that
1394  // contains the byte we're looking for.
1395  unsigned TokNo = 0;
1396  unsigned StringOffset = 0;
1397  if (StartToken)
1398  TokNo = *StartToken;
1399  if (StartTokenByteOffset) {
1400  StringOffset = *StartTokenByteOffset;
1401  ByteNo -= StringOffset;
1402  }
1403  while (true) {
1404  assert(TokNo < getNumConcatenated() && "Invalid byte number!");
1405  SourceLocation StrTokLoc = getStrTokenLoc(TokNo);
1406 
1407  // Get the spelling of the string so that we can get the data that makes up
1408  // the string literal, not the identifier for the macro it is potentially
1409  // expanded through.
1410  SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc);
1411 
1412  // Re-lex the token to get its length and original spelling.
1413  std::pair<FileID, unsigned> LocInfo =
1414  SM.getDecomposedLoc(StrTokSpellingLoc);
1415  bool Invalid = false;
1416  StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
1417  if (Invalid) {
1418  if (StartTokenByteOffset != nullptr)
1419  *StartTokenByteOffset = StringOffset;
1420  if (StartToken != nullptr)
1421  *StartToken = TokNo;
1422  return StrTokSpellingLoc;
1423  }
1424 
1425  const char *StrData = Buffer.data()+LocInfo.second;
1426 
1427  // Create a lexer starting at the beginning of this token.
1428  Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features,
1429  Buffer.begin(), StrData, Buffer.end());
1430  Token TheTok;
1431  TheLexer.LexFromRawLexer(TheTok);
1432 
1433  // Use the StringLiteralParser to compute the length of the string in bytes.
1434  StringLiteralParser SLP(TheTok, SM, Features, Target);
1435  unsigned TokNumBytes = SLP.GetStringLength();
1436 
1437  // If the byte is in this token, return the location of the byte.
1438  if (ByteNo < TokNumBytes ||
1439  (ByteNo == TokNumBytes && TokNo == getNumConcatenated() - 1)) {
1440  unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo);
1441 
1442  // Now that we know the offset of the token in the spelling, use the
1443  // preprocessor to get the offset in the original source.
1444  if (StartTokenByteOffset != nullptr)
1445  *StartTokenByteOffset = StringOffset;
1446  if (StartToken != nullptr)
1447  *StartToken = TokNo;
1448  return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features);
1449  }
1450 
1451  // Move to the next string token.
1452  StringOffset += TokNumBytes;
1453  ++TokNo;
1454  ByteNo -= TokNumBytes;
1455  }
1456 }
1457 
1458 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1459 /// corresponds to, e.g. "sizeof" or "[pre]++".
1461  switch (Op) {
1462 #define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
1463 #include "clang/AST/OperationKinds.def"
1464  }
1465  llvm_unreachable("Unknown unary operator");
1466 }
1467 
1470  switch (OO) {
1471  default: llvm_unreachable("No unary operator for overloaded function");
1472  case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc;
1473  case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec;
1474  case OO_Amp: return UO_AddrOf;
1475  case OO_Star: return UO_Deref;
1476  case OO_Plus: return UO_Plus;
1477  case OO_Minus: return UO_Minus;
1478  case OO_Tilde: return UO_Not;
1479  case OO_Exclaim: return UO_LNot;
1480  case OO_Coawait: return UO_Coawait;
1481  }
1482 }
1483 
1485  switch (Opc) {
1486  case UO_PostInc: case UO_PreInc: return OO_PlusPlus;
1487  case UO_PostDec: case UO_PreDec: return OO_MinusMinus;
1488  case UO_AddrOf: return OO_Amp;
1489  case UO_Deref: return OO_Star;
1490  case UO_Plus: return OO_Plus;
1491  case UO_Minus: return OO_Minus;
1492  case UO_Not: return OO_Tilde;
1493  case UO_LNot: return OO_Exclaim;
1494  case UO_Coawait: return OO_Coawait;
1495  default: return OO_None;
1496  }
1497 }
1498 
1499 
1500 //===----------------------------------------------------------------------===//
1501 // Postfix Operators.
1502 //===----------------------------------------------------------------------===//
1503 
1506  SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
1507  unsigned MinNumArgs, ADLCallKind UsesADL)
1508  : Expr(SC, Ty, VK, OK_Ordinary), RParenLoc(RParenLoc) {
1509  NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1510  unsigned NumPreArgs = PreArgs.size();
1511  CallExprBits.NumPreArgs = NumPreArgs;
1512  assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1513 
1514  unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1515  CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1516  assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1517  "OffsetToTrailingObjects overflow!");
1518 
1519  CallExprBits.UsesADL = static_cast<bool>(UsesADL);
1520 
1521  setCallee(Fn);
1522  for (unsigned I = 0; I != NumPreArgs; ++I)
1523  setPreArg(I, PreArgs[I]);
1524  for (unsigned I = 0; I != Args.size(); ++I)
1525  setArg(I, Args[I]);
1526  for (unsigned I = Args.size(); I != NumArgs; ++I)
1527  setArg(I, nullptr);
1528 
1529  this->computeDependence();
1530 
1531  CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
1532  if (hasStoredFPFeatures())
1533  setStoredFPFeatures(FPFeatures);
1534 }
1535 
1536 CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
1537  bool HasFPFeatures, EmptyShell Empty)
1538  : Expr(SC, Empty), NumArgs(NumArgs) {
1539  CallExprBits.NumPreArgs = NumPreArgs;
1540  assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1541 
1542  unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1543  CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1544  assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1545  "OffsetToTrailingObjects overflow!");
1546  CallExprBits.HasFPFeatures = HasFPFeatures;
1547 }
1548 
1551  SourceLocation RParenLoc,
1552  FPOptionsOverride FPFeatures, unsigned MinNumArgs,
1553  ADLCallKind UsesADL) {
1554  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1555  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1556  /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
1557  void *Mem =
1558  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr));
1559  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
1560  RParenLoc, FPFeatures, MinNumArgs, UsesADL);
1561 }
1562 
1564  ExprValueKind VK, SourceLocation RParenLoc,
1565  ADLCallKind UsesADL) {
1566  assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) &&
1567  "Misaligned memory in CallExpr::CreateTemporary!");
1568  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty,
1569  VK, RParenLoc, FPOptionsOverride(),
1570  /*MinNumArgs=*/0, UsesADL);
1571 }
1572 
1573 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
1574  bool HasFPFeatures, EmptyShell Empty) {
1575  unsigned SizeOfTrailingObjects =
1576  CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
1577  void *Mem =
1578  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr));
1579  return new (Mem)
1580  CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
1581 }
1582 
1583 unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
1584  switch (SC) {
1585  case CallExprClass:
1586  return sizeof(CallExpr);
1587  case CXXOperatorCallExprClass:
1588  return sizeof(CXXOperatorCallExpr);
1589  case CXXMemberCallExprClass:
1590  return sizeof(CXXMemberCallExpr);
1591  case UserDefinedLiteralClass:
1592  return sizeof(UserDefinedLiteral);
1593  case CUDAKernelCallExprClass:
1594  return sizeof(CUDAKernelCallExpr);
1595  default:
1596  llvm_unreachable("unexpected class deriving from CallExpr!");
1597  }
1598 }
1599 
1601  Expr *CEE = IgnoreParenImpCasts();
1602 
1603  while (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE))
1604  CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
1605 
1606  // If we're calling a dereference, look at the pointer instead.
1607  while (true) {
1608  if (auto *BO = dyn_cast<BinaryOperator>(CEE)) {
1609  if (BO->isPtrMemOp()) {
1610  CEE = BO->getRHS()->IgnoreParenImpCasts();
1611  continue;
1612  }
1613  } else if (auto *UO = dyn_cast<UnaryOperator>(CEE)) {
1614  if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
1615  UO->getOpcode() == UO_Plus) {
1616  CEE = UO->getSubExpr()->IgnoreParenImpCasts();
1617  continue;
1618  }
1619  }
1620  break;
1621  }
1622 
1623  if (auto *DRE = dyn_cast<DeclRefExpr>(CEE))
1624  return DRE->getDecl();
1625  if (auto *ME = dyn_cast<MemberExpr>(CEE))
1626  return ME->getMemberDecl();
1627  if (auto *BE = dyn_cast<BlockExpr>(CEE))
1628  return BE->getBlockDecl();
1629 
1630  return nullptr;
1631 }
1632 
1633 /// If this is a call to a builtin, return the builtin ID. If not, return 0.
1634 unsigned CallExpr::getBuiltinCallee() const {
1635  const auto *FDecl = getDirectCallee();
1636  return FDecl ? FDecl->getBuiltinID() : 0;
1637 }
1638 
1640  if (unsigned BI = getBuiltinCallee())
1641  return Ctx.BuiltinInfo.isUnevaluated(BI);
1642  return false;
1643 }
1644 
1646  const Expr *Callee = getCallee();
1647  QualType CalleeType = Callee->getType();
1648  if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) {
1649  CalleeType = FnTypePtr->getPointeeType();
1650  } else if (const auto *BPT = CalleeType->getAs<BlockPointerType>()) {
1651  CalleeType = BPT->getPointeeType();
1652  } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) {
1653  if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens()))
1654  return Ctx.VoidTy;
1655 
1656  if (isa<UnresolvedMemberExpr>(Callee->IgnoreParens()))
1657  return Ctx.DependentTy;
1658 
1659  // This should never be overloaded and so should never return null.
1660  CalleeType = Expr::findBoundMemberType(Callee);
1661  assert(!CalleeType.isNull());
1662  } else if (CalleeType->isRecordType()) {
1663  // If the Callee is a record type, then it is a not-yet-resolved
1664  // dependent call to the call operator of that type.
1665  return Ctx.DependentTy;
1666  } else if (CalleeType->isDependentType() ||
1667  CalleeType->isSpecificPlaceholderType(BuiltinType::Overload)) {
1668  return Ctx.DependentTy;
1669  }
1670 
1671  const FunctionType *FnType = CalleeType->castAs<FunctionType>();
1672  return FnType->getReturnType();
1673 }
1674 
1676  // If the return type is a struct, union, or enum that is marked nodiscard,
1677  // then return the return type attribute.
1678  if (const TagDecl *TD = getCallReturnType(Ctx)->getAsTagDecl())
1679  if (const auto *A = TD->getAttr<WarnUnusedResultAttr>())
1680  return A;
1681 
1682  for (const auto *TD = getCallReturnType(Ctx)->getAs<TypedefType>(); TD;
1683  TD = TD->desugar()->getAs<TypedefType>())
1684  if (const auto *A = TD->getDecl()->getAttr<WarnUnusedResultAttr>())
1685  return A;
1686 
1687  // Otherwise, see if the callee is marked nodiscard and return that attribute
1688  // instead.
1689  const Decl *D = getCalleeDecl();
1690  return D ? D->getAttr<WarnUnusedResultAttr>() : nullptr;
1691 }
1692 
1694  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
1695  return OCE->getBeginLoc();
1696 
1697  SourceLocation begin = getCallee()->getBeginLoc();
1698  if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
1699  begin = getArg(0)->getBeginLoc();
1700  return begin;
1701 }
1703  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
1704  return OCE->getEndLoc();
1705 
1706  SourceLocation end = getRParenLoc();
1707  if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
1708  end = getArg(getNumArgs() - 1)->getEndLoc();
1709  return end;
1710 }
1711 
1713  SourceLocation OperatorLoc,
1714  TypeSourceInfo *tsi,
1715  ArrayRef<OffsetOfNode> comps,
1716  ArrayRef<Expr*> exprs,
1717  SourceLocation RParenLoc) {
1718  void *Mem = C.Allocate(
1719  totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size()));
1720 
1721  return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs,
1722  RParenLoc);
1723 }
1724 
1726  unsigned numComps, unsigned numExprs) {
1727  void *Mem =
1728  C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs));
1729  return new (Mem) OffsetOfExpr(numComps, numExprs);
1730 }
1731 
1732 OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type,
1733  SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1735  SourceLocation RParenLoc)
1736  : Expr(OffsetOfExprClass, type, VK_PRValue, OK_Ordinary),
1737  OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
1738  NumComps(comps.size()), NumExprs(exprs.size()) {
1739  for (unsigned i = 0; i != comps.size(); ++i)
1740  setComponent(i, comps[i]);
1741  for (unsigned i = 0; i != exprs.size(); ++i)
1742  setIndexExpr(i, exprs[i]);
1743 
1745 }
1746 
1748  assert(getKind() == Field || getKind() == Identifier);
1749  if (getKind() == Field)
1750  return getField()->getIdentifier();
1751 
1752  return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask);
1753 }
1754 
1756  UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType,
1758  : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_PRValue, OK_Ordinary),
1759  OpLoc(op), RParenLoc(rp) {
1760  assert(ExprKind <= UETT_Last && "invalid enum value!");
1761  UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1762  assert(static_cast<unsigned>(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind &&
1763  "UnaryExprOrTypeTraitExprBits.Kind overflow!");
1764  UnaryExprOrTypeTraitExprBits.IsType = false;
1765  Argument.Ex = E;
1767 }
1768 
1769 MemberExpr::MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
1770  NestedNameSpecifierLoc QualifierLoc,
1771  SourceLocation TemplateKWLoc, ValueDecl *MemberDecl,
1772  DeclAccessPair FoundDecl,
1773  const DeclarationNameInfo &NameInfo,
1774  const TemplateArgumentListInfo *TemplateArgs, QualType T,
1776  NonOdrUseReason NOUR)
1777  : Expr(MemberExprClass, T, VK, OK), Base(Base), MemberDecl(MemberDecl),
1778  MemberDNLoc(NameInfo.getInfo()), MemberLoc(NameInfo.getLoc()) {
1779  assert(!NameInfo.getName() ||
1780  MemberDecl->getDeclName() == NameInfo.getName());
1781  MemberExprBits.IsArrow = IsArrow;
1782  MemberExprBits.HasQualifier = QualifierLoc.hasQualifier();
1783  MemberExprBits.HasFoundDecl =
1784  FoundDecl.getDecl() != MemberDecl ||
1785  FoundDecl.getAccess() != MemberDecl->getAccess();
1786  MemberExprBits.HasTemplateKWAndArgsInfo =
1787  TemplateArgs || TemplateKWLoc.isValid();
1788  MemberExprBits.HadMultipleCandidates = false;
1789  MemberExprBits.NonOdrUseReason = NOUR;
1790  MemberExprBits.OperatorLoc = OperatorLoc;
1791 
1792  if (hasQualifier())
1793  new (getTrailingObjects<NestedNameSpecifierLoc>())
1794  NestedNameSpecifierLoc(QualifierLoc);
1795  if (hasFoundDecl())
1796  *getTrailingObjects<DeclAccessPair>() = FoundDecl;
1797  if (TemplateArgs) {
1799  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1800  TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1801  Deps);
1802  } else if (TemplateKWLoc.isValid()) {
1803  getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1804  TemplateKWLoc);
1805  }
1807 }
1808 
1810  const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
1811  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1812  ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
1813  DeclarationNameInfo NameInfo, const TemplateArgumentListInfo *TemplateArgs,
1815  bool HasQualifier = QualifierLoc.hasQualifier();
1816  bool HasFoundDecl = FoundDecl.getDecl() != MemberDecl ||
1817  FoundDecl.getAccess() != MemberDecl->getAccess();
1818  bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1819  std::size_t Size =
1820  totalSizeToAlloc<NestedNameSpecifierLoc, DeclAccessPair,
1822  HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1823  TemplateArgs ? TemplateArgs->size() : 0);
1824 
1825  void *Mem = C.Allocate(Size, alignof(MemberExpr));
1826  return new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, QualifierLoc,
1827  TemplateKWLoc, MemberDecl, FoundDecl, NameInfo,
1828  TemplateArgs, T, VK, OK, NOUR);
1829 }
1830 
1832  bool HasQualifier, bool HasFoundDecl,
1833  bool HasTemplateKWAndArgsInfo,
1834  unsigned NumTemplateArgs) {
1835  assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) &&
1836  "template args but no template arg info?");
1837  std::size_t Size =
1838  totalSizeToAlloc<NestedNameSpecifierLoc, DeclAccessPair,
1840  HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1841  NumTemplateArgs);
1842  void *Mem = Context.Allocate(Size, alignof(MemberExpr));
1843  return new (Mem) MemberExpr(EmptyShell());
1844 }
1845 
1847  MemberDecl = NewD;
1848  if (getType()->isUndeducedType())
1849  setType(NewD->getType());
1851 }
1852 
1854  if (isImplicitAccess()) {
1855  if (hasQualifier())
1856  return getQualifierLoc().getBeginLoc();
1857  return MemberLoc;
1858  }
1859 
1860  // FIXME: We don't want this to happen. Rather, we should be able to
1861  // detect all kinds of implicit accesses more cleanly.
1862  SourceLocation BaseStartLoc = getBase()->getBeginLoc();
1863  if (BaseStartLoc.isValid())
1864  return BaseStartLoc;
1865  return MemberLoc;
1866 }
1870  EndLoc = getRAngleLoc();
1871  else if (EndLoc.isInvalid())
1872  EndLoc = getBase()->getEndLoc();
1873  return EndLoc;
1874 }
1875 
1876 bool CastExpr::CastConsistency() const {
1877  switch (getCastKind()) {
1878  case CK_DerivedToBase:
1879  case CK_UncheckedDerivedToBase:
1880  case CK_DerivedToBaseMemberPointer:
1881  case CK_BaseToDerived:
1882  case CK_BaseToDerivedMemberPointer:
1883  assert(!path_empty() && "Cast kind should have a base path!");
1884  break;
1885 
1886  case CK_CPointerToObjCPointerCast:
1887  assert(getType()->isObjCObjectPointerType());
1888  assert(getSubExpr()->getType()->isPointerType());
1889  goto CheckNoBasePath;
1890 
1891  case CK_BlockPointerToObjCPointerCast:
1892  assert(getType()->isObjCObjectPointerType());
1893  assert(getSubExpr()->getType()->isBlockPointerType());
1894  goto CheckNoBasePath;
1895 
1896  case CK_ReinterpretMemberPointer:
1897  assert(getType()->isMemberPointerType());
1898  assert(getSubExpr()->getType()->isMemberPointerType());
1899  goto CheckNoBasePath;
1900 
1901  case CK_BitCast:
1902  // Arbitrary casts to C pointer types count as bitcasts.
1903  // Otherwise, we should only have block and ObjC pointer casts
1904  // here if they stay within the type kind.
1905  if (!getType()->isPointerType()) {
1906  assert(getType()->isObjCObjectPointerType() ==
1907  getSubExpr()->getType()->isObjCObjectPointerType());
1908  assert(getType()->isBlockPointerType() ==
1909  getSubExpr()->getType()->isBlockPointerType());
1910  }
1911  goto CheckNoBasePath;
1912 
1913  case CK_AnyPointerToBlockPointerCast:
1914  assert(getType()->isBlockPointerType());
1915  assert(getSubExpr()->getType()->isAnyPointerType() &&
1916  !getSubExpr()->getType()->isBlockPointerType());
1917  goto CheckNoBasePath;
1918 
1919  case CK_CopyAndAutoreleaseBlockObject:
1920  assert(getType()->isBlockPointerType());
1921  assert(getSubExpr()->getType()->isBlockPointerType());
1922  goto CheckNoBasePath;
1923 
1924  case CK_FunctionToPointerDecay:
1925  assert(getType()->isPointerType());
1926  assert(getSubExpr()->getType()->isFunctionType());
1927  goto CheckNoBasePath;
1928 
1929  case CK_AddressSpaceConversion: {
1930  auto Ty = getType();
1931  auto SETy = getSubExpr()->getType();
1932  assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
1933  if (isPRValue() && !Ty->isDependentType() && !SETy->isDependentType()) {
1934  Ty = Ty->getPointeeType();
1935  SETy = SETy->getPointeeType();
1936  }
1937  assert((Ty->isDependentType() || SETy->isDependentType()) ||
1938  (!Ty.isNull() && !SETy.isNull() &&
1939  Ty.getAddressSpace() != SETy.getAddressSpace()));
1940  goto CheckNoBasePath;
1941  }
1942  // These should not have an inheritance path.
1943  case CK_Dynamic:
1944  case CK_ToUnion:
1945  case CK_ArrayToPointerDecay:
1946  case CK_NullToMemberPointer:
1947  case CK_NullToPointer:
1948  case CK_ConstructorConversion:
1949  case CK_IntegralToPointer:
1950  case CK_PointerToIntegral:
1951  case CK_ToVoid:
1952  case CK_VectorSplat:
1953  case CK_IntegralCast:
1954  case CK_BooleanToSignedIntegral:
1955  case CK_IntegralToFloating:
1956  case CK_FloatingToIntegral:
1957  case CK_FloatingCast:
1958  case CK_ObjCObjectLValueCast:
1959  case CK_FloatingRealToComplex:
1960  case CK_FloatingComplexToReal:
1961  case CK_FloatingComplexCast:
1962  case CK_FloatingComplexToIntegralComplex:
1963  case CK_IntegralRealToComplex:
1964  case CK_IntegralComplexToReal:
1965  case CK_IntegralComplexCast:
1966  case CK_IntegralComplexToFloatingComplex:
1967  case CK_ARCProduceObject:
1968  case CK_ARCConsumeObject:
1969  case CK_ARCReclaimReturnedObject:
1970  case CK_ARCExtendBlockObject:
1971  case CK_ZeroToOCLOpaqueType:
1972  case CK_IntToOCLSampler:
1973  case CK_FloatingToFixedPoint:
1974  case CK_FixedPointToFloating:
1975  case CK_FixedPointCast:
1976  case CK_FixedPointToIntegral:
1977  case CK_IntegralToFixedPoint:
1978  case CK_MatrixCast:
1979  case CK_HLSLVectorTruncation:
1980  assert(!getType()->isBooleanType() && "unheralded conversion to bool");
1981  goto CheckNoBasePath;
1982 
1983  case CK_Dependent:
1984  case CK_LValueToRValue:
1985  case CK_NoOp:
1986  case CK_AtomicToNonAtomic:
1987  case CK_NonAtomicToAtomic:
1988  case CK_PointerToBoolean:
1989  case CK_IntegralToBoolean:
1990  case CK_FloatingToBoolean:
1991  case CK_MemberPointerToBoolean:
1992  case CK_FloatingComplexToBoolean:
1993  case CK_IntegralComplexToBoolean:
1994  case CK_LValueBitCast: // -> bool&
1995  case CK_LValueToRValueBitCast:
1996  case CK_UserDefinedConversion: // operator bool()
1997  case CK_BuiltinFnToFnPtr:
1998  case CK_FixedPointToBoolean:
1999  case CK_HLSLArrayRValue:
2000  CheckNoBasePath:
2001  assert(path_empty() && "Cast kind should not have a base path!");
2002  break;
2003  }
2004  return true;
2005 }
2006 
2008  switch (CK) {
2009 #define CAST_OPERATION(Name) case CK_##Name: return #Name;
2010 #include "clang/AST/OperationKinds.def"
2011  }
2012  llvm_unreachable("Unhandled cast kind!");
2013 }
2014 
2015 namespace {
2016 // Skip over implicit nodes produced as part of semantic analysis.
2017 // Designed for use with IgnoreExprNodes.
2018 static Expr *ignoreImplicitSemaNodes(Expr *E) {
2019  if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E))
2020  return Materialize->getSubExpr();
2021 
2022  if (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
2023  return Binder->getSubExpr();
2024 
2025  if (auto *Full = dyn_cast<FullExpr>(E))
2026  return Full->getSubExpr();
2027 
2028  if (auto *CPLIE = dyn_cast<CXXParenListInitExpr>(E);
2029  CPLIE && CPLIE->getInitExprs().size() == 1)
2030  return CPLIE->getInitExprs()[0];
2031 
2032  return E;
2033 }
2034 } // namespace
2035 
2037  const Expr *SubExpr = nullptr;
2038 
2039  for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)) {
2040  SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes);
2041 
2042  // Conversions by constructor and conversion functions have a
2043  // subexpression describing the call; strip it off.
2044  if (E->getCastKind() == CK_ConstructorConversion) {
2045  SubExpr = IgnoreExprNodes(cast<CXXConstructExpr>(SubExpr)->getArg(0),
2046  ignoreImplicitSemaNodes);
2047  } else if (E->getCastKind() == CK_UserDefinedConversion) {
2048  assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
2049  "Unexpected SubExpr for CK_UserDefinedConversion.");
2050  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
2051  SubExpr = MCE->getImplicitObjectArgument();
2052  }
2053  }
2054 
2055  return const_cast<Expr *>(SubExpr);
2056 }
2057 
2059  const Expr *SubExpr = nullptr;
2060 
2061  for (const CastExpr *E = this; E; E = dyn_cast<ImplicitCastExpr>(SubExpr)) {
2062  SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes);
2063 
2064  if (E->getCastKind() == CK_ConstructorConversion)
2065  return cast<CXXConstructExpr>(SubExpr)->getConstructor();
2066 
2067  if (E->getCastKind() == CK_UserDefinedConversion) {
2068  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
2069  return MCE->getMethodDecl();
2070  }
2071  }
2072 
2073  return nullptr;
2074 }
2075 
2076 CXXBaseSpecifier **CastExpr::path_buffer() {
2077  switch (getStmtClass()) {
2078 #define ABSTRACT_STMT(x)
2079 #define CASTEXPR(Type, Base) \
2080  case Stmt::Type##Class: \
2081  return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>();
2082 #define STMT(Type, Base)
2083 #include "clang/AST/StmtNodes.inc"
2084  default:
2085  llvm_unreachable("non-cast expressions not possible here");
2086  }
2087 }
2088 
2090  QualType opType) {
2091  auto RD = unionType->castAs<RecordType>()->getDecl();
2092  return getTargetFieldForToUnionCast(RD, opType);
2093 }
2094 
2096  QualType OpType) {
2097  auto &Ctx = RD->getASTContext();
2098  RecordDecl::field_iterator Field, FieldEnd;
2099  for (Field = RD->field_begin(), FieldEnd = RD->field_end();
2100  Field != FieldEnd; ++Field) {
2101  if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) &&
2102  !Field->isUnnamedBitField()) {
2103  return *Field;
2104  }
2105  }
2106  return nullptr;
2107 }
2108 
2110  assert(hasStoredFPFeatures());
2111  switch (getStmtClass()) {
2112  case ImplicitCastExprClass:
2113  return static_cast<ImplicitCastExpr *>(this)
2114  ->getTrailingObjects<FPOptionsOverride>();
2115  case CStyleCastExprClass:
2116  return static_cast<CStyleCastExpr *>(this)
2117  ->getTrailingObjects<FPOptionsOverride>();
2118  case CXXFunctionalCastExprClass:
2119  return static_cast<CXXFunctionalCastExpr *>(this)
2120  ->getTrailingObjects<FPOptionsOverride>();
2121  case CXXStaticCastExprClass:
2122  return static_cast<CXXStaticCastExpr *>(this)
2123  ->getTrailingObjects<FPOptionsOverride>();
2124  default:
2125  llvm_unreachable("Cast does not have FPFeatures");
2126  }
2127 }
2128 
2130  CastKind Kind, Expr *Operand,
2131  const CXXCastPath *BasePath,
2132  ExprValueKind VK,
2133  FPOptionsOverride FPO) {
2134  unsigned PathSize = (BasePath ? BasePath->size() : 0);
2135  void *Buffer =
2136  C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2137  PathSize, FPO.requiresTrailingStorage()));
2138  // Per C++ [conv.lval]p3, lvalue-to-rvalue conversions on class and
2139  // std::nullptr_t have special semantics not captured by CK_LValueToRValue.
2140  assert((Kind != CK_LValueToRValue ||
2141  !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&
2142  "invalid type for lvalue-to-rvalue conversion");
2143  ImplicitCastExpr *E =
2144  new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, FPO, VK);
2145  if (PathSize)
2146  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2147  E->getTrailingObjects<CXXBaseSpecifier *>());
2148  return E;
2149 }
2150 
2152  unsigned PathSize,
2153  bool HasFPFeatures) {
2154  void *Buffer =
2155  C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2156  PathSize, HasFPFeatures));
2157  return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize, HasFPFeatures);
2158 }
2159 
2161  ExprValueKind VK, CastKind K, Expr *Op,
2162  const CXXCastPath *BasePath,
2163  FPOptionsOverride FPO,
2164  TypeSourceInfo *WrittenTy,
2166  unsigned PathSize = (BasePath ? BasePath->size() : 0);
2167  void *Buffer =
2168  C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2169  PathSize, FPO.requiresTrailingStorage()));
2170  CStyleCastExpr *E =
2171  new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, FPO, WrittenTy, L, R);
2172  if (PathSize)
2173  std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2174  E->getTrailingObjects<CXXBaseSpecifier *>());
2175  return E;
2176 }
2177 
2179  unsigned PathSize,
2180  bool HasFPFeatures) {
2181  void *Buffer =
2182  C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2183  PathSize, HasFPFeatures));
2184  return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize, HasFPFeatures);
2185 }
2186 
2187 /// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
2188 /// corresponds to, e.g. "<<=".
2190  switch (Op) {
2191 #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling;
2192 #include "clang/AST/OperationKinds.def"
2193  }
2194  llvm_unreachable("Invalid OpCode!");
2195 }
2196 
2199  switch (OO) {
2200  default: llvm_unreachable("Not an overloadable binary operator");
2201  case OO_Plus: return BO_Add;
2202  case OO_Minus: return BO_Sub;
2203  case OO_Star: return BO_Mul;
2204  case OO_Slash: return BO_Div;
2205  case OO_Percent: return BO_Rem;
2206  case OO_Caret: return BO_Xor;
2207  case OO_Amp: return BO_And;
2208  case OO_Pipe: return BO_Or;
2209  case OO_Equal: return BO_Assign;
2210  case OO_Spaceship: return BO_Cmp;
2211  case OO_Less: return BO_LT;
2212  case OO_Greater: return BO_GT;
2213  case OO_PlusEqual: return BO_AddAssign;
2214  case OO_MinusEqual: return BO_SubAssign;
2215  case OO_StarEqual: return BO_MulAssign;
2216  case OO_SlashEqual: return BO_DivAssign;
2217  case OO_PercentEqual: return BO_RemAssign;
2218  case OO_CaretEqual: return BO_XorAssign;
2219  case OO_AmpEqual: return BO_AndAssign;
2220  case OO_PipeEqual: return BO_OrAssign;
2221  case OO_LessLess: return BO_Shl;
2222  case OO_GreaterGreater: return BO_Shr;
2223  case OO_LessLessEqual: return BO_ShlAssign;
2224  case OO_GreaterGreaterEqual: return BO_ShrAssign;
2225  case OO_EqualEqual: return BO_EQ;
2226  case OO_ExclaimEqual: return BO_NE;
2227  case OO_LessEqual: return BO_LE;
2228  case OO_GreaterEqual: return BO_GE;
2229  case OO_AmpAmp: return BO_LAnd;
2230  case OO_PipePipe: return BO_LOr;
2231  case OO_Comma: return BO_Comma;
2232  case OO_ArrowStar: return BO_PtrMemI;
2233  }
2234 }
2235 
2237  static const OverloadedOperatorKind OverOps[] = {
2238  /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
2239  OO_Star, OO_Slash, OO_Percent,
2240  OO_Plus, OO_Minus,
2241  OO_LessLess, OO_GreaterGreater,
2242  OO_Spaceship,
2243  OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
2244  OO_EqualEqual, OO_ExclaimEqual,
2245  OO_Amp,
2246  OO_Caret,
2247  OO_Pipe,
2248  OO_AmpAmp,
2249  OO_PipePipe,
2250  OO_Equal, OO_StarEqual,
2251  OO_SlashEqual, OO_PercentEqual,
2252  OO_PlusEqual, OO_MinusEqual,
2253  OO_LessLessEqual, OO_GreaterGreaterEqual,
2254  OO_AmpEqual, OO_CaretEqual,
2255  OO_PipeEqual,
2256  OO_Comma
2257  };
2258  return OverOps[Opc];
2259 }
2260 
2262  Opcode Opc,
2263  const Expr *LHS,
2264  const Expr *RHS) {
2265  if (Opc != BO_Add)
2266  return false;
2267 
2268  // Check that we have one pointer and one integer operand.
2269  const Expr *PExp;
2270  if (LHS->getType()->isPointerType()) {
2271  if (!RHS->getType()->isIntegerType())
2272  return false;
2273  PExp = LHS;
2274  } else if (RHS->getType()->isPointerType()) {
2275  if (!LHS->getType()->isIntegerType())
2276  return false;
2277  PExp = RHS;
2278  } else {
2279  return false;
2280  }
2281 
2282  // Check that the pointer is a nullptr.
2283  if (!PExp->IgnoreParenCasts()
2285  return false;
2286 
2287  // Check that the pointee type is char-sized.
2288  const PointerType *PTy = PExp->getType()->getAs<PointerType>();
2289  if (!PTy || !PTy->getPointeeType()->isCharType())
2290  return false;
2291 
2292  return true;
2293 }
2294 
2296  QualType ResultTy, SourceLocation BLoc,
2297  SourceLocation RParenLoc,
2298  DeclContext *ParentContext)
2299  : Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary),
2300  BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
2301  SourceLocExprBits.Kind = llvm::to_underlying(Kind);
2303 }
2304 
2305 StringRef SourceLocExpr::getBuiltinStr() const {
2306  switch (getIdentKind()) {
2308  return "__builtin_FILE";
2310  return "__builtin_FILE_NAME";
2312  return "__builtin_FUNCTION";
2314  return "__builtin_FUNCSIG";
2316  return "__builtin_LINE";
2318  return "__builtin_COLUMN";
2320  return "__builtin_source_location";
2321  }
2322  llvm_unreachable("unexpected IdentKind!");
2323 }
2324 
2326  const Expr *DefaultExpr) const {
2328  const DeclContext *Context;
2329 
2330  if (const auto *DIE = dyn_cast_if_present<CXXDefaultInitExpr>(DefaultExpr)) {
2331  Loc = DIE->getUsedLocation();
2332  Context = DIE->getUsedContext();
2333  } else if (const auto *DAE =
2334  dyn_cast_if_present<CXXDefaultArgExpr>(DefaultExpr)) {
2335  Loc = DAE->getUsedLocation();
2336  Context = DAE->getUsedContext();
2337  } else {
2338  Loc = getLocation();
2339  Context = getParentContext();
2340  }
2341 
2344 
2345  auto MakeStringLiteral = [&](StringRef Tmp) {
2346  using LValuePathEntry = APValue::LValuePathEntry;
2348  // Decay the string to a pointer to the first character.
2349  LValuePathEntry Path[1] = {LValuePathEntry::ArrayIndex(0)};
2350  return APValue(Res, CharUnits::Zero(), Path, /*OnePastTheEnd=*/false);
2351  };
2352 
2353  switch (getIdentKind()) {
2355  // __builtin_FILE_NAME() is a Clang-specific extension that expands to the
2356  // the last part of __builtin_FILE().
2359  FileName, PLoc, Ctx.getLangOpts(), Ctx.getTargetInfo());
2360  return MakeStringLiteral(FileName);
2361  }
2362  case SourceLocIdentKind::File: {
2363  SmallString<256> Path(PLoc.getFilename());
2365  Ctx.getTargetInfo());
2366  return MakeStringLiteral(Path);
2367  }
2370  const auto *CurDecl = dyn_cast<Decl>(Context);
2374  return MakeStringLiteral(
2375  CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
2376  }
2378  return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
2380  return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
2382  // Fill in a std::source_location::__impl structure, by creating an
2383  // artificial file-scoped CompoundLiteralExpr, and returning a pointer to
2384  // that.
2385  const CXXRecordDecl *ImplDecl = getType()->getPointeeCXXRecordDecl();
2386  assert(ImplDecl);
2387 
2388  // Construct an APValue for the __impl struct, and get or create a Decl
2389  // corresponding to that. Note that we've already verified that the shape of
2390  // the ImplDecl type is as expected.
2391 
2393  for (const FieldDecl *F : ImplDecl->fields()) {
2394  StringRef Name = F->getName();
2395  if (Name == "_M_file_name") {
2396  SmallString<256> Path(PLoc.getFilename());
2398  Ctx.getTargetInfo());
2399  Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(Path);
2400  } else if (Name == "_M_function_name") {
2401  // Note: this emits the PrettyFunction name -- different than what
2402  // __builtin_FUNCTION() above returns!
2403  const auto *CurDecl = dyn_cast<Decl>(Context);
2404  Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(
2405  CurDecl && !isa<TranslationUnitDecl>(CurDecl)
2406  ? StringRef(PredefinedExpr::ComputeName(
2408  : "");
2409  } else if (Name == "_M_line") {
2410  llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
2411  Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
2412  } else if (Name == "_M_column") {
2413  llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
2414  Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
2415  }
2416  }
2417 
2419  Ctx.getUnnamedGlobalConstantDecl(getType()->getPointeeType(), Value);
2420 
2422  false);
2423  }
2424  }
2425  llvm_unreachable("unhandled case");
2426 }
2427 
2429  ArrayRef<Expr *> initExprs, SourceLocation rbraceloc)
2430  : Expr(InitListExprClass, QualType(), VK_PRValue, OK_Ordinary),
2431  InitExprs(C, initExprs.size()), LBraceLoc(lbraceloc),
2432  RBraceLoc(rbraceloc), AltForm(nullptr, true) {
2433  sawArrayRangeDesignator(false);
2434  InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end());
2435 
2437 }
2438 
2439 void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) {
2440  if (NumInits > InitExprs.size())
2441  InitExprs.reserve(C, NumInits);
2442 }
2443 
2444 void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) {
2445  InitExprs.resize(C, NumInits, nullptr);
2446 }
2447 
2448 Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) {
2449  if (Init >= InitExprs.size()) {
2450  InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr);
2451  setInit(Init, expr);
2452  return nullptr;
2453  }
2454 
2455  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
2456  setInit(Init, expr);
2457  return Result;
2458 }
2459 
2461  assert(!hasArrayFiller() && "Filler already set!");
2462  ArrayFillerOrUnionFieldInit = filler;
2463  // Fill out any "holes" in the array due to designated initializers.
2464  Expr **inits = getInits();
2465  for (unsigned i = 0, e = getNumInits(); i != e; ++i)
2466  if (inits[i] == nullptr)
2467  inits[i] = filler;
2468 }
2469 
2471  if (getNumInits() != 1)
2472  return false;
2473  const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
2474  if (!AT || !AT->getElementType()->isIntegerType())
2475  return false;
2476  // It is possible for getInit() to return null.
2477  const Expr *Init = getInit(0);
2478  if (!Init)
2479  return false;
2480  Init = Init->IgnoreParenImpCasts();
2481  return isa<StringLiteral>(Init) || isa<ObjCEncodeExpr>(Init);
2482 }
2483 
2485  assert(isSemanticForm() && "syntactic form never semantically transparent");
2486 
2487  // A glvalue InitListExpr is always just sugar.
2488  if (isGLValue()) {
2489  assert(getNumInits() == 1 && "multiple inits in glvalue init list");
2490  return true;
2491  }
2492 
2493  // Otherwise, we're sugar if and only if we have exactly one initializer that
2494  // is of the same type.
2495  if (getNumInits() != 1 || !getInit(0))
2496  return false;
2497 
2498  // Don't confuse aggregate initialization of a struct X { X &x; }; with a
2499  // transparent struct copy.
2500  if (!getInit(0)->isPRValue() && getType()->isRecordType())
2501  return false;
2502 
2503  return getType().getCanonicalType() ==
2505 }
2506 
2508  assert(isSyntacticForm() && "only test syntactic form as zero initializer");
2509 
2510  if (LangOpts.CPlusPlus || getNumInits() != 1 || !getInit(0)) {
2511  return false;
2512  }
2513 
2514  const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0)->IgnoreImplicit());
2515  return Lit && Lit->getValue() == 0;
2516 }
2517 
2519  if (InitListExpr *SyntacticForm = getSyntacticForm())
2520  return SyntacticForm->getBeginLoc();
2521  SourceLocation Beg = LBraceLoc;
2522  if (Beg.isInvalid()) {
2523  // Find the first non-null initializer.
2524  for (InitExprsTy::const_iterator I = InitExprs.begin(),
2525  E = InitExprs.end();
2526  I != E; ++I) {
2527  if (Stmt *S = *I) {
2528  Beg = S->getBeginLoc();
2529  break;
2530  }
2531  }
2532  }
2533  return Beg;
2534 }
2535 
2537  if (InitListExpr *SyntacticForm = getSyntacticForm())
2538  return SyntacticForm->getEndLoc();
2539  SourceLocation End = RBraceLoc;
2540  if (End.isInvalid()) {
2541  // Find the first non-null initializer from the end.
2542  for (Stmt *S : llvm::reverse(InitExprs)) {
2543  if (S) {
2544  End = S->getEndLoc();
2545  break;
2546  }
2547  }
2548  }
2549  return End;
2550 }
2551 
2552 /// getFunctionType - Return the underlying function type for this block.
2553 ///
2555  // The block pointer is never sugared, but the function type might be.
2556  return cast<BlockPointerType>(getType())
2558 }
2559 
2561  return TheBlock->getCaretLocation();
2562 }
2563 const Stmt *BlockExpr::getBody() const {
2564  return TheBlock->getBody();
2565 }
2567  return TheBlock->getBody();
2568 }
2569 
2570 
2571 //===----------------------------------------------------------------------===//
2572 // Generic Expression Routines
2573 //===----------------------------------------------------------------------===//
2574 
2576  // In C++11, discarded-value expressions of a certain form are special,
2577  // according to [expr]p10:
2578  // The lvalue-to-rvalue conversion (4.1) is applied only if the
2579  // expression is a glvalue of volatile-qualified type and it has
2580  // one of the following forms:
2581  if (!isGLValue() || !getType().isVolatileQualified())
2582  return false;
2583 
2584  const Expr *E = IgnoreParens();
2585 
2586  // - id-expression (5.1.1),
2587  if (isa<DeclRefExpr>(E))
2588  return true;
2589 
2590  // - subscripting (5.2.1),
2591  if (isa<ArraySubscriptExpr>(E))
2592  return true;
2593 
2594  // - class member access (5.2.5),
2595  if (isa<MemberExpr>(E))
2596  return true;
2597 
2598  // - indirection (5.3.1),
2599  if (auto *UO = dyn_cast<UnaryOperator>(E))
2600  if (UO->getOpcode() == UO_Deref)
2601  return true;
2602 
2603  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
2604  // - pointer-to-member operation (5.5),
2605  if (BO->isPtrMemOp())
2606  return true;
2607 
2608  // - comma expression (5.18) where the right operand is one of the above.
2609  if (BO->getOpcode() == BO_Comma)
2610  return BO->getRHS()->isReadIfDiscardedInCPlusPlus11();
2611  }
2612 
2613  // - conditional expression (5.16) where both the second and the third
2614  // operands are one of the above, or
2615  if (auto *CO = dyn_cast<ConditionalOperator>(E))
2616  return CO->getTrueExpr()->isReadIfDiscardedInCPlusPlus11() &&
2617  CO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2618  // The related edge case of "*x ?: *x".
2619  if (auto *BCO =
2620  dyn_cast<BinaryConditionalOperator>(E)) {
2621  if (auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
2622  return OVE->getSourceExpr()->isReadIfDiscardedInCPlusPlus11() &&
2623  BCO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2624  }
2625 
2626  // Objective-C++ extensions to the rule.
2627  if (isa<ObjCIvarRefExpr>(E))
2628  return true;
2629  if (const auto *POE = dyn_cast<PseudoObjectExpr>(E)) {
2630  if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(POE->getSyntacticForm()))
2631  return true;
2632  }
2633 
2634  return false;
2635 }
2636 
2637 /// isUnusedResultAWarning - Return true if this immediate expression should
2638 /// be warned about if the result is unused. If so, fill in Loc and Ranges
2639 /// with location to warn on and the source range[s] to report with the
2640 /// warning.
2642  SourceRange &R1, SourceRange &R2,
2643  ASTContext &Ctx) const {
2644  // Don't warn if the expr is type dependent. The type could end up
2645  // instantiating to void.
2646  if (isTypeDependent())
2647  return false;
2648 
2649  switch (getStmtClass()) {
2650  default:
2651  if (getType()->isVoidType())
2652  return false;
2653  WarnE = this;
2654  Loc = getExprLoc();
2655  R1 = getSourceRange();
2656  return true;
2657  case ParenExprClass:
2658  return cast<ParenExpr>(this)->getSubExpr()->
2659  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2660  case GenericSelectionExprClass:
2661  return cast<GenericSelectionExpr>(this)->getResultExpr()->
2662  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2663  case CoawaitExprClass:
2664  case CoyieldExprClass:
2665  return cast<CoroutineSuspendExpr>(this)->getResumeExpr()->
2666  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2667  case ChooseExprClass:
2668  return cast<ChooseExpr>(this)->getChosenSubExpr()->
2669  isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2670  case UnaryOperatorClass: {
2671  const UnaryOperator *UO = cast<UnaryOperator>(this);
2672 
2673  switch (UO->getOpcode()) {
2674  case UO_Plus:
2675  case UO_Minus:
2676  case UO_AddrOf:
2677  case UO_Not:
2678  case UO_LNot:
2679  case UO_Deref:
2680  break;
2681  case UO_Coawait:
2682  // This is just the 'operator co_await' call inside the guts of a
2683  // dependent co_await call.
2684  case UO_PostInc:
2685  case UO_PostDec:
2686  case UO_PreInc:
2687  case UO_PreDec: // ++/--
2688  return false; // Not a warning.
2689  case UO_Real:
2690  case UO_Imag:
2691  // accessing a piece of a volatile complex is a side-effect.
2692  if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
2694  return false;
2695  break;
2696  case UO_Extension:
2697  return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2698  }
2699  WarnE = this;
2700  Loc = UO->getOperatorLoc();
2701  R1 = UO->getSubExpr()->getSourceRange();
2702  return true;
2703  }
2704  case BinaryOperatorClass: {
2705  const BinaryOperator *BO = cast<BinaryOperator>(this);
2706  switch (BO->getOpcode()) {
2707  default:
2708  break;
2709  // Consider the RHS of comma for side effects. LHS was checked by
2710  // Sema::CheckCommaOperands.
2711  case BO_Comma:
2712  // ((foo = <blah>), 0) is an idiom for hiding the result (and
2713  // lvalue-ness) of an assignment written in a macro.
2714  if (IntegerLiteral *IE =
2715  dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
2716  if (IE->getValue() == 0)
2717  return false;
2718  return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2719  // Consider '||', '&&' to have side effects if the LHS or RHS does.
2720  case BO_LAnd:
2721  case BO_LOr:
2722  if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) ||
2723  !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
2724  return false;
2725  break;
2726  }
2727  if (BO->isAssignmentOp())
2728  return false;
2729  WarnE = this;
2730  Loc = BO->getOperatorLoc();
2731  R1 = BO->getLHS()->getSourceRange();
2732  R2 = BO->getRHS()->getSourceRange();
2733  return true;
2734  }
2735  case CompoundAssignOperatorClass:
2736  case VAArgExprClass:
2737  case AtomicExprClass:
2738  return false;
2739 
2740  case ConditionalOperatorClass: {
2741  // If only one of the LHS or RHS is a warning, the operator might
2742  // be being used for control flow. Only warn if both the LHS and
2743  // RHS are warnings.
2744  const auto *Exp = cast<ConditionalOperator>(this);
2745  return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
2746  Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2747  }
2748  case BinaryConditionalOperatorClass: {
2749  const auto *Exp = cast<BinaryConditionalOperator>(this);
2750  return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2751  }
2752 
2753  case MemberExprClass:
2754  WarnE = this;
2755  Loc = cast<MemberExpr>(this)->getMemberLoc();
2756  R1 = SourceRange(Loc, Loc);
2757  R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
2758  return true;
2759 
2760  case ArraySubscriptExprClass:
2761  WarnE = this;
2762  Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
2763  R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
2764  R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
2765  return true;
2766 
2767  case CXXOperatorCallExprClass: {
2768  // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator
2769  // overloads as there is no reasonable way to define these such that they
2770  // have non-trivial, desirable side-effects. See the -Wunused-comparison
2771  // warning: operators == and != are commonly typo'ed, and so warning on them
2772  // provides additional value as well. If this list is updated,
2773  // DiagnoseUnusedComparison should be as well.
2774  const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this);
2775  switch (Op->getOperator()) {
2776  default:
2777  break;
2778  case OO_EqualEqual:
2779  case OO_ExclaimEqual:
2780  case OO_Less:
2781  case OO_Greater:
2782  case OO_GreaterEqual:
2783  case OO_LessEqual:
2784  if (Op->getCallReturnType(Ctx)->isReferenceType() ||
2785  Op->getCallReturnType(Ctx)->isVoidType())
2786  break;
2787  WarnE = this;
2788  Loc = Op->getOperatorLoc();
2789  R1 = Op->getSourceRange();
2790  return true;
2791  }
2792 
2793  // Fallthrough for generic call handling.
2794  [[fallthrough]];
2795  }
2796  case CallExprClass:
2797  case CXXMemberCallExprClass:
2798  case UserDefinedLiteralClass: {
2799  // If this is a direct call, get the callee.
2800  const CallExpr *CE = cast<CallExpr>(this);
2801  if (const Decl *FD = CE->getCalleeDecl()) {
2802  // If the callee has attribute pure, const, or warn_unused_result, warn
2803  // about it. void foo() { strlen("bar"); } should warn.
2804  //
2805  // Note: If new cases are added here, DiagnoseUnusedExprResult should be
2806  // updated to match for QoI.
2807  if (CE->hasUnusedResultAttr(Ctx) ||
2808  FD->hasAttr<PureAttr>() || FD->hasAttr<ConstAttr>()) {
2809  WarnE = this;
2810  Loc = CE->getCallee()->getBeginLoc();
2811  R1 = CE->getCallee()->getSourceRange();
2812 
2813  if (unsigned NumArgs = CE->getNumArgs())
2814  R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2815  CE->getArg(NumArgs - 1)->getEndLoc());
2816  return true;
2817  }
2818  }
2819  return false;
2820  }
2821 
2822  // If we don't know precisely what we're looking at, let's not warn.
2823  case UnresolvedLookupExprClass:
2824  case CXXUnresolvedConstructExprClass:
2825  case RecoveryExprClass:
2826  return false;
2827 
2828  case CXXTemporaryObjectExprClass:
2829  case CXXConstructExprClass: {
2830  if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) {
2831  const auto *WarnURAttr = Type->getAttr<WarnUnusedResultAttr>();
2832  if (Type->hasAttr<WarnUnusedAttr>() ||
2833  (WarnURAttr && WarnURAttr->IsCXX11NoDiscard())) {
2834  WarnE = this;
2835  Loc = getBeginLoc();
2836  R1 = getSourceRange();
2837  return true;
2838  }
2839  }
2840 
2841  const auto *CE = cast<CXXConstructExpr>(this);
2842  if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
2843  const auto *WarnURAttr = Ctor->getAttr<WarnUnusedResultAttr>();
2844  if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()) {
2845  WarnE = this;
2846  Loc = getBeginLoc();
2847  R1 = getSourceRange();
2848 
2849  if (unsigned NumArgs = CE->getNumArgs())
2850  R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2851  CE->getArg(NumArgs - 1)->getEndLoc());
2852  return true;
2853  }
2854  }
2855 
2856  return false;
2857  }
2858 
2859  case ObjCMessageExprClass: {
2860  const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
2861  if (Ctx.getLangOpts().ObjCAutoRefCount &&
2862  ME->isInstanceMessage() &&
2863  !ME->getType()->isVoidType() &&
2864  ME->getMethodFamily() == OMF_init) {
2865  WarnE = this;
2866  Loc = getExprLoc();
2867  R1 = ME->getSourceRange();
2868  return true;
2869  }
2870 
2871  if (const ObjCMethodDecl *MD = ME->getMethodDecl())
2872  if (MD->hasAttr<WarnUnusedResultAttr>()) {
2873  WarnE = this;
2874  Loc = getExprLoc();
2875  return true;
2876  }
2877 
2878  return false;
2879  }
2880 
2881  case ObjCPropertyRefExprClass:
2882  case ObjCSubscriptRefExprClass:
2883  WarnE = this;
2884  Loc = getExprLoc();
2885  R1 = getSourceRange();
2886  return true;
2887 
2888  case PseudoObjectExprClass: {
2889  const auto *POE = cast<PseudoObjectExpr>(this);
2890 
2891  // For some syntactic forms, we should always warn.
2892  if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(
2893  POE->getSyntacticForm())) {
2894  WarnE = this;
2895  Loc = getExprLoc();
2896  R1 = getSourceRange();
2897  return true;
2898  }
2899 
2900  // For others, we should never warn.
2901  if (auto *BO = dyn_cast<BinaryOperator>(POE->getSyntacticForm()))
2902  if (BO->isAssignmentOp())
2903  return false;
2904  if (auto *UO = dyn_cast<UnaryOperator>(POE->getSyntacticForm()))
2905  if (UO->isIncrementDecrementOp())
2906  return false;
2907 
2908  // Otherwise, warn if the result expression would warn.
2909  const Expr *Result = POE->getResultExpr();
2910  return Result && Result->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2911  }
2912 
2913  case StmtExprClass: {
2914  // Statement exprs don't logically have side effects themselves, but are
2915  // sometimes used in macros in ways that give them a type that is unused.
2916  // For example ({ blah; foo(); }) will end up with a type if foo has a type.
2917  // however, if the result of the stmt expr is dead, we don't want to emit a
2918  // warning.
2919  const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
2920  if (!CS->body_empty()) {
2921  if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
2922  return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2923  if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back()))
2924  if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt()))
2925  return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2926  }
2927 
2928  if (getType()->isVoidType())
2929  return false;
2930  WarnE = this;
2931  Loc = cast<StmtExpr>(this)->getLParenLoc();
2932  R1 = getSourceRange();
2933  return true;
2934  }
2935  case CXXFunctionalCastExprClass:
2936  case CStyleCastExprClass: {
2937  // Ignore an explicit cast to void, except in C++98 if the operand is a
2938  // volatile glvalue for which we would trigger an implicit read in any
2939  // other language mode. (Such an implicit read always happens as part of
2940  // the lvalue conversion in C, and happens in C++ for expressions of all
2941  // forms where it seems likely the user intended to trigger a volatile
2942  // load.)
2943  const CastExpr *CE = cast<CastExpr>(this);
2944  const Expr *SubE = CE->getSubExpr()->IgnoreParens();
2945  if (CE->getCastKind() == CK_ToVoid) {
2946  if (Ctx.getLangOpts().CPlusPlus && !Ctx.getLangOpts().CPlusPlus11 &&
2948  // Suppress the "unused value" warning for idiomatic usage of
2949  // '(void)var;' used to suppress "unused variable" warnings.
2950  if (auto *DRE = dyn_cast<DeclRefExpr>(SubE))
2951  if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2952  if (!VD->isExternallyVisible())
2953  return false;
2954 
2955  // The lvalue-to-rvalue conversion would have no effect for an array.
2956  // It's implausible that the programmer expected this to result in a
2957  // volatile array load, so don't warn.
2958  if (SubE->getType()->isArrayType())
2959  return false;
2960 
2961  return SubE->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2962  }
2963  return false;
2964  }
2965 
2966  // If this is a cast to a constructor conversion, check the operand.
2967  // Otherwise, the result of the cast is unused.
2968  if (CE->getCastKind() == CK_ConstructorConversion)
2969  return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2970  if (CE->getCastKind() == CK_Dependent)
2971  return false;
2972 
2973  WarnE = this;
2974  if (const CXXFunctionalCastExpr *CXXCE =
2975  dyn_cast<CXXFunctionalCastExpr>(this)) {
2976  Loc = CXXCE->getBeginLoc();
2977  R1 = CXXCE->getSubExpr()->getSourceRange();
2978  } else {
2979  const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this);
2980  Loc = CStyleCE->getLParenLoc();
2981  R1 = CStyleCE->getSubExpr()->getSourceRange();
2982  }
2983  return true;
2984  }
2985  case ImplicitCastExprClass: {
2986  const CastExpr *ICE = cast<ImplicitCastExpr>(this);
2987 
2988  // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect.
2989  if (ICE->getCastKind() == CK_LValueToRValue &&
2991  return false;
2992 
2993  return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2994  }
2995  case CXXDefaultArgExprClass:
2996  return (cast<CXXDefaultArgExpr>(this)
2997  ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
2998  case CXXDefaultInitExprClass:
2999  return (cast<CXXDefaultInitExpr>(this)
3000  ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
3001 
3002  case CXXNewExprClass:
3003  // FIXME: In theory, there might be new expressions that don't have side
3004  // effects (e.g. a placement new with an uninitialized POD).
3005  case CXXDeleteExprClass:
3006  return false;
3007  case MaterializeTemporaryExprClass:
3008  return cast<MaterializeTemporaryExpr>(this)
3009  ->getSubExpr()
3010  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
3011  case CXXBindTemporaryExprClass:
3012  return cast<CXXBindTemporaryExpr>(this)->getSubExpr()
3013  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
3014  case ExprWithCleanupsClass:
3015  return cast<ExprWithCleanups>(this)->getSubExpr()
3016  ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
3017  }
3018 }
3019 
3020 /// isOBJCGCCandidate - Check if an expression is objc gc'able.
3021 /// returns true, if it is; false otherwise.
3023  const Expr *E = IgnoreParens();
3024  switch (E->getStmtClass()) {
3025  default:
3026  return false;
3027  case ObjCIvarRefExprClass:
3028  return true;
3029  case Expr::UnaryOperatorClass:
3030  return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3031  case ImplicitCastExprClass:
3032  return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3033  case MaterializeTemporaryExprClass:
3034  return cast<MaterializeTemporaryExpr>(E)->getSubExpr()->isOBJCGCCandidate(
3035  Ctx);
3036  case CStyleCastExprClass:
3037  return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3038  case DeclRefExprClass: {
3039  const Decl *D = cast<DeclRefExpr>(E)->getDecl();
3040 
3041  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
3042  if (VD->hasGlobalStorage())
3043  return true;
3044  QualType T = VD->getType();
3045  // dereferencing to a pointer is always a gc'able candidate,
3046  // unless it is __weak.
3047  return T->isPointerType() &&
3049  }
3050  return false;
3051  }
3052  case MemberExprClass: {
3053  const MemberExpr *M = cast<MemberExpr>(E);
3054  return M->getBase()->isOBJCGCCandidate(Ctx);
3055  }
3056  case ArraySubscriptExprClass:
3057  return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx);
3058  }
3059 }
3060 
3062  if (isTypeDependent())
3063  return false;
3064  return ClassifyLValue(Ctx) == Expr::LV_MemberFunction;
3065 }
3066 
3068  assert(expr->hasPlaceholderType(BuiltinType::BoundMember));
3069 
3070  // Bound member expressions are always one of these possibilities:
3071  // x->m x.m x->*y x.*y
3072  // (possibly parenthesized)
3073 
3074  expr = expr->IgnoreParens();
3075  if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) {
3076  assert(isa<CXXMethodDecl>(mem->getMemberDecl()));
3077  return mem->getMemberDecl()->getType();
3078  }
3079 
3080  if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) {
3081  QualType type = op->getRHS()->getType()->castAs<MemberPointerType>()
3082  ->getPointeeType();
3083  assert(type->isFunctionType());
3084  return type;
3085  }
3086 
3087  assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr));
3088  return QualType();
3089 }
3090 
3093 }
3094 
3096  return IgnoreExprNodes(this, IgnoreCastsSingleStep);
3097 }
3098 
3101 }
3102 
3105 }
3106 
3109 }
3110 
3114 }
3115 
3118 }
3119 
3121  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
3122  if (MCE->getMethodDecl() && isa<CXXConversionDecl>(MCE->getMethodDecl()))
3123  return MCE->getImplicitObjectArgument();
3124  }
3125  return this;
3126 }
3127 
3131 }
3132 
3136 }
3137 
3139  auto IgnoreNoopCastsSingleStep = [&Ctx](Expr *E) {
3140  if (auto *CE = dyn_cast<CastExpr>(E)) {
3141  // We ignore integer <-> casts that are of the same width, ptr<->ptr and
3142  // ptr<->int casts of the same width. We also ignore all identity casts.
3143  Expr *SubExpr = CE->getSubExpr();
3144  bool IsIdentityCast =
3145  Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType());
3146  bool IsSameWidthCast = (E->getType()->isPointerType() ||
3147  E->getType()->isIntegralType(Ctx)) &&
3148  (SubExpr->getType()->isPointerType() ||
3149  SubExpr->getType()->isIntegralType(Ctx)) &&
3150  (Ctx.getTypeSize(E->getType()) ==
3151  Ctx.getTypeSize(SubExpr->getType()));
3152 
3153  if (IsIdentityCast || IsSameWidthCast)
3154  return SubExpr;
3155  } else if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
3156  return NTTP->getReplacement();
3157 
3158  return E;
3159  };
3161  IgnoreNoopCastsSingleStep);
3162 }
3163 
3166  if (auto *Cast = dyn_cast<CXXFunctionalCastExpr>(E)) {
3167  auto *SE = Cast->getSubExpr();
3168  if (SE->getSourceRange() == E->getSourceRange())
3169  return SE;
3170  }
3171 
3172  if (auto *C = dyn_cast<CXXConstructExpr>(E)) {
3173  auto NumArgs = C->getNumArgs();
3174  if (NumArgs == 1 ||
3175  (NumArgs > 1 && isa<CXXDefaultArgExpr>(C->getArg(1)))) {
3176  Expr *A = C->getArg(0);
3177  if (A->getSourceRange() == E->getSourceRange() || C->isElidable())
3178  return A;
3179  }
3180  }
3181  return E;
3182  };
3183  auto IgnoreImplicitMemberCallSingleStep = [](Expr *E) {
3184  if (auto *C = dyn_cast<CXXMemberCallExpr>(E)) {
3185  Expr *ExprNode = C->getImplicitObjectArgument();
3186  if (ExprNode->getSourceRange() == E->getSourceRange()) {
3187  return ExprNode;
3188  }
3189  if (auto *PE = dyn_cast<ParenExpr>(ExprNode)) {
3190  if (PE->getSourceRange() == C->getSourceRange()) {
3191  return cast<Expr>(PE);
3192  }
3193  }
3194  ExprNode = ExprNode->IgnoreParenImpCasts();
3195  if (ExprNode->getSourceRange() == E->getSourceRange())
3196  return ExprNode;
3197  }
3198  return E;
3199  };
3200  return IgnoreExprNodes(
3203  IgnoreImplicitMemberCallSingleStep);
3204 }
3205 
3207  const Expr *E = this;
3208  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
3209  E = M->getSubExpr();
3210 
3211  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
3212  E = ICE->getSubExprAsWritten();
3213 
3214  return isa<CXXDefaultArgExpr>(E);
3215 }
3216 
3217 /// Skip over any no-op casts and any temporary-binding
3218 /// expressions.
3220  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
3221  E = M->getSubExpr();
3222 
3223  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3224  if (ICE->getCastKind() == CK_NoOp)
3225  E = ICE->getSubExpr();
3226  else
3227  break;
3228  }
3229 
3230  while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
3231  E = BE->getSubExpr();
3232 
3233  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3234  if (ICE->getCastKind() == CK_NoOp)
3235  E = ICE->getSubExpr();
3236  else
3237  break;
3238  }
3239 
3240  return E->IgnoreParens();
3241 }
3242 
3243 /// isTemporaryObject - Determines if this expression produces a
3244 /// temporary of the given class type.
3245 bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const {
3246  if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy)))
3247  return false;
3248 
3250 
3251  // Temporaries are by definition pr-values of class type.
3252  if (!E->Classify(C).isPRValue()) {
3253  // In this context, property reference is a message call and is pr-value.
3254  if (!isa<ObjCPropertyRefExpr>(E))
3255  return false;
3256  }
3257 
3258  // Black-list a few cases which yield pr-values of class type that don't
3259  // refer to temporaries of that type:
3260 
3261  // - implicit derived-to-base conversions
3262  if (isa<ImplicitCastExpr>(E)) {
3263  switch (cast<ImplicitCastExpr>(E)->getCastKind()) {
3264  case CK_DerivedToBase:
3265  case CK_UncheckedDerivedToBase:
3266  return false;
3267  default:
3268  break;
3269  }
3270  }
3271 
3272  // - member expressions (all)
3273  if (isa<MemberExpr>(E))
3274  return false;
3275 
3276  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
3277  if (BO->isPtrMemOp())
3278  return false;
3279 
3280  // - opaque values (all)
3281  if (isa<OpaqueValueExpr>(E))
3282  return false;
3283 
3284  return true;
3285 }
3286 
3288  const Expr *E = this;
3289 
3290  // Strip away parentheses and casts we don't care about.
3291  while (true) {
3292  if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) {
3293  E = Paren->getSubExpr();
3294  continue;
3295  }
3296 
3297  if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3298  if (ICE->getCastKind() == CK_NoOp ||
3299  ICE->getCastKind() == CK_LValueToRValue ||
3300  ICE->getCastKind() == CK_DerivedToBase ||
3301  ICE->getCastKind() == CK_UncheckedDerivedToBase) {
3302  E = ICE->getSubExpr();
3303  continue;
3304  }
3305  }
3306 
3307  if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) {
3308  if (UnOp->getOpcode() == UO_Extension) {
3309  E = UnOp->getSubExpr();
3310  continue;
3311  }
3312  }
3313 
3314  if (const MaterializeTemporaryExpr *M
3315  = dyn_cast<MaterializeTemporaryExpr>(E)) {
3316  E = M->getSubExpr();
3317  continue;
3318  }
3319 
3320  break;
3321  }
3322 
3323  if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E))
3324  return This->isImplicit();
3325 
3326  return false;
3327 }
3328 
3329 /// hasAnyTypeDependentArguments - Determines if any of the expressions
3330 /// in Exprs is type-dependent.
3332  for (unsigned I = 0; I < Exprs.size(); ++I)
3333  if (Exprs[I]->isTypeDependent())
3334  return true;
3335 
3336  return false;
3337 }
3338 
3339 bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
3340  const Expr **Culprit) const {
3341  assert(!isValueDependent() &&
3342  "Expression evaluator can't be called on a dependent expression.");
3343 
3344  // This function is attempting whether an expression is an initializer
3345  // which can be evaluated at compile-time. It very closely parallels
3346  // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it
3347  // will lead to unexpected results. Like ConstExprEmitter, it falls back
3348  // to isEvaluatable most of the time.
3349  //
3350  // If we ever capture reference-binding directly in the AST, we can
3351  // kill the second parameter.
3352 
3353  if (IsForRef) {
3354  if (auto *EWC = dyn_cast<ExprWithCleanups>(this))
3355  return EWC->getSubExpr()->isConstantInitializer(Ctx, true, Culprit);
3356  if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(this))
3357  return MTE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3358  EvalResult Result;
3359  if (EvaluateAsLValue(Result, Ctx) && !Result.HasSideEffects)
3360  return true;
3361  if (Culprit)
3362  *Culprit = this;
3363  return false;
3364  }
3365 
3366  switch (getStmtClass()) {
3367  default: break;
3368  case Stmt::ExprWithCleanupsClass:
3369  return cast<ExprWithCleanups>(this)->getSubExpr()->isConstantInitializer(
3370  Ctx, IsForRef, Culprit);
3371  case StringLiteralClass:
3372  case ObjCEncodeExprClass:
3373  return true;
3374  case CXXTemporaryObjectExprClass:
3375  case CXXConstructExprClass: {
3376  const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
3377 
3378  if (CE->getConstructor()->isTrivial() &&
3380  // Trivial default constructor
3381  if (!CE->getNumArgs()) return true;
3382 
3383  // Trivial copy constructor
3384  assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument");
3385  return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit);
3386  }
3387 
3388  break;
3389  }
3390  case ConstantExprClass: {
3391  // FIXME: We should be able to return "true" here, but it can lead to extra
3392  // error messages. E.g. in Sema/array-init.c.
3393  const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr();
3394  return Exp->isConstantInitializer(Ctx, false, Culprit);
3395  }
3396  case CompoundLiteralExprClass: {
3397  // This handles gcc's extension that allows global initializers like
3398  // "struct x {int x;} x = (struct x) {};".
3399  // FIXME: This accepts other cases it shouldn't!
3400  const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
3401  return Exp->isConstantInitializer(Ctx, false, Culprit);
3402  }
3403  case DesignatedInitUpdateExprClass: {
3404  const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this);
3405  return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) &&
3406  DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit);
3407  }
3408  case InitListExprClass: {
3409  // C++ [dcl.init.aggr]p2:
3410  // The elements of an aggregate are:
3411  // - for an array, the array elements in increasing subscript order, or
3412  // - for a class, the direct base classes in declaration order, followed
3413  // by the direct non-static data members (11.4) that are not members of
3414  // an anonymous union, in declaration order.
3415  const InitListExpr *ILE = cast<InitListExpr>(this);
3416  assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form");
3417  if (ILE->getType()->isArrayType()) {
3418  unsigned numInits = ILE->getNumInits();
3419  for (unsigned i = 0; i < numInits; i++) {
3420  if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit))
3421  return false;
3422  }
3423  return true;
3424  }
3425 
3426  if (ILE->getType()->isRecordType()) {
3427  unsigned ElementNo = 0;
3428  RecordDecl *RD = ILE->getType()->castAs<RecordType>()->getDecl();
3429 
3430  // In C++17, bases were added to the list of members used by aggregate
3431  // initialization.
3432  if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3433  for (unsigned i = 0, e = CXXRD->getNumBases(); i < e; i++) {
3434  if (ElementNo < ILE->getNumInits()) {
3435  const Expr *Elt = ILE->getInit(ElementNo++);
3436  if (!Elt->isConstantInitializer(Ctx, false, Culprit))
3437  return false;
3438  }
3439  }
3440  }
3441 
3442  for (const auto *Field : RD->fields()) {
3443  // If this is a union, skip all the fields that aren't being initialized.
3444  if (RD->isUnion() && ILE->getInitializedFieldInUnion() != Field)
3445  continue;
3446 
3447  // Don't emit anonymous bitfields, they just affect layout.
3448  if (Field->isUnnamedBitField())
3449  continue;
3450 
3451  if (ElementNo < ILE->getNumInits()) {
3452  const Expr *Elt = ILE->getInit(ElementNo++);
3453  if (Field->isBitField()) {
3454  // Bitfields have to evaluate to an integer.
3455  EvalResult Result;
3456  if (!Elt->EvaluateAsInt(Result, Ctx)) {
3457  if (Culprit)
3458  *Culprit = Elt;
3459  return false;
3460  }
3461  } else {
3462  bool RefType = Field->getType()->isReferenceType();
3463  if (!Elt->isConstantInitializer(Ctx, RefType, Culprit))
3464  return false;
3465  }
3466  }
3467  }
3468  return true;
3469  }
3470 
3471  break;
3472  }
3473  case ImplicitValueInitExprClass:
3474  case NoInitExprClass:
3475  return true;
3476  case ParenExprClass:
3477  return cast<ParenExpr>(this)->getSubExpr()
3478  ->isConstantInitializer(Ctx, IsForRef, Culprit);
3479  case GenericSelectionExprClass:
3480  return cast<GenericSelectionExpr>(this)->getResultExpr()
3481  ->isConstantInitializer(Ctx, IsForRef, Culprit);
3482  case ChooseExprClass:
3483  if (cast<ChooseExpr>(this)->isConditionDependent()) {
3484  if (Culprit)
3485  *Culprit = this;
3486  return false;
3487  }
3488  return cast<ChooseExpr>(this)->getChosenSubExpr()
3489  ->isConstantInitializer(Ctx, IsForRef, Culprit);
3490  case UnaryOperatorClass: {
3491  const UnaryOperator* Exp = cast<UnaryOperator>(this);
3492  if (Exp->getOpcode() == UO_Extension)
3493  return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3494  break;
3495  }
3496  case PackIndexingExprClass: {
3497  return cast<PackIndexingExpr>(this)
3498  ->getSelectedExpr()
3499  ->isConstantInitializer(Ctx, false, Culprit);
3500  }
3501  case CXXFunctionalCastExprClass:
3502  case CXXStaticCastExprClass:
3503  case ImplicitCastExprClass:
3504  case CStyleCastExprClass:
3505  case ObjCBridgedCastExprClass:
3506  case CXXDynamicCastExprClass:
3507  case CXXReinterpretCastExprClass:
3508  case CXXAddrspaceCastExprClass:
3509  case CXXConstCastExprClass: {
3510  const CastExpr *CE = cast<CastExpr>(this);
3511 
3512  // Handle misc casts we want to ignore.
3513  if (CE->getCastKind() == CK_NoOp ||
3514  CE->getCastKind() == CK_LValueToRValue ||
3515  CE->getCastKind() == CK_ToUnion ||
3516  CE->getCastKind() == CK_ConstructorConversion ||
3517  CE->getCastKind() == CK_NonAtomicToAtomic ||
3518  CE->getCastKind() == CK_AtomicToNonAtomic ||
3519  CE->getCastKind() == CK_NullToPointer ||
3520  CE->getCastKind() == CK_IntToOCLSampler)
3521  return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3522 
3523  break;
3524  }
3525  case MaterializeTemporaryExprClass:
3526  return cast<MaterializeTemporaryExpr>(this)
3527  ->getSubExpr()
3528  ->isConstantInitializer(Ctx, false, Culprit);
3529 
3530  case SubstNonTypeTemplateParmExprClass:
3531  return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement()
3532  ->isConstantInitializer(Ctx, false, Culprit);
3533  case CXXDefaultArgExprClass:
3534  return cast<CXXDefaultArgExpr>(this)->getExpr()
3535  ->isConstantInitializer(Ctx, false, Culprit);
3536  case CXXDefaultInitExprClass:
3537  return cast<CXXDefaultInitExpr>(this)->getExpr()
3538  ->isConstantInitializer(Ctx, false, Culprit);
3539  }
3540  // Allow certain forms of UB in constant initializers: signed integer
3541  // overflow and floating-point division by zero. We'll give a warning on
3542  // these, but they're common enough that we have to accept them.
3544  return true;
3545  if (Culprit)
3546  *Culprit = this;
3547  return false;
3548 }
3549 
3551  unsigned BuiltinID = getBuiltinCallee();
3552  if (BuiltinID != Builtin::BI__assume &&
3553  BuiltinID != Builtin::BI__builtin_assume)
3554  return false;
3555 
3556  const Expr* Arg = getArg(0);
3557  bool ArgVal;
3558  return !Arg->isValueDependent() &&
3559  Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && !ArgVal;
3560 }
3561 
3563  return getBuiltinCallee() == Builtin::BImove;
3564 }
3565 
3566 namespace {
3567  /// Look for any side effects within a Stmt.
3568  class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> {
3570  const bool IncludePossibleEffects;
3571  bool HasSideEffects;
3572 
3573  public:
3574  explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible)
3575  : Inherited(Context),
3576  IncludePossibleEffects(IncludePossible), HasSideEffects(false) { }
3577 
3578  bool hasSideEffects() const { return HasSideEffects; }
3579 
3580  void VisitDecl(const Decl *D) {
3581  if (!D)
3582  return;
3583 
3584  // We assume the caller checks subexpressions (eg, the initializer, VLA
3585  // bounds) for side-effects on our behalf.
3586  if (auto *VD = dyn_cast<VarDecl>(D)) {
3587  // Registering a destructor is a side-effect.
3588  if (IncludePossibleEffects && VD->isThisDeclarationADefinition() &&
3589  VD->needsDestruction(Context))
3590  HasSideEffects = true;
3591  }
3592  }
3593 
3594  void VisitDeclStmt(const DeclStmt *DS) {
3595  for (auto *D : DS->decls())
3596  VisitDecl(D);
3597  Inherited::VisitDeclStmt(DS);
3598  }
3599 
3600  void VisitExpr(const Expr *E) {
3601  if (!HasSideEffects &&
3602  E->HasSideEffects(Context, IncludePossibleEffects))
3603  HasSideEffects = true;
3604  }
3605  };
3606 }
3607 
3609  bool IncludePossibleEffects) const {
3610  // In circumstances where we care about definite side effects instead of
3611  // potential side effects, we want to ignore expressions that are part of a
3612  // macro expansion as a potential side effect.
3613  if (!IncludePossibleEffects && getExprLoc().isMacroID())
3614  return false;
3615 
3616  switch (getStmtClass()) {
3617  case NoStmtClass:
3618  #define ABSTRACT_STMT(Type)
3619  #define STMT(Type, Base) case Type##Class:
3620  #define EXPR(Type, Base)
3621  #include "clang/AST/StmtNodes.inc"
3622  llvm_unreachable("unexpected Expr kind");
3623 
3624  case DependentScopeDeclRefExprClass:
3625  case CXXUnresolvedConstructExprClass:
3626  case CXXDependentScopeMemberExprClass:
3627  case UnresolvedLookupExprClass:
3628  case UnresolvedMemberExprClass:
3629  case PackExpansionExprClass:
3630  case SubstNonTypeTemplateParmPackExprClass:
3631  case FunctionParmPackExprClass:
3632  case TypoExprClass:
3633  case RecoveryExprClass:
3634  case CXXFoldExprClass:
3635  // Make a conservative assumption for dependent nodes.
3636  return IncludePossibleEffects;
3637 
3638  case DeclRefExprClass:
3639  case ObjCIvarRefExprClass:
3640  case PredefinedExprClass:
3641  case IntegerLiteralClass:
3642  case FixedPointLiteralClass:
3643  case FloatingLiteralClass:
3644  case ImaginaryLiteralClass:
3645  case StringLiteralClass:
3646  case CharacterLiteralClass:
3647  case OffsetOfExprClass:
3648  case ImplicitValueInitExprClass:
3649  case UnaryExprOrTypeTraitExprClass:
3650  case AddrLabelExprClass:
3651  case GNUNullExprClass:
3652  case ArrayInitIndexExprClass:
3653  case NoInitExprClass:
3654  case CXXBoolLiteralExprClass:
3655  case CXXNullPtrLiteralExprClass:
3656  case CXXThisExprClass:
3657  case CXXScalarValueInitExprClass:
3658  case TypeTraitExprClass:
3659  case ArrayTypeTraitExprClass:
3660  case ExpressionTraitExprClass:
3661  case CXXNoexceptExprClass:
3662  case SizeOfPackExprClass:
3663  case ObjCStringLiteralClass:
3664  case ObjCEncodeExprClass:
3665  case ObjCBoolLiteralExprClass:
3666  case ObjCAvailabilityCheckExprClass:
3667  case CXXUuidofExprClass:
3668  case OpaqueValueExprClass:
3669  case SourceLocExprClass:
3670  case ConceptSpecializationExprClass:
3671  case RequiresExprClass:
3672  case SYCLBuiltinNumFieldsExprClass:
3673  case SYCLBuiltinFieldTypeExprClass:
3674  case SYCLBuiltinNumBasesExprClass:
3675  case SYCLBuiltinBaseTypeExprClass:
3676  case SYCLUniqueStableNameExprClass:
3677  case SYCLUniqueStableIdExprClass:
3678  // These never have a side-effect.
3679  return false;
3680 
3681  case PackIndexingExprClass:
3682  return cast<PackIndexingExpr>(this)->getSelectedExpr()->HasSideEffects(
3683  Ctx, IncludePossibleEffects);
3684  case ConstantExprClass:
3685  // FIXME: Move this into the "return false;" block above.
3686  return cast<ConstantExpr>(this)->getSubExpr()->HasSideEffects(
3687  Ctx, IncludePossibleEffects);
3688 
3689  case CallExprClass:
3690  case CXXOperatorCallExprClass:
3691  case CXXMemberCallExprClass:
3692  case CUDAKernelCallExprClass:
3693  case UserDefinedLiteralClass: {
3694  // We don't know a call definitely has side effects, except for calls
3695  // to pure/const functions that definitely don't.
3696  // If the call itself is considered side-effect free, check the operands.
3697  const Decl *FD = cast<CallExpr>(this)->getCalleeDecl();
3698  bool IsPure = FD && (FD->hasAttr<ConstAttr>() || FD->hasAttr<PureAttr>());
3699  if (IsPure || !IncludePossibleEffects)
3700  break;
3701  return true;
3702  }
3703 
3704  case BlockExprClass:
3705  case CXXBindTemporaryExprClass:
3706  if (!IncludePossibleEffects)
3707  break;
3708  return true;
3709 
3710  case MSPropertyRefExprClass:
3711  case MSPropertySubscriptExprClass:
3712  case CompoundAssignOperatorClass:
3713  case VAArgExprClass:
3714  case AtomicExprClass:
3715  case CXXThrowExprClass:
3716  case CXXNewExprClass:
3717  case CXXDeleteExprClass:
3718  case CoawaitExprClass:
3719  case DependentCoawaitExprClass:
3720  case CoyieldExprClass:
3721  // These always have a side-effect.
3722  return true;
3723 
3724  case StmtExprClass: {
3725  // StmtExprs have a side-effect if any substatement does.
3726  SideEffectFinder Finder(Ctx, IncludePossibleEffects);
3727  Finder.Visit(cast<StmtExpr>(this)->getSubStmt());
3728  return Finder.hasSideEffects();
3729  }
3730 
3731  case ExprWithCleanupsClass:
3732  if (IncludePossibleEffects)
3733  if (cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects())
3734  return true;
3735  break;
3736 
3737  case ParenExprClass:
3738  case ArraySubscriptExprClass:
3739  case MatrixSubscriptExprClass:
3740  case ArraySectionExprClass:
3741  case OMPArrayShapingExprClass:
3742  case OMPIteratorExprClass:
3743  case MemberExprClass:
3744  case ConditionalOperatorClass:
3745  case BinaryConditionalOperatorClass:
3746  case CompoundLiteralExprClass:
3747  case ExtVectorElementExprClass:
3748  case DesignatedInitExprClass:
3749  case DesignatedInitUpdateExprClass:
3750  case ArrayInitLoopExprClass:
3751  case ParenListExprClass:
3752  case CXXPseudoDestructorExprClass:
3753  case CXXRewrittenBinaryOperatorClass:
3754  case CXXStdInitializerListExprClass:
3755  case SubstNonTypeTemplateParmExprClass:
3756  case MaterializeTemporaryExprClass:
3757  case ShuffleVectorExprClass:
3758  case ConvertVectorExprClass:
3759  case AsTypeExprClass:
3760  case CXXParenListInitExprClass:
3761  // These have a side-effect if any subexpression does.
3762  break;
3763 
3764  case UnaryOperatorClass:
3765  if (cast<UnaryOperator>(this)->isIncrementDecrementOp())
3766  return true;
3767  break;
3768 
3769  case BinaryOperatorClass:
3770  if (cast<BinaryOperator>(this)->isAssignmentOp())
3771  return true;
3772  break;
3773 
3774  case InitListExprClass:
3775  // FIXME: The children for an InitListExpr doesn't include the array filler.
3776  if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller())
3777  if (E->HasSideEffects(Ctx, IncludePossibleEffects))
3778  return true;
3779  break;
3780 
3781  case GenericSelectionExprClass:
3782  return cast<GenericSelectionExpr>(this)->getResultExpr()->
3783  HasSideEffects(Ctx, IncludePossibleEffects);
3784 
3785  case ChooseExprClass:
3786  return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects(
3787  Ctx, IncludePossibleEffects);
3788 
3789  case CXXDefaultArgExprClass:
3790  return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(
3791  Ctx, IncludePossibleEffects);
3792 
3793  case CXXDefaultInitExprClass: {
3794  const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField();
3795  if (const Expr *E = FD->getInClassInitializer())
3796  return E->HasSideEffects(Ctx, IncludePossibleEffects);
3797  // If we've not yet parsed the initializer, assume it has side-effects.
3798  return true;
3799  }
3800 
3801  case CXXDynamicCastExprClass: {
3802  // A dynamic_cast expression has side-effects if it can throw.
3803  const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this);
3804  if (DCE->getTypeAsWritten()->isReferenceType() &&
3805  DCE->getCastKind() == CK_Dynamic)
3806  return true;
3807  }
3808  [[fallthrough]];
3809  case ImplicitCastExprClass:
3810  case CStyleCastExprClass:
3811  case CXXStaticCastExprClass:
3812  case CXXReinterpretCastExprClass:
3813  case CXXConstCastExprClass:
3814  case CXXAddrspaceCastExprClass:
3815  case CXXFunctionalCastExprClass:
3816  case BuiltinBitCastExprClass: {
3817  // While volatile reads are side-effecting in both C and C++, we treat them
3818  // as having possible (not definite) side-effects. This allows idiomatic
3819  // code to behave without warning, such as sizeof(*v) for a volatile-
3820  // qualified pointer.
3821  if (!IncludePossibleEffects)
3822  break;
3823 
3824  const CastExpr *CE = cast<CastExpr>(this);
3825  if (CE->getCastKind() == CK_LValueToRValue &&
3827  return true;
3828  break;
3829  }
3830 
3831  case CXXTypeidExprClass:
3832  // typeid might throw if its subexpression is potentially-evaluated, so has
3833  // side-effects in that case whether or not its subexpression does.
3834  return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated();
3835 
3836  case CXXConstructExprClass:
3837  case CXXTemporaryObjectExprClass: {
3838  const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
3839  if (!CE->getConstructor()->isTrivial() && IncludePossibleEffects)
3840  return true;
3841  // A trivial constructor does not add any side-effects of its own. Just look
3842  // at its arguments.
3843  break;
3844  }
3845 
3846  case CXXInheritedCtorInitExprClass: {
3847  const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this);
3848  if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects)
3849  return true;
3850  break;
3851  }
3852 
3853  case LambdaExprClass: {
3854  const LambdaExpr *LE = cast<LambdaExpr>(this);
3855  for (Expr *E : LE->capture_inits())
3856  if (E && E->HasSideEffects(Ctx, IncludePossibleEffects))
3857  return true;
3858  return false;
3859  }
3860 
3861  case PseudoObjectExprClass: {
3862  // Only look for side-effects in the semantic form, and look past
3863  // OpaqueValueExpr bindings in that form.
3864  const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
3866  E = PO->semantics_end();
3867  I != E; ++I) {
3868  const Expr *Subexpr = *I;
3869  if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr))
3870  Subexpr = OVE->getSourceExpr();
3871  if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects))
3872  return true;
3873  }
3874  return false;
3875  }
3876 
3877  case ObjCBoxedExprClass:
3878  case ObjCArrayLiteralClass:
3879  case ObjCDictionaryLiteralClass:
3880  case ObjCSelectorExprClass:
3881  case ObjCProtocolExprClass:
3882  case ObjCIsaExprClass:
3883  case ObjCIndirectCopyRestoreExprClass:
3884  case ObjCSubscriptRefExprClass:
3885  case ObjCBridgedCastExprClass:
3886  case ObjCMessageExprClass:
3887  case ObjCPropertyRefExprClass:
3888  // FIXME: Classify these cases better.
3889  if (IncludePossibleEffects)
3890  return true;
3891  break;
3892  }
3893 
3894  // Recurse to children.
3895  for (const Stmt *SubStmt : children())
3896  if (SubStmt &&
3897  cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects))
3898  return true;
3899 
3900  return false;
3901 }
3902 
3904  if (auto Call = dyn_cast<CallExpr>(this))
3905  return Call->getFPFeaturesInEffect(LO);
3906  if (auto UO = dyn_cast<UnaryOperator>(this))
3907  return UO->getFPFeaturesInEffect(LO);
3908  if (auto BO = dyn_cast<BinaryOperator>(this))
3909  return BO->getFPFeaturesInEffect(LO);
3910  if (auto Cast = dyn_cast<CastExpr>(this))
3911  return Cast->getFPFeaturesInEffect(LO);
3913 }
3914 
3915 namespace {
3916  /// Look for a call to a non-trivial function within an expression.
3917  class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder>
3918  {
3920 
3921  bool NonTrivial;
3922 
3923  public:
3924  explicit NonTrivialCallFinder(const ASTContext &Context)
3925  : Inherited(Context), NonTrivial(false) { }
3926 
3927  bool hasNonTrivialCall() const { return NonTrivial; }
3928 
3929  void VisitCallExpr(const CallExpr *E) {
3930  if (const CXXMethodDecl *Method
3931  = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) {
3932  if (Method->isTrivial()) {
3933  // Recurse to children of the call.
3934  Inherited::VisitStmt(E);
3935  return;
3936  }
3937  }
3938 
3939  NonTrivial = true;
3940  }
3941 
3942  void VisitCXXConstructExpr(const CXXConstructExpr *E) {
3943  if (E->getConstructor()->isTrivial()) {
3944  // Recurse to children of the call.
3945  Inherited::VisitStmt(E);
3946  return;
3947  }
3948 
3949  NonTrivial = true;
3950  }
3951 
3952  void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
3953  // Destructor of the temporary might be null if destructor declaration
3954  // is not valid.
3955  if (const CXXDestructorDecl *DtorDecl =
3956  E->getTemporary()->getDestructor()) {
3957  if (DtorDecl->isTrivial()) {
3958  Inherited::VisitStmt(E);
3959  return;
3960  }
3961  }
3962 
3963  NonTrivial = true;
3964  }
3965  };
3966 }
3967 
3968 bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const {
3969  NonTrivialCallFinder Finder(Ctx);
3970  Finder.Visit(this);
3971  return Finder.hasNonTrivialCall();
3972 }
3973 
3974 /// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null
3975 /// pointer constant or not, as well as the specific kind of constant detected.
3976 /// Null pointer constants can be integer constant expressions with the
3977 /// value zero, casts of zero to void*, nullptr (C++0X), or __null
3978 /// (a GNU extension).
3982  if (isValueDependent() &&
3983  (!Ctx.getLangOpts().CPlusPlus11 || Ctx.getLangOpts().MSVCCompat)) {
3984  // Error-dependent expr should never be a null pointer.
3985  if (containsErrors())
3986  return NPCK_NotNull;
3987  switch (NPC) {
3989  llvm_unreachable("Unexpected value dependent expression!");
3991  if (isTypeDependent() || getType()->isIntegralType(Ctx))
3992  return NPCK_ZeroExpression;
3993  else
3994  return NPCK_NotNull;
3995 
3997  return NPCK_NotNull;
3998  }
3999  }
4000 
4001  // Strip off a cast to void*, if it exists. Except in C++.
4002  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
4003  if (!Ctx.getLangOpts().CPlusPlus) {
4004  // Check that it is a cast to void*.
4005  if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
4006  QualType Pointee = PT->getPointeeType();
4007  Qualifiers Qs = Pointee.getQualifiers();
4008  // Only (void*)0 or equivalent are treated as nullptr. If pointee type
4009  // has non-default address space it is not treated as nullptr.
4010  // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
4011  // since it cannot be assigned to a pointer to constant address space.
4012  if (Ctx.getLangOpts().OpenCL &&
4014  Qs.removeAddressSpace();
4015 
4016  if (Pointee->isVoidType() && Qs.empty() && // to void*
4017  CE->getSubExpr()->getType()->isIntegerType()) // from int
4018  return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4019  }
4020  }
4021  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
4022  // Ignore the ImplicitCastExpr type entirely.
4023  return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4024  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
4025  // Accept ((void*)0) as a null pointer constant, as many other
4026  // implementations do.
4027  return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4028  } else if (const GenericSelectionExpr *GE =
4029  dyn_cast<GenericSelectionExpr>(this)) {
4030  if (GE->isResultDependent())
4031  return NPCK_NotNull;
4032  return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC);
4033  } else if (const ChooseExpr *CE = dyn_cast<ChooseExpr>(this)) {
4034  if (CE->isConditionDependent())
4035  return NPCK_NotNull;
4036  return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC);
4037  } else if (const CXXDefaultArgExpr *DefaultArg
4038  = dyn_cast<CXXDefaultArgExpr>(this)) {
4039  // See through default argument expressions.
4040  return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
4041  } else if (const CXXDefaultInitExpr *DefaultInit
4042  = dyn_cast<CXXDefaultInitExpr>(this)) {
4043  // See through default initializer expressions.
4044  return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC);
4045  } else if (isa<GNUNullExpr>(this)) {
4046  // The GNU __null extension is always a null pointer constant.
4047  return NPCK_GNUNull;
4048  } else if (const MaterializeTemporaryExpr *M
4049  = dyn_cast<MaterializeTemporaryExpr>(this)) {
4050  return M->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4051  } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) {
4052  if (const Expr *Source = OVE->getSourceExpr())
4053  return Source->isNullPointerConstant(Ctx, NPC);
4054  }
4055 
4056  // If the expression has no type information, it cannot be a null pointer
4057  // constant.
4058  if (getType().isNull())
4059  return NPCK_NotNull;
4060 
4061  // C++11/C23 nullptr_t is always a null pointer constant.
4062  if (getType()->isNullPtrType())
4063  return NPCK_CXX11_nullptr;
4064 
4065  if (const RecordType *UT = getType()->getAsUnionType())
4066  if (!Ctx.getLangOpts().CPlusPlus11 &&
4067  UT && UT->getDecl()->hasAttr<TransparentUnionAttr>())
4068  if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){
4069  const Expr *InitExpr = CLE->getInitializer();
4070  if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr))
4071  return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC);
4072  }
4073  // This expression must be an integer type.
4074  if (!getType()->isIntegerType() ||
4075  (Ctx.getLangOpts().CPlusPlus && getType()->isEnumeralType()))
4076  return NPCK_NotNull;
4077 
4078  if (Ctx.getLangOpts().CPlusPlus11) {
4079  // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with
4080  // value zero or a prvalue of type std::nullptr_t.
4081  // Microsoft mode permits C++98 rules reflecting MSVC behavior.
4082  const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this);
4083  if (Lit && !Lit->getValue())
4084  return NPCK_ZeroLiteral;
4085  if (!Ctx.getLangOpts().MSVCCompat || !isCXX98IntegralConstantExpr(Ctx))
4086  return NPCK_NotNull;
4087  } else {
4088  // If we have an integer constant expression, we need to *evaluate* it and
4089  // test for the value 0.
4090  if (!isIntegerConstantExpr(Ctx))
4091  return NPCK_NotNull;
4092  }
4093 
4094  if (EvaluateKnownConstInt(Ctx) != 0)
4095  return NPCK_NotNull;
4096 
4097  if (isa<IntegerLiteral>(this))
4098  return NPCK_ZeroLiteral;
4099  return NPCK_ZeroExpression;
4100 }
4101 
4102 /// If this expression is an l-value for an Objective C
4103 /// property, find the underlying property reference expression.
4105  const Expr *E = this;
4106  while (true) {
4107  assert((E->isLValue() && E->getObjectKind() == OK_ObjCProperty) &&
4108  "expression is not a property reference");
4109  E = E->IgnoreParenCasts();
4110  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
4111  if (BO->getOpcode() == BO_Comma) {
4112  E = BO->getRHS();
4113  continue;
4114  }
4115  }
4116 
4117  break;
4118  }
4119 
4120  return cast<ObjCPropertyRefExpr>(E);
4121 }
4122 
4123 bool Expr::isObjCSelfExpr() const {
4124  const Expr *E = IgnoreParenImpCasts();
4125 
4126  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
4127  if (!DRE)
4128  return false;
4129 
4130  const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl());
4131  if (!Param)
4132  return false;
4133 
4134  const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext());
4135  if (!M)
4136  return false;
4137 
4138  return M->getSelfDecl() == Param;
4139 }
4140 
4142  Expr *E = this->IgnoreParens();
4143 
4144  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
4145  if (ICE->getCastKind() == CK_LValueToRValue ||
4146  (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp))
4147  E = ICE->getSubExpr()->IgnoreParens();
4148  else
4149  break;
4150  }
4151 
4152  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
4153  if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
4154  if (Field->isBitField())
4155  return Field;
4156 
4157  if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) {
4158  FieldDecl *Ivar = IvarRef->getDecl();
4159  if (Ivar->isBitField())
4160  return Ivar;
4161  }
4162 
4163  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) {
4164  if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
4165  if (Field->isBitField())
4166  return Field;
4167 
4168  if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl()))
4169  if (Expr *E = BD->getBinding())
4170  return E->getSourceBitField();
4171  }
4172 
4173  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) {
4174  if (BinOp->isAssignmentOp() && BinOp->getLHS())
4175  return BinOp->getLHS()->getSourceBitField();
4176 
4177  if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS())
4178  return BinOp->getRHS()->getSourceBitField();
4179  }
4180 
4181  if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E))
4182  if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp())
4183  return UnOp->getSubExpr()->getSourceBitField();
4184 
4185  return nullptr;
4186 }
4187 
4189  Expr *E = this->IgnoreParenImpCasts();
4190  if (auto *DRE = dyn_cast<DeclRefExpr>(E))
4191  return dyn_cast<EnumConstantDecl>(DRE->getDecl());
4192  return nullptr;
4193 }
4194 
4196  // FIXME: Why do we not just look at the ObjectKind here?
4197  const Expr *E = this->IgnoreParens();
4198 
4199  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
4200  if (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp)
4201  E = ICE->getSubExpr()->IgnoreParens();
4202  else
4203  break;
4204  }
4205 
4206  if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E))
4207  return ASE->getBase()->getType()->isVectorType();
4208 
4209  if (isa<ExtVectorElementExpr>(E))
4210  return true;
4211 
4212  if (auto *DRE = dyn_cast<DeclRefExpr>(E))
4213  if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl()))
4214  if (auto *E = BD->getBinding())
4215  return E->refersToVectorElement();
4216 
4217  return false;
4218 }
4219 
4221  const Expr *E = this->IgnoreParenImpCasts();
4222 
4223  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
4224  if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
4225  if (VD->getStorageClass() == SC_Register &&
4226  VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
4227  return true;
4228 
4229  return false;
4230 }
4231 
4232 bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) {
4233  E1 = E1->IgnoreParens();
4234  E2 = E2->IgnoreParens();
4235 
4236  if (E1->getStmtClass() != E2->getStmtClass())
4237  return false;
4238 
4239  switch (E1->getStmtClass()) {
4240  default:
4241  return false;
4242  case CXXThisExprClass:
4243  return true;
4244  case DeclRefExprClass: {
4245  // DeclRefExpr without an ImplicitCastExpr can happen for integral
4246  // template parameters.
4247  const auto *DRE1 = cast<DeclRefExpr>(E1);
4248  const auto *DRE2 = cast<DeclRefExpr>(E2);
4249  return DRE1->isPRValue() && DRE2->isPRValue() &&
4250  DRE1->getDecl() == DRE2->getDecl();
4251  }
4252  case ImplicitCastExprClass: {
4253  // Peel off implicit casts.
4254  while (true) {
4255  const auto *ICE1 = dyn_cast<ImplicitCastExpr>(E1);
4256  const auto *ICE2 = dyn_cast<ImplicitCastExpr>(E2);
4257  if (!ICE1 || !ICE2)
4258  return false;
4259  if (ICE1->getCastKind() != ICE2->getCastKind())
4260  return false;
4261  E1 = ICE1->getSubExpr()->IgnoreParens();
4262  E2 = ICE2->getSubExpr()->IgnoreParens();
4263  // The final cast must be one of these types.
4264  if (ICE1->getCastKind() == CK_LValueToRValue ||
4265  ICE1->getCastKind() == CK_ArrayToPointerDecay ||
4266  ICE1->getCastKind() == CK_FunctionToPointerDecay) {
4267  break;
4268  }
4269  }
4270 
4271  const auto *DRE1 = dyn_cast<DeclRefExpr>(E1);
4272  const auto *DRE2 = dyn_cast<DeclRefExpr>(E2);
4273  if (DRE1 && DRE2)
4274  return declaresSameEntity(DRE1->getDecl(), DRE2->getDecl());
4275 
4276  const auto *Ivar1 = dyn_cast<ObjCIvarRefExpr>(E1);
4277  const auto *Ivar2 = dyn_cast<ObjCIvarRefExpr>(E2);
4278  if (Ivar1 && Ivar2) {
4279  return Ivar1->isFreeIvar() && Ivar2->isFreeIvar() &&
4280  declaresSameEntity(Ivar1->getDecl(), Ivar2->getDecl());
4281  }
4282 
4283  const auto *Array1 = dyn_cast<ArraySubscriptExpr>(E1);
4284  const auto *Array2 = dyn_cast<ArraySubscriptExpr>(E2);
4285  if (Array1 && Array2) {
4286  if (!isSameComparisonOperand(Array1->getBase(), Array2->getBase()))
4287  return false;
4288 
4289  auto Idx1 = Array1->getIdx();
4290  auto Idx2 = Array2->getIdx();
4291  const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1);
4292  const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2);
4293  if (Integer1 && Integer2) {
4294  if (!llvm::APInt::isSameValue(Integer1->getValue(),
4295  Integer2->getValue()))
4296  return false;
4297  } else {
4298  if (!isSameComparisonOperand(Idx1, Idx2))
4299  return false;
4300  }
4301 
4302  return true;
4303  }
4304 
4305  // Walk the MemberExpr chain.
4306  while (isa<MemberExpr>(E1) && isa<MemberExpr>(E2)) {
4307  const auto *ME1 = cast<MemberExpr>(E1);
4308  const auto *ME2 = cast<MemberExpr>(E2);
4309  if (!declaresSameEntity(ME1->getMemberDecl(), ME2->getMemberDecl()))
4310  return false;
4311  if (const auto *D = dyn_cast<VarDecl>(ME1->getMemberDecl()))
4312  if (D->isStaticDataMember())
4313  return true;
4314  E1 = ME1->getBase()->IgnoreParenImpCasts();
4315  E2 = ME2->getBase()->IgnoreParenImpCasts();
4316  }
4317 
4318  if (isa<CXXThisExpr>(E1) && isa<CXXThisExpr>(E2))
4319  return true;
4320 
4321  // A static member variable can end the MemberExpr chain with either
4322  // a MemberExpr or a DeclRefExpr.
4323  auto getAnyDecl = [](const Expr *E) -> const ValueDecl * {
4324  if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
4325  return DRE->getDecl();
4326  if (const auto *ME = dyn_cast<MemberExpr>(E))
4327  return ME->getMemberDecl();
4328  return nullptr;
4329  };
4330 
4331  const ValueDecl *VD1 = getAnyDecl(E1);
4332  const ValueDecl *VD2 = getAnyDecl(E2);
4333  return declaresSameEntity(VD1, VD2);
4334  }
4335  }
4336 }
4337 
4338 /// isArrow - Return true if the base expression is a pointer to vector,
4339 /// return false if the base expression is a vector.
4341  return getBase()->getType()->isPointerType();
4342 }
4343 
4345  if (const VectorType *VT = getType()->getAs<VectorType>())
4346  return VT->getNumElements();
4347  return 1;
4348 }
4349 
4350 /// containsDuplicateElements - Return true if any element access is repeated.
4352  // FIXME: Refactor this code to an accessor on the AST node which returns the
4353  // "type" of component access, and share with code below and in Sema.
4354  StringRef Comp = Accessor->getName();
4355 
4356  // Halving swizzles do not contain duplicate elements.
4357  if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
4358  return false;
4359 
4360  // Advance past s-char prefix on hex swizzles.
4361  if (Comp[0] == 's' || Comp[0] == 'S')
4362  Comp = Comp.substr(1);
4363 
4364  for (unsigned i = 0, e = Comp.size(); i != e; ++i)
4365  if (Comp.substr(i + 1).contains(Comp[i]))
4366  return true;
4367 
4368  return false;
4369 }
4370 
4371 /// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
4373  SmallVectorImpl<uint32_t> &Elts) const {
4374  StringRef Comp = Accessor->getName();
4375  bool isNumericAccessor = false;
4376  if (Comp[0] == 's' || Comp[0] == 'S') {
4377  Comp = Comp.substr(1);
4378  isNumericAccessor = true;
4379  }
4380 
4381  bool isHi = Comp == "hi";
4382  bool isLo = Comp == "lo";
4383  bool isEven = Comp == "even";
4384  bool isOdd = Comp == "odd";
4385 
4386  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
4387  uint64_t Index;
4388 
4389  if (isHi)
4390  Index = e + i;
4391  else if (isLo)
4392  Index = i;
4393  else if (isEven)
4394  Index = 2 * i;
4395  else if (isOdd)
4396  Index = 2 * i + 1;
4397  else
4398  Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor);
4399 
4400  Elts.push_back(Index);
4401  }
4402 }
4403 
4406  SourceLocation RP)
4407  : Expr(ShuffleVectorExprClass, Type, VK_PRValue, OK_Ordinary),
4408  BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) {
4409  SubExprs = new (C) Stmt*[args.size()];
4410  for (unsigned i = 0; i != args.size(); i++)
4411  SubExprs[i] = args[i];
4412 
4414 }
4415 
4417  if (SubExprs) C.Deallocate(SubExprs);
4418 
4419  this->NumExprs = Exprs.size();
4420  SubExprs = new (C) Stmt*[NumExprs];
4421  memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size());
4422 }
4423 
4424 GenericSelectionExpr::GenericSelectionExpr(
4425  const ASTContext &, SourceLocation GenericLoc, Expr *ControllingExpr,
4426  ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4427  SourceLocation DefaultLoc, SourceLocation RParenLoc,
4428  bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
4429  : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4430  AssocExprs[ResultIndex]->getValueKind(),
4431  AssocExprs[ResultIndex]->getObjectKind()),
4432  NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4433  IsExprPredicate(true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4434  assert(AssocTypes.size() == AssocExprs.size() &&
4435  "Must have the same number of association expressions"
4436  " and TypeSourceInfo!");
4437  assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!");
4438 
4439  GenericSelectionExprBits.GenericLoc = GenericLoc;
4440  getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4441  ControllingExpr;
4442  std::copy(AssocExprs.begin(), AssocExprs.end(),
4443  getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4444  std::copy(AssocTypes.begin(), AssocTypes.end(),
4445  getTrailingObjects<TypeSourceInfo *>() +
4446  getIndexOfStartOfAssociatedTypes());
4447 
4448  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4449 }
4450 
4451 GenericSelectionExpr::GenericSelectionExpr(
4452  const ASTContext &, SourceLocation GenericLoc,
4453  TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
4454  ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
4455  SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
4456  unsigned ResultIndex)
4457  : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4458  AssocExprs[ResultIndex]->getValueKind(),
4459  AssocExprs[ResultIndex]->getObjectKind()),
4460  NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4461  IsExprPredicate(false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4462  assert(AssocTypes.size() == AssocExprs.size() &&
4463  "Must have the same number of association expressions"
4464  " and TypeSourceInfo!");
4465  assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!");
4466 
4467  GenericSelectionExprBits.GenericLoc = GenericLoc;
4468  getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4469  ControllingType;
4470  std::copy(AssocExprs.begin(), AssocExprs.end(),
4471  getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4472  std::copy(AssocTypes.begin(), AssocTypes.end(),
4473  getTrailingObjects<TypeSourceInfo *>() +
4474  getIndexOfStartOfAssociatedTypes());
4475 
4476  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4477 }
4478 
4479 GenericSelectionExpr::GenericSelectionExpr(
4480  const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4481  ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4482  SourceLocation DefaultLoc, SourceLocation RParenLoc,
4483  bool ContainsUnexpandedParameterPack)
4484  : Expr(GenericSelectionExprClass, Context.DependentTy, VK_PRValue,
4485  OK_Ordinary),
4486  NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4487  IsExprPredicate(true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4488  assert(AssocTypes.size() == AssocExprs.size() &&
4489  "Must have the same number of association expressions"
4490  " and TypeSourceInfo!");
4491 
4492  GenericSelectionExprBits.GenericLoc = GenericLoc;
4493  getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4494  ControllingExpr;
4495  std::copy(AssocExprs.begin(), AssocExprs.end(),
4496  getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4497  std::copy(AssocTypes.begin(), AssocTypes.end(),
4498  getTrailingObjects<TypeSourceInfo *>() +
4499  getIndexOfStartOfAssociatedTypes());
4500 
4501  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4502 }
4503 
4504 GenericSelectionExpr::GenericSelectionExpr(
4505  const ASTContext &Context, SourceLocation GenericLoc,
4506  TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
4507  ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
4508  SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack)
4509  : Expr(GenericSelectionExprClass, Context.DependentTy, VK_PRValue,
4510  OK_Ordinary),
4511  NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4512  IsExprPredicate(false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4513  assert(AssocTypes.size() == AssocExprs.size() &&
4514  "Must have the same number of association expressions"
4515  " and TypeSourceInfo!");
4516 
4517  GenericSelectionExprBits.GenericLoc = GenericLoc;
4518  getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4519  ControllingType;
4520  std::copy(AssocExprs.begin(), AssocExprs.end(),
4521  getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4522  std::copy(AssocTypes.begin(), AssocTypes.end(),
4523  getTrailingObjects<TypeSourceInfo *>() +
4524  getIndexOfStartOfAssociatedTypes());
4525 
4526  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4527 }
4528 
4529 GenericSelectionExpr::GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs)
4530  : Expr(GenericSelectionExprClass, Empty), NumAssocs(NumAssocs) {}
4531 
4533  const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4534  ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4535  SourceLocation DefaultLoc, SourceLocation RParenLoc,
4536  bool ContainsUnexpandedParameterPack, unsigned ResultIndex) {
4537  unsigned NumAssocs = AssocExprs.size();
4538  void *Mem = Context.Allocate(
4539  totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4540  alignof(GenericSelectionExpr));
4541  return new (Mem) GenericSelectionExpr(
4542  Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4543  RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4544 }
4545 
4547  const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4548  ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4549  SourceLocation DefaultLoc, SourceLocation RParenLoc,
4550  bool ContainsUnexpandedParameterPack) {
4551  unsigned NumAssocs = AssocExprs.size();
4552  void *Mem = Context.Allocate(
4553  totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4554  alignof(GenericSelectionExpr));
4555  return new (Mem) GenericSelectionExpr(
4556  Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4557  RParenLoc, ContainsUnexpandedParameterPack);
4558 }
4559 
4561  const ASTContext &Context, SourceLocation GenericLoc,
4562  TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
4563  ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
4564  SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
4565  unsigned ResultIndex) {
4566  unsigned NumAssocs = AssocExprs.size();
4567  void *Mem = Context.Allocate(
4568  totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4569  alignof(GenericSelectionExpr));
4570  return new (Mem) GenericSelectionExpr(
4571  Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4572  RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4573 }
4574 
4576  const ASTContext &Context, SourceLocation GenericLoc,
4577  TypeSourceInfo *ControllingType, ArrayRef<TypeSourceInfo *> AssocTypes,
4578  ArrayRef<Expr *> AssocExprs, SourceLocation DefaultLoc,
4579  SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack) {
4580  unsigned NumAssocs = AssocExprs.size();
4581  void *Mem = Context.Allocate(
4582  totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4583  alignof(GenericSelectionExpr));
4584  return new (Mem) GenericSelectionExpr(
4585  Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4586  RParenLoc, ContainsUnexpandedParameterPack);
4587 }
4588 
4591  unsigned NumAssocs) {
4592  void *Mem = Context.Allocate(
4593  totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4594  alignof(GenericSelectionExpr));
4595  return new (Mem) GenericSelectionExpr(EmptyShell(), NumAssocs);
4596 }
4597 
4598 //===----------------------------------------------------------------------===//
4599 // DesignatedInitExpr
4600 //===----------------------------------------------------------------------===//
4601 
4603  assert(isFieldDesignator() && "Only valid on a field designator");
4604  if (FieldInfo.NameOrField & 0x01)
4605  return reinterpret_cast<IdentifierInfo *>(FieldInfo.NameOrField & ~0x01);
4606  return getFieldDecl()->getIdentifier();
4607 }
4608 
4609 DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty,
4610  llvm::ArrayRef<Designator> Designators,
4611  SourceLocation EqualOrColonLoc,
4612  bool GNUSyntax,
4613  ArrayRef<Expr *> IndexExprs, Expr *Init)
4614  : Expr(DesignatedInitExprClass, Ty, Init->getValueKind(),
4615  Init->getObjectKind()),
4616  EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
4617  NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) {
4618  this->Designators = new (C) Designator[NumDesignators];
4619 
4620  // Record the initializer itself.
4621  child_iterator Child = child_begin();
4622  *Child++ = Init;
4623 
4624  // Copy the designators and their subexpressions, computing
4625  // value-dependence along the way.
4626  unsigned IndexIdx = 0;
4627  for (unsigned I = 0; I != NumDesignators; ++I) {
4628  this->Designators[I] = Designators[I];
4629  if (this->Designators[I].isArrayDesignator()) {
4630  // Copy the index expressions into permanent storage.
4631  *Child++ = IndexExprs[IndexIdx++];
4632  } else if (this->Designators[I].isArrayRangeDesignator()) {
4633  // Copy the start/end expressions into permanent storage.
4634  *Child++ = IndexExprs[IndexIdx++];
4635  *Child++ = IndexExprs[IndexIdx++];
4636  }
4637  }
4638 
4639  assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions");
4641 }
4642 
4645  llvm::ArrayRef<Designator> Designators,
4646  ArrayRef<Expr*> IndexExprs,
4647  SourceLocation ColonOrEqualLoc,
4648  bool UsesColonSyntax, Expr *Init) {
4649  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
4650  alignof(DesignatedInitExpr));
4651  return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators,
4652  ColonOrEqualLoc, UsesColonSyntax,
4653  IndexExprs, Init);
4654 }
4655 
4657  unsigned NumIndexExprs) {
4658  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1),
4659  alignof(DesignatedInitExpr));
4660  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
4661 }
4662 
4664  const Designator *Desigs,
4665  unsigned NumDesigs) {
4666  Designators = new (C) Designator[NumDesigs];
4667  NumDesignators = NumDesigs;
4668  for (unsigned I = 0; I != NumDesigs; ++I)
4669  Designators[I] = Desigs[I];
4670 }
4671 
4673  DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this);
4674  if (size() == 1)
4675  return DIE->getDesignator(0)->getSourceRange();
4676  return SourceRange(DIE->getDesignator(0)->getBeginLoc(),
4677  DIE->getDesignator(size() - 1)->getEndLoc());
4678 }
4679 
4681  auto *DIE = const_cast<DesignatedInitExpr *>(this);
4682  Designator &First = *DIE->getDesignator(0);
4683  if (First.isFieldDesignator()) {
4684  // Skip past implicit designators for anonymous structs/unions, since
4685  // these do not have valid source locations.
4686  for (unsigned int i = 0; i < DIE->size(); i++) {
4687  Designator &Des = *DIE->getDesignator(i);
4688  SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
4689  if (!retval.isValid())
4690  continue;
4691  return retval;
4692  }
4693  }
4694  return First.getLBracketLoc();
4695 }
4696 
4698  return getInit()->getEndLoc();
4699 }
4700 
4702  assert(D.isArrayDesignator() && "Requires array designator");
4703  return getSubExpr(D.getArrayIndex() + 1);
4704 }
4705 
4707  assert(D.isArrayRangeDesignator() && "Requires array range designator");
4708  return getSubExpr(D.getArrayIndex() + 1);
4709 }
4710 
4712  assert(D.isArrayRangeDesignator() && "Requires array range designator");
4713  return getSubExpr(D.getArrayIndex() + 2);
4714 }
4715 
4716 /// Replaces the designator at index @p Idx with the series
4717 /// of designators in [First, Last).
4719  const Designator *First,
4720  const Designator *Last) {
4721  unsigned NumNewDesignators = Last - First;
4722  if (NumNewDesignators == 0) {
4723  std::copy_backward(Designators + Idx + 1,
4724  Designators + NumDesignators,
4725  Designators + Idx);
4726  --NumNewDesignators;
4727  return;
4728  }
4729  if (NumNewDesignators == 1) {
4730  Designators[Idx] = *First;
4731  return;
4732  }
4733 
4734  Designator *NewDesignators
4735  = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
4736  std::copy(Designators, Designators + Idx, NewDesignators);
4737  std::copy(First, Last, NewDesignators + Idx);
4738  std::copy(Designators + Idx + 1, Designators + NumDesignators,
4739  NewDesignators + Idx + NumNewDesignators);
4740  Designators = NewDesignators;
4741  NumDesignators = NumDesignators - 1 + NumNewDesignators;
4742 }
4743 
4745  SourceLocation lBraceLoc,
4746  Expr *baseExpr,
4747  SourceLocation rBraceLoc)
4748  : Expr(DesignatedInitUpdateExprClass, baseExpr->getType(), VK_PRValue,
4749  OK_Ordinary) {
4750  BaseAndUpdaterExprs[0] = baseExpr;
4751 
4752  InitListExpr *ILE =
4753  new (C) InitListExpr(C, lBraceLoc, std::nullopt, rBraceLoc);
4754  ILE->setType(baseExpr->getType());
4755  BaseAndUpdaterExprs[1] = ILE;
4756 
4757  // FIXME: this is wrong, set it correctly.
4759 }
4760 
4762  return getBase()->getBeginLoc();
4763 }
4764 
4766  return getBase()->getEndLoc();
4767 }
4768 
4769 ParenListExpr::ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs,
4770  SourceLocation RParenLoc)
4771  : Expr(ParenListExprClass, QualType(), VK_PRValue, OK_Ordinary),
4772  LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4773  ParenListExprBits.NumExprs = Exprs.size();
4774 
4775  for (unsigned I = 0, N = Exprs.size(); I != N; ++I)
4776  getTrailingObjects<Stmt *>()[I] = Exprs[I];
4778 }
4779 
4780 ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs)
4781  : Expr(ParenListExprClass, Empty) {
4782  ParenListExprBits.NumExprs = NumExprs;
4783 }
4784 
4786  SourceLocation LParenLoc,
4787  ArrayRef<Expr *> Exprs,
4788  SourceLocation RParenLoc) {
4789  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(Exprs.size()),
4790  alignof(ParenListExpr));
4791  return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc);
4792 }
4793 
4795  unsigned NumExprs) {
4796  void *Mem =
4797  Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumExprs), alignof(ParenListExpr));
4798  return new (Mem) ParenListExpr(EmptyShell(), NumExprs);
4799 }
4800 
4802  Opcode opc, QualType ResTy, ExprValueKind VK,
4803  ExprObjectKind OK, SourceLocation opLoc,
4804  FPOptionsOverride FPFeatures)
4805  : Expr(BinaryOperatorClass, ResTy, VK, OK) {
4806  BinaryOperatorBits.Opc = opc;
4807  assert(!isCompoundAssignmentOp() &&
4808  "Use CompoundAssignOperator for compound assignments");
4809  BinaryOperatorBits.OpLoc = opLoc;
4810  SubExprs[LHS] = lhs;
4811  SubExprs[RHS] = rhs;
4812  BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4813  if (hasStoredFPFeatures())
4814  setStoredFPFeatures(FPFeatures);
4816 }
4817 
4819  Opcode opc, QualType ResTy, ExprValueKind VK,
4820  ExprObjectKind OK, SourceLocation opLoc,
4821  FPOptionsOverride FPFeatures, bool dead2)
4822  : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) {
4823  BinaryOperatorBits.Opc = opc;
4824  assert(isCompoundAssignmentOp() &&
4825  "Use CompoundAssignOperator for compound assignments");
4826  BinaryOperatorBits.OpLoc = opLoc;
4827  SubExprs[LHS] = lhs;
4828  SubExprs[RHS] = rhs;
4829  BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4830  if (hasStoredFPFeatures())
4831  setStoredFPFeatures(FPFeatures);
4833 }
4834 
4836  bool HasFPFeatures) {
4837  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4838  void *Mem =
4839  C.Allocate(sizeof(BinaryOperator) + Extra, alignof(BinaryOperator));
4840  return new (Mem) BinaryOperator(EmptyShell());
4841 }
4842 
4844  Expr *rhs, Opcode opc, QualType ResTy,
4846  SourceLocation opLoc,
4847  FPOptionsOverride FPFeatures) {
4848  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4849  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4850  void *Mem =
4851  C.Allocate(sizeof(BinaryOperator) + Extra, alignof(BinaryOperator));
4852  return new (Mem)
4853  BinaryOperator(C, lhs, rhs, opc, ResTy, VK, OK, opLoc, FPFeatures);
4854 }
4855 
4857 CompoundAssignOperator::CreateEmpty(const ASTContext &C, bool HasFPFeatures) {
4858  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4859  void *Mem = C.Allocate(sizeof(CompoundAssignOperator) + Extra,
4860  alignof(CompoundAssignOperator));
4861  return new (Mem) CompoundAssignOperator(C, EmptyShell(), HasFPFeatures);
4862 }
4863 
4866  Opcode opc, QualType ResTy, ExprValueKind VK,
4867  ExprObjectKind OK, SourceLocation opLoc,
4868  FPOptionsOverride FPFeatures,
4869  QualType CompLHSType, QualType CompResultType) {
4870  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4871  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4872  void *Mem = C.Allocate(sizeof(CompoundAssignOperator) + Extra,
4873  alignof(CompoundAssignOperator));
4874  return new (Mem)
4875  CompoundAssignOperator(C, lhs, rhs, opc, ResTy, VK, OK, opLoc, FPFeatures,
4876  CompLHSType, CompResultType);
4877 }
4878 
4880  bool hasFPFeatures) {
4881  void *Mem = C.Allocate(totalSizeToAlloc<FPOptionsOverride>(hasFPFeatures),
4882  alignof(UnaryOperator));
4883  return new (Mem) UnaryOperator(hasFPFeatures, EmptyShell());
4884 }
4885 
4888  SourceLocation l, bool CanOverflow,
4889  FPOptionsOverride FPFeatures)
4890  : Expr(UnaryOperatorClass, type, VK, OK), Val(input) {
4891  UnaryOperatorBits.Opc = opc;
4892  UnaryOperatorBits.CanOverflow = CanOverflow;
4893  UnaryOperatorBits.Loc = l;
4894  UnaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4895  if (hasStoredFPFeatures())
4896  setStoredFPFeatures(FPFeatures);
4897  setDependence(computeDependence(this, Ctx));
4898 }
4899 
4901  Opcode opc, QualType type,
4903  SourceLocation l, bool CanOverflow,
4904  FPOptionsOverride FPFeatures) {
4905  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4906  unsigned Size = totalSizeToAlloc<FPOptionsOverride>(HasFPFeatures);
4907  void *Mem = C.Allocate(Size, alignof(UnaryOperator));
4908  return new (Mem)
4909  UnaryOperator(C, input, opc, type, VK, OK, l, CanOverflow, FPFeatures);
4910 }
4911 
4913  if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e))
4914  e = ewc->getSubExpr();
4915  if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e))
4916  e = m->getSubExpr();
4917  e = cast<CXXConstructExpr>(e)->getArg(0);
4918  while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
4919  e = ice->getSubExpr();
4920  return cast<OpaqueValueExpr>(e);
4921 }
4922 
4924  EmptyShell sh,
4925  unsigned numSemanticExprs) {
4926  void *buffer =
4927  Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs),
4928  alignof(PseudoObjectExpr));
4929  return new(buffer) PseudoObjectExpr(sh, numSemanticExprs);
4930 }
4931 
4932 PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
4933  : Expr(PseudoObjectExprClass, shell) {
4934  PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1;
4935 }
4936 
4938  ArrayRef<Expr*> semantics,
4939  unsigned resultIndex) {
4940  assert(syntax && "no syntactic expression!");
4941  assert(semantics.size() && "no semantic expressions!");
4942 
4943  QualType type;
4944  ExprValueKind VK;
4945  if (resultIndex == NoResult) {
4946  type = C.VoidTy;
4947  VK = VK_PRValue;
4948  } else {
4949  assert(resultIndex < semantics.size());
4950  type = semantics[resultIndex]->getType();
4951  VK = semantics[resultIndex]->getValueKind();
4952  assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary);
4953  }
4954 
4955  void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1),
4956  alignof(PseudoObjectExpr));
4957  return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics,
4958  resultIndex);
4959 }
4960 
4961 PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK,
4962  Expr *syntax, ArrayRef<Expr *> semantics,
4963  unsigned resultIndex)
4964  : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) {
4965  PseudoObjectExprBits.NumSubExprs = semantics.size() + 1;
4966  PseudoObjectExprBits.ResultIndex = resultIndex + 1;
4967 
4968  for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) {
4969  Expr *E = (i == 0 ? syntax : semantics[i-1]);
4970  getSubExprsBuffer()[i] = E;
4971 
4972  if (isa<OpaqueValueExpr>(E))
4973  assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr &&
4974  "opaque-value semantic expressions for pseudo-object "
4975  "operations must have sources");
4976  }
4977 
4979 }
4980 
4981 //===----------------------------------------------------------------------===//
4982 // Child Iterators for iterating over subexpressions/substatements
4983 //===----------------------------------------------------------------------===//
4984 
4985 // UnaryExprOrTypeTraitExpr
4987  const_child_range CCR =
4988  const_cast<const UnaryExprOrTypeTraitExpr *>(this)->children();
4989  return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end()));
4990 }
4991 
4993  // If this is of a type and the type is a VLA type (and not a typedef), the
4994  // size expression of the VLA needs to be treated as an executable expression.
4995  // Why isn't this weirdness documented better in StmtIterator?
4996  if (isArgumentType()) {
4997  if (const VariableArrayType *T =
4998  dyn_cast<VariableArrayType>(getArgumentType().getTypePtr()))
5001  }
5002  return const_child_range(&Argument.Ex, &Argument.Ex + 1);
5003 }
5004 
5006  AtomicOp op, SourceLocation RP)
5007  : Expr(AtomicExprClass, t, VK_PRValue, OK_Ordinary),
5008  NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) {
5009  assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions");
5010  for (unsigned i = 0; i != args.size(); i++)
5011  SubExprs[i] = args[i];
5013 }
5014 
5016  switch (Op) {
5017  case AO__c11_atomic_init:
5018  case AO__opencl_atomic_init:
5019  case AO__c11_atomic_load:
5020  case AO__atomic_load_n:
5021  return 2;
5022 
5023  case AO__scoped_atomic_load_n:
5024  case AO__opencl_atomic_load:
5025  case AO__hip_atomic_load:
5026  case AO__c11_atomic_store:
5027  case AO__c11_atomic_exchange:
5028  case AO__atomic_load:
5029  case AO__atomic_store:
5030  case AO__atomic_store_n:
5031  case AO__atomic_exchange_n:
5032  case AO__c11_atomic_fetch_add:
5033  case AO__c11_atomic_fetch_sub:
5034  case AO__c11_atomic_fetch_and:
5035  case AO__c11_atomic_fetch_or:
5036  case AO__c11_atomic_fetch_xor:
5037  case AO__c11_atomic_fetch_nand:
5038  case AO__c11_atomic_fetch_max:
5039  case AO__c11_atomic_fetch_min:
5040  case AO__atomic_fetch_add:
5041  case AO__atomic_fetch_sub:
5042  case AO__atomic_fetch_and:
5043  case AO__atomic_fetch_or:
5044  case AO__atomic_fetch_xor:
5045  case AO__atomic_fetch_nand:
5046  case AO__atomic_add_fetch:
5047  case AO__atomic_sub_fetch:
5048  case AO__atomic_and_fetch:
5049  case AO__atomic_or_fetch:
5050  case AO__atomic_xor_fetch:
5051  case AO__atomic_nand_fetch:
5052  case AO__atomic_min_fetch:
5053  case AO__atomic_max_fetch:
5054  case AO__atomic_fetch_min:
5055  case AO__atomic_fetch_max:
5056  return 3;
5057 
5058  case AO__scoped_atomic_load:
5059  case AO__scoped_atomic_store:
5060  case AO__scoped_atomic_store_n:
5061  case AO__scoped_atomic_fetch_add:
5062  case AO__scoped_atomic_fetch_sub:
5063  case AO__scoped_atomic_fetch_and:
5064  case AO__scoped_atomic_fetch_or:
5065  case AO__scoped_atomic_fetch_xor:
5066  case AO__scoped_atomic_fetch_nand:
5067  case AO__scoped_atomic_add_fetch:
5068  case AO__scoped_atomic_sub_fetch:
5069  case AO__scoped_atomic_and_fetch:
5070  case AO__scoped_atomic_or_fetch:
5071  case AO__scoped_atomic_xor_fetch:
5072  case AO__scoped_atomic_nand_fetch:
5073  case AO__scoped_atomic_min_fetch:
5074  case AO__scoped_atomic_max_fetch:
5075  case AO__scoped_atomic_fetch_min:
5076  case AO__scoped_atomic_fetch_max:
5077  case AO__scoped_atomic_exchange_n:
5078  case AO__hip_atomic_exchange:
5079  case AO__hip_atomic_fetch_add:
5080  case AO__hip_atomic_fetch_sub:
5081  case AO__hip_atomic_fetch_and:
5082  case AO__hip_atomic_fetch_or:
5083  case AO__hip_atomic_fetch_xor:
5084  case AO__hip_atomic_fetch_min:
5085  case AO__hip_atomic_fetch_max:
5086  case AO__opencl_atomic_store:
5087  case AO__hip_atomic_store:
5088  case AO__opencl_atomic_exchange:
5089  case AO__opencl_atomic_fetch_add:
5090  case AO__opencl_atomic_fetch_sub:
5091  case AO__opencl_atomic_fetch_and:
5092  case AO__opencl_atomic_fetch_or:
5093  case AO__opencl_atomic_fetch_xor:
5094  case AO__opencl_atomic_fetch_min:
5095  case AO__opencl_atomic_fetch_max:
5096  case AO__atomic_exchange:
5097  return 4;
5098 
5099  case AO__scoped_atomic_exchange:
5100  case AO__c11_atomic_compare_exchange_strong:
5101  case AO__c11_atomic_compare_exchange_weak:
5102  return 5;
5103  case AO__hip_atomic_compare_exchange_strong:
5104  case AO__opencl_atomic_compare_exchange_strong:
5105  case AO__opencl_atomic_compare_exchange_weak:
5106  case AO__hip_atomic_compare_exchange_weak:
5107  case AO__atomic_compare_exchange:
5108  case AO__atomic_compare_exchange_n:
5109  return 6;
5110 
5111  case AO__scoped_atomic_compare_exchange:
5112  case AO__scoped_atomic_compare_exchange_n:
5113  return 7;
5114  }
5115  llvm_unreachable("unknown atomic op");
5116 }
5117 
5119  auto T = getPtr()->getType()->castAs<PointerType>()->getPointeeType();
5120  if (auto AT = T->getAs<AtomicType>())
5121  return AT->getValueType();
5122  return T;
5123 }
5124 
5126  unsigned ArraySectionCount = 0;
5127  while (auto *OASE = dyn_cast<ArraySectionExpr>(Base->IgnoreParens())) {
5128  Base = OASE->getBase();
5129  ++ArraySectionCount;
5130  }
5131  while (auto *ASE =
5132  dyn_cast<ArraySubscriptExpr>(Base->IgnoreParenImpCasts())) {
5133  Base = ASE->getBase();
5134  ++ArraySectionCount;
5135  }
5136  Base = Base->IgnoreParenImpCasts();
5137  auto OriginalTy = Base->getType();
5138  if (auto *DRE = dyn_cast<DeclRefExpr>(Base))
5139  if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
5140  OriginalTy = PVD->getOriginalType().getNonReferenceType();
5141 
5142  for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
5143  if (OriginalTy->isAnyPointerType())
5144  OriginalTy = OriginalTy->getPointeeType();
5145  else if (OriginalTy->isArrayType())
5146  OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
5147  else
5148  return {};
5149  }
5150  return OriginalTy;
5151 }
5152 
5153 RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, SourceLocation BeginLoc,
5154  SourceLocation EndLoc, ArrayRef<Expr *> SubExprs)
5155  : Expr(RecoveryExprClass, T.getNonReferenceType(),
5156  T->isDependentType() ? VK_LValue : getValueKindForType(T),
5157  OK_Ordinary),
5158  BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
5159  assert(!T.isNull());
5160  assert(!llvm::is_contained(SubExprs, nullptr));
5161 
5162  llvm::copy(SubExprs, getTrailingObjects<Expr *>());
5164 }
5165 
5167  SourceLocation BeginLoc,
5168  SourceLocation EndLoc,
5169  ArrayRef<Expr *> SubExprs) {
5170  void *Mem = Ctx.Allocate(totalSizeToAlloc<Expr *>(SubExprs.size()),
5171  alignof(RecoveryExpr));
5172  return new (Mem) RecoveryExpr(Ctx, T, BeginLoc, EndLoc, SubExprs);
5173 }
5174 
5175 RecoveryExpr *RecoveryExpr::CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs) {
5176  void *Mem = Ctx.Allocate(totalSizeToAlloc<Expr *>(NumSubExprs),
5177  alignof(RecoveryExpr));
5178  return new (Mem) RecoveryExpr(EmptyShell(), NumSubExprs);
5179 }
5180 
5181 void OMPArrayShapingExpr::setDimensions(ArrayRef<Expr *> Dims) {
5182  assert(
5183  NumDims == Dims.size() &&
5184  "Preallocated number of dimensions is different from the provided one.");
5185  llvm::copy(Dims, getTrailingObjects<Expr *>());
5186 }
5187 
5188 void OMPArrayShapingExpr::setBracketsRanges(ArrayRef<SourceRange> BR) {
5189  assert(
5190  NumDims == BR.size() &&
5191  "Preallocated number of dimensions is different from the provided one.");
5192  llvm::copy(BR, getTrailingObjects<SourceRange>());
5193 }
5194 
5195 OMPArrayShapingExpr::OMPArrayShapingExpr(QualType ExprTy, Expr *Op,
5197  ArrayRef<Expr *> Dims)
5198  : Expr(OMPArrayShapingExprClass, ExprTy, VK_LValue, OK_Ordinary), LPLoc(L),
5199  RPLoc(R), NumDims(Dims.size()) {
5200  setBase(Op);
5201  setDimensions(Dims);
5203 }
5204 
5208  ArrayRef<Expr *> Dims,
5209  ArrayRef<SourceRange> BracketRanges) {
5210  assert(Dims.size() == BracketRanges.size() &&
5211  "Different number of dimensions and brackets ranges.");
5212  void *Mem = Context.Allocate(
5213  totalSizeToAlloc<Expr *, SourceRange>(Dims.size() + 1, Dims.size()),
5214  alignof(OMPArrayShapingExpr));
5215  auto *E = new (Mem) OMPArrayShapingExpr(T, Op, L, R, Dims);
5216  E->setBracketsRanges(BracketRanges);
5217  return E;
5218 }
5219 
5221  unsigned NumDims) {
5222  void *Mem = Context.Allocate(
5223  totalSizeToAlloc<Expr *, SourceRange>(NumDims + 1, NumDims),
5224  alignof(OMPArrayShapingExpr));
5225  return new (Mem) OMPArrayShapingExpr(EmptyShell(), NumDims);
5226 }
5227 
5228 void OMPIteratorExpr::setIteratorDeclaration(unsigned I, Decl *D) {
5229  assert(I < NumIterators &&
5230  "Idx is greater or equal the number of iterators definitions.");
5231  getTrailingObjects<Decl *>()[I] = D;
5232 }
5233 
5234 void OMPIteratorExpr::setAssignmentLoc(unsigned I, SourceLocation Loc) {
5235  assert(I < NumIterators &&
5236  "Idx is greater or equal the number of iterators definitions.");
5237  getTrailingObjects<
5238  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5239  static_cast<int>(RangeLocOffset::AssignLoc)] = Loc;
5240 }
5241 
5242 void OMPIteratorExpr::setIteratorRange(unsigned I, Expr *Begin,
5243  SourceLocation ColonLoc, Expr *End,
5244  SourceLocation SecondColonLoc,
5245  Expr *Step) {
5246  assert(I < NumIterators &&
5247  "Idx is greater or equal the number of iterators definitions.");
5248  getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5249  static_cast<int>(RangeExprOffset::Begin)] =
5250  Begin;
5251  getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5252  static_cast<int>(RangeExprOffset::End)] = End;
5253  getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5254  static_cast<int>(RangeExprOffset::Step)] = Step;
5255  getTrailingObjects<
5256  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5257  static_cast<int>(RangeLocOffset::FirstColonLoc)] =
5258  ColonLoc;
5259  getTrailingObjects<
5260  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5261  static_cast<int>(RangeLocOffset::SecondColonLoc)] =
5262  SecondColonLoc;
5263 }
5264 
5266  return getTrailingObjects<Decl *>()[I];
5267 }
5268 
5270  IteratorRange Res;
5271  Res.Begin =
5272  getTrailingObjects<Expr *>()[I * static_cast<int>(
5273  RangeExprOffset::Total) +
5274  static_cast<int>(RangeExprOffset::Begin)];
5275  Res.End =
5276  getTrailingObjects<Expr *>()[I * static_cast<int>(
5277  RangeExprOffset::Total) +
5278  static_cast<int>(RangeExprOffset::End)];
5279  Res.Step =
5280  getTrailingObjects<Expr *>()[I * static_cast<int>(
5281  RangeExprOffset::Total) +
5282  static_cast<int>(RangeExprOffset::Step)];
5283  return Res;
5284 }
5285 
5287  return getTrailingObjects<
5288  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5289  static_cast<int>(RangeLocOffset::AssignLoc)];
5290 }
5291 
5293  return getTrailingObjects<
5294  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5295  static_cast<int>(RangeLocOffset::FirstColonLoc)];
5296 }
5297 
5299  return getTrailingObjects<
5300  SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5301  static_cast<int>(RangeLocOffset::SecondColonLoc)];
5302 }
5303 
5304 void OMPIteratorExpr::setHelper(unsigned I, const OMPIteratorHelperData &D) {
5305  getTrailingObjects<OMPIteratorHelperData>()[I] = D;
5306 }
5307 
5309  return getTrailingObjects<OMPIteratorHelperData>()[I];
5310 }
5311 
5313  return getTrailingObjects<OMPIteratorHelperData>()[I];
5314 }
5315 
5316 OMPIteratorExpr::OMPIteratorExpr(
5317  QualType ExprTy, SourceLocation IteratorKwLoc, SourceLocation L,
5320  : Expr(OMPIteratorExprClass, ExprTy, VK_LValue, OK_Ordinary),
5321  IteratorKwLoc(IteratorKwLoc), LPLoc(L), RPLoc(R),
5322  NumIterators(Data.size()) {
5323  for (unsigned I = 0, E = Data.size(); I < E; ++I) {
5324  const IteratorDefinition &D = Data[I];
5325  setIteratorDeclaration(I, D.IteratorDecl);
5326  setAssignmentLoc(I, D.AssignmentLoc);
5327  setIteratorRange(I, D.Range.Begin, D.ColonLoc, D.Range.End,
5328  D.SecondColonLoc, D.Range.Step);
5329  setHelper(I, Helpers[I]);
5330  }
5332 }
5333 
5336  SourceLocation IteratorKwLoc, SourceLocation L,
5337  SourceLocation R,
5340  assert(Data.size() == Helpers.size() &&
5341  "Data and helpers must have the same size.");
5342  void *Mem = Context.Allocate(
5343  totalSizeToAlloc<Decl *, Expr *, SourceLocation, OMPIteratorHelperData>(
5344  Data.size(), Data.size() * static_cast<int>(RangeExprOffset::Total),
5345  Data.size() * static_cast<int>(RangeLocOffset::Total),
5346  Helpers.size()),
5347  alignof(OMPIteratorExpr));
5348  return new (Mem) OMPIteratorExpr(T, IteratorKwLoc, L, R, Data, Helpers);
5349 }
5350 
5352  unsigned NumIterators) {
5353  void *Mem = Context.Allocate(
5354  totalSizeToAlloc<Decl *, Expr *, SourceLocation, OMPIteratorHelperData>(
5355  NumIterators, NumIterators * static_cast<int>(RangeExprOffset::Total),
5356  NumIterators * static_cast<int>(RangeLocOffset::Total), NumIterators),
5357  alignof(OMPIteratorExpr));
5358  return new (Mem) OMPIteratorExpr(EmptyShell(), NumIterators);
5359 }
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3299
static char ID
Definition: Arena.cpp:183
#define SM(sm)
Definition: Cuda.cpp:83
static bool isBooleanType(QualType Ty)
static Expr * IgnoreImplicitConstructorSingleStep(Expr *E)
Definition: BuildTree.cpp:53
Defines enum values for all the target-independent builtin functions.
llvm::APSInt APSInt
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
static void AssertResultStorageKind(ConstantResultStorageKind Kind)
Definition: Expr.cpp:294
static std::optional< unsigned > UniqueStableNameDiscriminator(ASTContext &, const NamedDecl *ND)
Definition: Expr.cpp:598
static const Expr * skipTemporaryBindingsNoOpCastsAndParens(const Expr *E)
Skip over any no-op casts and any temporary-binding expressions.
Definition: Expr.cpp:3219
unsigned Offset
Definition: Format.cpp:2978
llvm::MachO::Target Target
Definition: MachO.h:50
Defines the clang::Preprocessor interface.
static QualType getUnderlyingType(const SubRegion *R)
static bool isRecordType(QualType T)
SourceLocation Loc
Definition: SemaObjC.cpp:755
Defines the SourceManager interface.
const char * Data
static const TypeInfo & getInfo(unsigned id)
Definition: Types.cpp:47
SourceLocation End
SourceLocation Begin
std::string Label
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__SIZE_TYPE__ size_t
do v
Definition: arm_acle.h:83
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
uint64_t * pVal
Used to store the >64 bits integer value.
uint64_t VAL
Used to store the <= 64 bits integer value.
void setIntValue(const ASTContext &C, const llvm::APInt &Val)
Definition: Expr.cpp:1004
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:208
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
static APValue IndeterminateValue()
Definition: APValue.h:366
APSInt & getInt()
Definition: APValue.h:423
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
SourceManager & getSourceManager()
Definition: ASTContext.h:708
MangleContext * createMangleContext(const TargetInfo *T=nullptr)
If T is null pointer, assume the target in ASTContext.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2589
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:721
CanQualType DependentTy
Definition: ASTContext.h:1122
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:1605
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:649
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Definition: ASTContext.h:2782
Qualifiers::GC getObjCGCAttrKind(QualType Ty) const
Return one of the GCNone, Weak or Strong Objective-C garbage collection attributes.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:778
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
CanQualType CharTy
Definition: ASTContext.h:1096
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
Definition: ASTContext.h:1430
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2632
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2355
CanQualType VoidTy
Definition: ASTContext.h:1094
CanQualType UnsignedIntTy
Definition: ASTContext.h:1104
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:760
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
Definition: ASTContext.h:3040
StringLiteral * getPredefinedStringLiteralFromCache(StringRef Key) const
Return a string representing the human readable name for the specified function declaration or file n...
DiagnosticsEngine & getDiagnostics() const
UnnamedGlobalConstantDecl * getUnnamedGlobalConstantDecl(QualType Ty, const APValue &Value) const
Return a declaration for a uniquified anonymous global constant corresponding to a given APValue.
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3126
size_type size() const
Definition: ASTVector.h:109
void resize(const ASTContext &C, unsigned N, const T &NV)
Definition: ASTVector.h:341
iterator begin()
Definition: ASTVector.h:97
iterator insert(const ASTContext &C, iterator I, const T &Elt)
Definition: ASTVector.h:219
void reserve(const ASTContext &C, unsigned N)
Definition: ASTVector.h:173
iterator end()
Definition: ASTVector.h:99
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
Definition: Expr.cpp:5125
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2716
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3530
QualType getElementType() const
Definition: Type.h:3542
QualType getValueType() const
Definition: Expr.cpp:5118
Expr * getPtr() const
Definition: Expr.h:6510
AtomicExpr(SourceLocation BLoc, ArrayRef< Expr * > args, QualType t, AtomicOp op, SourceLocation RP)
Definition: Expr.cpp:5005
unsigned getNumSubExprs() const
Definition: Expr.h:6553
Attr - This represents one attribute.
Definition: Attr.h:46
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3892
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2236
StringRef getOpcodeStr() const
Definition: Expr.h:3957
SourceLocation getOperatorLoc() const
Definition: Expr.h:3933
bool hasStoredFPFeatures() const
Definition: Expr.h:4076
bool isCompoundAssignmentOp() const
Definition: Expr.h:4035
static unsigned sizeOfTrailingObjects(bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:4129
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4843
static BinaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4835
static bool isAssignmentOp(Opcode Opc)
Definition: Expr.h:4027
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, const Expr *LHS, const Expr *RHS)
Return true if a binary operator using the specified opcode and operands would match the 'p = (i8*)nu...
Definition: Expr.cpp:2261
Opcode getOpcode() const
Definition: Expr.h:3936
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used only by Serialization.
Definition: Expr.h:4084
Expr * getRHS() const
Definition: Expr.h:3943
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2198
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Build a binary operator, assuming that appropriate storage has been allocated for the trailing object...
Definition: Expr.cpp:4801
Expr * getLHS() const
Definition: Expr.h:3941
A binding in a decomposition declaration.
Definition: DeclCXX.h:4107
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: Decl.h:4576
SourceLocation getCaretLocation() const
Definition: Decl.h:4570
SourceLocation getCaretLocation() const
Definition: Expr.cpp:2560
BlockDecl * TheBlock
Definition: Expr.h:6216
const Stmt * getBody() const
Definition: Expr.cpp:2563
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Definition: Expr.cpp:2554
Pointer to a block type.
Definition: Type.h:3361
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
Definition: Builtins.h:143
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition: Expr.h:3823
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition: Expr.cpp:2178
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:2160
SourceLocation getLParenLoc() const
Definition: Expr.h:3855
Represents a call to a CUDA kernel function.
Definition: ExprCXX.h:231
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1487
CXXTemporary * getTemporary()
Definition: ExprCXX.h:1505
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1542
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1685
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1682
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition: ExprCXX.h:1605
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1264
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1371
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition: ExprCXX.h:478
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition: ExprCXX.h:1813
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2186
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
Definition: ExprCXX.h:149
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
Definition: ExprCXX.h:111
SourceRange getSourceRange() const
Definition: ExprCXX.h:161
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
Definition: DeclCXX.h:1367
A C++ static_cast expression (C++ [expr.static.cast]).
Definition: ExprCXX.h:433
const CXXDestructorDecl * getDestructor() const
Definition: ExprCXX.h:1464
Represents the this expression in C++.
Definition: ExprCXX.h:1148
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2872
bool hasStoredFPFeatures() const
Definition: Expr.h:3034
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
Definition: Expr.h:2946
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
Definition: Expr.h:3076
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1549
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1693
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
Definition: Expr.cpp:1634
static CallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Create an empty call expression, for deserialization.
Definition: Expr.cpp:1573
bool isCallToStdMove() const
Definition: Expr.cpp:3562
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1702
void setPreArg(unsigned I, Stmt *PreArg)
Definition: Expr.h:2960
void computeDependence()
Compute and set dependence bits.
Definition: Expr.h:3082
void setStoredFPFeatures(FPOptionsOverride F)
Set FPOptionsOverride in trailing storage. Used only by Serialization.
Definition: Expr.h:3141
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition: Expr.h:3050
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition: Expr.h:3063
CallExpr(StmtClass SC, Expr *Fn, ArrayRef< Expr * > PreArgs, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs, ADLCallKind UsesADL)
Build a call expression, assuming that appropriate storage has been allocated for the trailing object...
Definition: Expr.cpp:1504
SourceLocation getRParenLoc() const
Definition: Expr.h:3182
Expr * getCallee()
Definition: Expr.h:3022
static constexpr ADLCallKind UsesADL
Definition: Expr.h:2930
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:1563
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:3550
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition: Expr.h:3042
Decl * getCalleeDecl()
Definition: Expr.h:3036
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1645
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:1675
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:1639
void setCallee(Expr *F)
Definition: Expr.h:3024
unsigned getNumPreArgs() const
Definition: Expr.h:2965
bool hasUnusedResultAttr(const ASTContext &Ctx) const
Returns true if this call expression should warn on unused results.
Definition: Expr.h:3178
QualType withConst() const
Retrieves a version of this type with const applied.
bool isVolatileQualified() const
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4689
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3535
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
Definition: Expr.cpp:2109
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes.
Definition: Expr.cpp:2058
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:2036
CastKind getCastKind() const
Definition: Expr.h:3579
Expr * getSubExpr()
Definition: Expr.h:3585
bool hasStoredFPFeatures() const
Definition: Expr.h:3634
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
Definition: Expr.cpp:2089
const char * getCastKindName() const
Definition: Expr.h:3583
bool path_empty() const
Definition: Expr.h:3603
SourceLocation getEnd() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Definition: CharUnits.h:53
void setValue(unsigned Val)
Definition: Expr.h:1616
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
Definition: Expr.cpp:1077
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4610
Represents a class template specialization, which refers to a class template with a given set of temp...
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4140
static CompoundAssignOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4857
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4865
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3465
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
bool body_empty() const
Definition: Stmt.h:1650
Stmt * body_back()
Definition: Stmt.h:1669
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4231
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1072
APValue getAPValueResult() const
Definition: Expr.cpp:413
static ConstantResultStorageKind getStorageKind(const APValue &Value)
Definition: Expr.cpp:302
void MoveIntoResult(APValue &Value, const ASTContext &Context)
Definition: Expr.cpp:378
llvm::APSInt getResultAsAPSInt() const
Definition: Expr.cpp:401
ConstantResultStorageKind getResultStorageKind() const
Definition: Expr.h:1141
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:350
static ConstantExpr * CreateEmpty(const ASTContext &Context, ConstantResultStorageKind StorageKind)
Definition: Expr.cpp:367
A POD class for pairing a NamedDecl* with an access specifier.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2342
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
Definition: Expr.h:1409
ValueDecl * getDecl()
Definition: Expr.h:1328
void setDecl(ValueDecl *NewD)
Definition: Expr.cpp:544
static DeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Construct an empty declaration reference expression.
Definition: Expr.cpp:529
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:551
DeclarationNameInfo getNameInfo() const
Definition: Expr.h:1332
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, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:488
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
Definition: Expr.h:1343
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
Definition: Expr.h:1347
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:556
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:1397
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1497
decl_range decls()
Definition: Stmt.h:1545
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:501
static Decl * castFromDeclContext(const DeclContext *)
Definition: DeclBase.cpp:1019
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
static bool isFlexibleArrayMemberLike(ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
Definition: DeclBase.cpp:413
bool hasAttr() const
Definition: DeclBase.h:583
T * getAttr() const
Definition: DeclBase.h:579
DeclContext * getDeclContext()
Definition: DeclBase.h:454
DeclarationNameLoc - Additional source/type location info for a declaration name.
Represents the type decltype(expr) (C++11).
Definition: Type.h:5370
Represents a single C99 designator.
Definition: Expr.h:5176
FieldDecl * getFieldDecl() const
Definition: Expr.h:5267
unsigned getArrayIndex() const
Definition: Expr.h:5314
SourceRange getSourceRange() const LLVM_READONLY
Definition: Expr.h:5348
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:5338
struct FieldDesignatorInfo FieldInfo
A field designator, e.g., ".x".
Definition: Expr.h:5238
SourceLocation getFieldLoc() const
Definition: Expr.h:5284
const IdentifierInfo * getFieldName() const
Definition: Expr.cpp:4602
SourceLocation getDotLoc() const
Definition: Expr.h:5279
Represents a C99 designated initializer expression.
Definition: Expr.h:5133
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Definition: Expr.cpp:4656
Expr * getArrayRangeEnd(const Designator &D) const
Definition: Expr.cpp:4711
Expr * getInit() const
Retrieve the initializer value.
Definition: Expr.h:5401
SourceRange getDesignatorsSourceRange() const
Definition: Expr.cpp:4672
Expr * getArrayRangeStart(const Designator &D) const
Definition: Expr.cpp:4706
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:4718
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4644
Expr * getSubExpr(unsigned Idx) const
Definition: Expr.h:5415
Expr * getArrayIndex(const Designator &D) const
Definition: Expr.cpp:4701
unsigned size() const
Returns the number of designators in this initializer.
Definition: Expr.h:5363
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:4680
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
Definition: Expr.cpp:4663
Designator * getDesignator(unsigned Idx)
Definition: Expr.h:5374
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:4697
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:4761
DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc, Expr *baseExprs, SourceLocation rBraceLoc)
Definition: Expr.cpp:4744
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:4765
Expr * getBase() const
Definition: Expr.h:5517
InitListExpr * getUpdater() const
Definition: Expr.h:5520
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3300
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3782
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Definition: Expr.h:3809
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3467
bool isPRValue() const
Definition: Expr.h:383
This represents one expression.
Definition: Expr.h:110
@ LV_MemberFunction
Definition: Expr.h:289
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
EnumConstantDecl * getEnumConstantDecl()
If this expression refers to an enum constant, retrieve its declaration.
Definition: Expr.cpp:4188
bool isReadIfDiscardedInCPlusPlus11() const
Determine whether an lvalue-to-rvalue conversion should implicitly be applied to this expression if i...
Definition: Expr.cpp:2575
bool isGLValue() const
Definition: Expr.h:280
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
Definition: Expr.cpp:3138
@ SE_AllowUndefinedBehavior
Allow UB that we can give a value, but not arbitrary unmodeled side effects.
Definition: Expr.h:669
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
Definition: Expr.cpp:3067
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
Definition: Expr.cpp:3287
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition: Expr.cpp:3116
void setType(QualType t)
Definition: Expr.h:143
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:2641
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
Definition: Expr.cpp:4195
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Skip past any parentheses and lvalue casts which might surround this expression until reaching a fixe...
Definition: Expr.cpp:3128
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
Definition: Expr.cpp:3903
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:68
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Definition: Expr.cpp:3111
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3099
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
Definition: Expr.cpp:3120
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
Definition: Expr.h:245
bool isObjCSelfExpr() const
Check if this expression is the ObjC 'self' implicit parameter.
Definition: Expr.cpp:4123
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3107
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
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...
Expr * IgnoreParenBaseCasts() LLVM_READONLY
Skip past any parentheses and derived-to-base casts until reaching a fixed point.
Definition: Expr.cpp:3133
bool isPRValue() const
Definition: Expr.h:278
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition: Expr.h:277
const Expr * skipRValueSubobjectAdjustments() const
Definition: Expr.h:1010
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
Definition: Expr.cpp:3331
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
Definition: Expr.cpp:4141
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
Definition: Expr.h:815
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
Definition: Expr.h:821
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
Definition: Expr.h:817
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
Definition: Expr.h:825
Expr * IgnoreUnlessSpelledInSource()
Skip past any invisible AST nodes which might surround this statement, such as ExprWithCleanups or Im...
Definition: Expr.cpp:3164
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
Expr * IgnoreCasts() LLVM_READONLY
Skip past any casts which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3095
Decl * getReferencedDeclOfCallee()
Definition: Expr.cpp:1600
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3103
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:3608
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
const Expr * getBestDynamicClassTypeExpr() const
Get the inner expression that determines the best dynamic class.
Definition: Expr.cpp:43
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3091
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
Definition: Expr.h:792
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
Definition: Expr.h:801
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
Definition: Expr.h:804
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
Definition: Expr.h:807
@ NPCK_GNUNull
Expression is a GNU-style __null constant.
Definition: Expr.h:810
@ NPCK_NotNull
Expression is not a Null pointer constant.
Definition: Expr.h:794
bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsBooleanCondition - Return true if this is a constant which we can fold and convert to a boo...
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:3245
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:3980
QualType getEnumCoercedType(const ASTContext &Ctx) const
If this expression is an enumeration constant, return the enumeration type under which said constant ...
Definition: Expr.cpp:266
bool isBoundMemberFunction(ASTContext &Ctx) const
Returns true if this expression is a bound member function.
Definition: Expr.cpp:3061
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:3339
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
static bool isSameComparisonOperand(const Expr *E1, const Expr *E2)
Checks that the two Expr's will refer to the same value as a comparison operand.
Definition: Expr.cpp:4232
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:3206
bool isFlexibleArrayMemberLike(ASTContext &Context, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution=false) const
Check whether this array fits the idiom of a flexible array member, depending on the value of -fstric...
Definition: Expr.cpp:206
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
Definition: Expr.h:405
QualType getType() const
Definition: Expr.h:142
bool hasNonTrivialCall(const ASTContext &Ctx) const
Determine whether this expression involves a call to any function that is not trivial.
Definition: Expr.cpp:3968
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
Definition: Expr.cpp:4220
bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const
isCXX98IntegralConstantExpr - Return true if this expression is an integral constant expression in C+...
const ValueDecl * getAsBuiltinConstantDeclRef(const ASTContext &Context) const
If this expression is an unambiguous reference to a single declaration, in the style of __builtin_fun...
Definition: Expr.cpp:226
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
Definition: Expr.cpp:3022
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:427
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
Definition: Expr.cpp:136
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
Definition: Expr.h:135
const ObjCPropertyRefExpr * getObjCProperty() const
If this expression is an l-value for an Objective C property, find the underlying property reference ...
Definition: Expr.cpp:4104
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
Definition: Expr.cpp:4351
const Expr * getBase() const
Definition: Expr.h:6171
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
Definition: Expr.cpp:4340
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Definition: Expr.cpp:4372
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
Definition: Expr.cpp:4344
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:4119
Represents difference between two FPOptions values.
Definition: LangOptions.h:956
bool requiresTrailingStorage() const
Definition: LangOptions.h:982
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
Represents a member of a struct/union/class.
Definition: Decl.h:3060
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4574
bool isBitField() const
Determines whether this field is a bitfield.
Definition: Decl.h:3151
static FixedPointLiteral * Create(const ASTContext &C, EmptyShell Empty)
Returns an empty fixed-point literal.
Definition: Expr.cpp:1062
std::string getValueAsString(unsigned Radix) const
Definition: Expr.cpp:1067
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
Definition: Expr.cpp:1054
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1133
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
Definition: Expr.cpp:1146
llvm::APFloat getValue() const
Definition: Expr.h:1647
FullExpr - Represents a "full-expression" node.
Definition: Expr.h:1039
Represents a function declaration or definition.
Definition: Decl.h:1972
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
Definition: Decl.cpp:4117
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition: Decl.h:2342
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4668
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:467
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:522
TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:481
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4268
CallingConv getCallConv() const
Definition: Type.h:4596
QualType getReturnType() const
Definition: Type.h:4585
Represents a C11 generic selection.
Definition: Expr.h:5766
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition: Expr.cpp:4532
static GenericSelectionExpr * CreateEmpty(const ASTContext &Context, unsigned NumAssocs)
Create an empty generic selection expression for deserialization.
Definition: Expr.cpp:4590
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:56
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3707
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2129
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Definition: Expr.cpp:2151
Describes an C or C++ initializer list.
Definition: Expr.h:4888
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
Definition: Expr.h:5007
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
Definition: Expr.h:4992
InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef< Expr * > initExprs, SourceLocation rbraceloc)
Definition: Expr.cpp:2428
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
Definition: Expr.cpp:2484
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
Definition: Expr.cpp:2444
bool isStringLiteralInit() const
Is this an initializer for an array of characters, initialized by a string literal or an @encode?
Definition: Expr.cpp:2470
unsigned getNumInits() const
Definition: Expr.h:4918
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:2518
bool isSemanticForm() const
Definition: Expr.h:5047
void setInit(unsigned Init, Expr *expr)
Definition: Expr.h:4944
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4934
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:2448
ArrayRef< Expr * > inits()
Definition: Expr.h:4928
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2460
Expr ** getInits()
Retrieve the set of initializers.
Definition: Expr.h:4921
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
Definition: Expr.cpp:2507
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:2536
bool isSyntacticForm() const
Definition: Expr.h:5051
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5068
InitListExpr * getSyntacticForm() const
Definition: Expr.h:5054
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
Definition: Expr.cpp:2439
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:1032
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2031
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1950
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:482
std::string SYCLUniquePrefix
A driver-provided unique string for this translation unit that is used to generate unique names for S...
Definition: LangOptions.h:586
void remapPathPrefix(SmallVectorImpl< char > &Path) const
Remap path prefix according to -fmacro-prefix-path option.
Definition: LangOptions.cpp:73
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:78
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Definition: Lexer.h:236
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:399
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4721
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3224
static MemberExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Definition: Expr.cpp:1831
void setMemberDecl(ValueDecl *D)
Definition: Expr.cpp:1846
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
Definition: Expr.h:3326
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
Definition: Expr.h:3368
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
Definition: Expr.h:3321
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1809
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
Definition: Expr.h:3422
Expr * getBase() const
Definition: Expr.h:3301
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: Expr.h:3357
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.cpp:1867
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.cpp:1853
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
Definition: Expr.h:3401
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3472
This represents a decl that may have a name.
Definition: Decl.h:249
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
bool isExternallyVisible() const
Definition: Decl.h:409
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
bool hasQualifier() const
Evaluates true when this nested-name-specifier location is non-empty.
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition: ExprOpenMP.h:24
static OMPArrayShapingExpr * CreateEmpty(const ASTContext &Context, unsigned NumDims)
Definition: Expr.cpp:5220
static OMPArrayShapingExpr * Create(const ASTContext &Context, QualType T, Expr *Op, SourceLocation L, SourceLocation R, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketRanges)
Definition: Expr.cpp:5206
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition: ExprOpenMP.h:151
static OMPIteratorExpr * Create(const ASTContext &Context, QualType T, SourceLocation IteratorKwLoc, SourceLocation L, SourceLocation R, ArrayRef< IteratorDefinition > Data, ArrayRef< OMPIteratorHelperData > Helpers)
Definition: Expr.cpp:5335
static OMPIteratorExpr * CreateEmpty(const ASTContext &Context, unsigned NumIterators)
Definition: Expr.cpp:5351
SourceLocation getSecondColonLoc(unsigned I) const
Gets the location of the second ':' (if any) in the range for the given iteratori definition.
Definition: Expr.cpp:5298
SourceLocation getColonLoc(unsigned I) const
Gets the location of the first ':' in the range for the given iterator definition.
Definition: Expr.cpp:5292
IteratorRange getIteratorRange(unsigned I)
Gets the iterator range for the given iterator.
Definition: Expr.cpp:5269
OMPIteratorHelperData & getHelper(unsigned I)
Fetches helper data for the specified iteration space.
Definition: Expr.cpp:5308
SourceLocation getAssignLoc(unsigned I) const
Gets the location of '=' for the given iterator definition.
Definition: Expr.cpp:5286
Decl * getIteratorDecl(unsigned I)
Gets the iterator declaration for the given iterator.
Definition: Expr.cpp:5265
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2542
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:549
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:945
ObjCMethodFamily getMethodFamily() const
Definition: ExprObjC.h:1375
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition: ExprObjC.h:1248
const ObjCMethodDecl * getMethodDecl() const
Definition: ExprObjC.h:1356
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:418
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2517
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
Definition: Expr.cpp:1725
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1712
void setIndexExpr(unsigned Idx, Expr *E)
Definition: Expr.h:2588
void setComponent(unsigned Idx, OffsetOfNode ON)
Definition: Expr.h:2569
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1747
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2475
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2420
@ Field
A field.
Definition: Expr.h:2418
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2465
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1168
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
Definition: Expr.cpp:4912
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2182
static ParenListExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumExprs)
Create an empty paren list.
Definition: Expr.cpp:4794
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4785
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3151
QualType getPointeeType() const
Definition: Type.h:3161
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1986
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:693
StringRef getIdentKindName() const
Definition: Expr.h:2043
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
Definition: Expr.cpp:702
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
Definition: Expr.cpp:733
static void processPathToFileName(SmallVectorImpl< char > &FileName, const PresumedLoc &PLoc, const LangOptions &LangOpts, const TargetInfo &TI)
static void processPathForFileMacro(SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI)
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
Callbacks to use to customize the behavior of the pretty-printer.
Definition: PrettyPrinter.h:32
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6346
semantics_iterator semantics_end()
Definition: Expr.h:6418
semantics_iterator semantics_begin()
Definition: Expr.h:6412
const Expr *const * const_semantics_iterator
Definition: Expr.h:6411
ArrayRef< Expr * > semantics()
Definition: Expr.h:6425
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
Definition: Expr.cpp:4937
A (possibly-)qualified type.
Definition: Type.h:940
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:7455
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7497
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7411
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
QualType getCanonicalType() const
Definition: Type.h:7423
The collection of all-type qualifiers we support.
Definition: Type.h:318
void removeAddressSpace()
Definition: Type.h:582
bool empty() const
Definition: Type.h:633
Represents a struct/union/class.
Definition: Decl.h:4171
field_iterator field_end() const
Definition: Decl.h:4380
field_range fields() const
Definition: Decl.h:4377
field_iterator field_begin() const
Definition: Decl.cpp:5073
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5561
RecordDecl * getDecl() const
Definition: Type.h:5571
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition: Expr.h:6950
static RecoveryExpr * Create(ASTContext &Ctx, QualType T, SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs)
Definition: Expr.cpp:5166
static RecoveryExpr * CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs)
Definition: Expr.cpp:5175
static SYCLUniqueStableIdExpr * CreateEmpty(const ASTContext &Ctx)
Definition: Expr.cpp:641
std::string ComputeName(ASTContext &Context) const
Definition: Expr.cpp:646
static SYCLUniqueStableIdExpr * Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, Expr *E)
Definition: Expr.cpp:631
TypeSourceInfo * getTypeSourceInfo()
Definition: Expr.h:2091
static SYCLUniqueStableNameExpr * Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: Expr.cpp:578
std::string ComputeName(ASTContext &Context) const
Definition: Expr.cpp:592
static SYCLUniqueStableNameExpr * CreateEmpty(const ASTContext &Ctx)
Definition: Expr.cpp:587
void setExprs(const ASTContext &C, ArrayRef< Expr * > Exprs)
Definition: Expr.cpp:4416
ShuffleVectorExpr(const ASTContext &C, ArrayRef< Expr * > args, QualType Type, SourceLocation BLoc, SourceLocation RP)
Definition: Expr.cpp:4404
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
Definition: Expr.h:4820
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
Definition: Expr.cpp:2325
SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Type, QualType ResultTy, SourceLocation BLoc, SourceLocation RParenLoc, DeclContext *Context)
Definition: Expr.cpp:2295
SourceLocation getLocation() const
Definition: Expr.h:4823
StringRef getBuiltinStr() const
Return a string representing the name of the specific builtin function.
Definition: Expr.cpp:2305
SourceLocIdentKind getIdentKind() const
Definition: Expr.h:4799
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
CharSourceRange getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
Definition: Stmt.h:1225
GenericSelectionExprBitfields GenericSelectionExprBits
Definition: Stmt.h:1233
ParenListExprBitfields ParenListExprBits
Definition: Stmt.h:1232
CallExprBitfields CallExprBits
Definition: Stmt.h:1227
child_range children()
Definition: Stmt.cpp:287
FloatingLiteralBitfields FloatingLiteralBits
Definition: Stmt.h:1221
child_iterator child_begin()
Definition: Stmt.h:1457
StmtClass getStmtClass() const
Definition: Stmt.h:1358
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
UnaryOperatorBitfields UnaryOperatorBits
Definition: Stmt.h:1224
SourceLocExprBitfields SourceLocExprBits
Definition: Stmt.h:1235
ConstantExprBitfields ConstantExprBits
Definition: Stmt.h:1218
llvm::iterator_range< child_iterator > child_range
Definition: Stmt.h:1447
StringLiteralBitfields StringLiteralBits
Definition: Stmt.h:1222
MemberExprBitfields MemberExprBits
Definition: Stmt.h:1228
DeclRefExprBitfields DeclRefExprBits
Definition: Stmt.h:1220
ConstStmtIterator const_child_iterator
Definition: Stmt.h:1445
PredefinedExprBitfields PredefinedExprBits
Definition: Stmt.h:1219
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
BinaryOperatorBitfields BinaryOperatorBits
Definition: Stmt.h:1230
PseudoObjectExprBitfields PseudoObjectExprBits
Definition: Stmt.h:1234
llvm::iterator_range< const_child_iterator > const_child_range
Definition: Stmt.h:1448
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
unsigned GetStringLength() const
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
Definition: Expr.h:1926
unsigned getLength() const
Definition: Expr.h:1890
StringLiteralKind getKind() const
Definition: Expr.h:1893
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:1384
uint32_t getCodeUnit(size_t i) const
Definition: Expr.h:1865
void outputString(raw_ostream &OS) const
Definition: Expr.cpp:1268
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind 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:1246
static StringLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumConcatenated, unsigned Length, unsigned CharByteWidth)
Construct an empty string literal.
Definition: Expr.cpp:1257
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Definition: Expr.h:1921
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3587
bool isUnion() const
Definition: Decl.h:3793
Exposes information about the current target.
Definition: TargetInfo.h:218
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
A template argument list.
Definition: DeclTemplate.h:244
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:280
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:265
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:413
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
A container of type source information.
Definition: Type.h:7342
The base class of the type hierarchy.
Definition: Type.h:1813
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1881
bool isVoidType() const
Definition: Type.h:7939
bool isBooleanType() const
Definition: Type.h:8067
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:1898
bool isArrayType() const
Definition: Type.h:7690
bool isCharType() const
Definition: Type.cpp:2088
bool isPointerType() const
Definition: Type.h:7624
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7979
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8227
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:7928
bool isReferenceType() const
Definition: Type.h:7636
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
Definition: Type.cpp:1866
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:2057
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8054
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2661
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8213
bool isVectorType() const
Definition: Type.h:7730
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8160
bool isNullPtrType() const
Definition: Type.h:7972
bool isRecordType() const
Definition: Type.h:7718
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2620
QualType getArgumentType() const
Definition: Expr.h:2663
bool isArgumentType() const
Definition: Expr.h:2662
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
Definition: Expr.h:2628
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2235
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2284
Opcode getOpcode() const
Definition: Expr.h:2275
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
Definition: Expr.h:2376
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
Definition: Expr.cpp:1484
Expr * getSubExpr() const
Definition: Expr.h:2280
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4900
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1469
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
Definition: Expr.h:2385
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4886
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4879
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
Definition: Expr.cpp:1460
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4346
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition: ExprCXX.h:637
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:707
QualType getType() const
Definition: Decl.h:718
Kind getKind() const
Definition: Value.h:136
Represents a variable declaration or definition.
Definition: Decl.h:919
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3759
Represents a GCC generic vector type.
Definition: Type.h:3981
Defines the clang::TargetInfo interface.
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
bool hasSideEffects(Expr *E, ASTContext &Ctx)
Definition: Transforms.cpp:167
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
llvm::APFloat APFloat
Definition: Floating.h:23
llvm::APInt APInt
Definition: Integral.h:29
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1903
bool LE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:883
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:709
bool Cast(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1717
bool GE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:898
constexpr bool isIntegralType(PrimType T)
Definition: PrimType.h:70
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
Definition: Expr.h:1066
@ Ctor_Base
Base object ctor.
Definition: ABI.h:26
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:161
Expr * IgnoreParensOnlySingleStep(Expr *E)
Definition: IgnoreExpr.h:144
Expr * IgnoreCastsSingleStep(Expr *E)
Definition: IgnoreExpr.h:75
Expr * IgnoreBaseCastsSingleStep(Expr *E)
Definition: IgnoreExpr.h:101
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1760
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1765
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1768
StmtIterator cast_away_const(const ConstStmtIterator &RHS)
Definition: StmtIterator.h:155
Expr * IgnoreParensSingleStep(Expr *E)
Definition: IgnoreExpr.h:150
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:146
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:158
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:148
Expr * IgnoreImplicitAsWrittenSingleStep(Expr *E)
Definition: IgnoreExpr.h:137
BinaryOperatorKind
ExprDependence computeDependence(FullExpr *E)
@ SC_Register
Definition: Specifiers.h:254
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
@ UETT_Last
Definition: TypeTraits.h:55
Expr * IgnoreImplicitCastsSingleStep(Expr *E)
Definition: IgnoreExpr.h:48
@ Dtor_Base
Base object dtor.
Definition: ABI.h:36
UnaryOperatorKind
Expr * IgnoreExprNodes(Expr *E, FnTys &&... Fns)
Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, Recursively apply each of the f...
Definition: IgnoreExpr.h:34
CastKind
CastKind - The kind of operation required for a conversion.
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:5017
Expr * IgnoreImplicitCastsExtraSingleStep(Expr *E)
Definition: IgnoreExpr.h:58
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:129
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
const FunctionProtoType * T
Expr * IgnoreLValueCastsSingleStep(Expr *E)
Definition: IgnoreExpr.h:91
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1275
StringLiteralKind
Definition: Expr.h:1744
@ CC_X86ThisCall
Definition: Specifiers.h:279
@ CC_C
Definition: Specifiers.h:276
@ CC_X86RegCall
Definition: Specifiers.h:284
@ CC_X86VectorCall
Definition: Specifiers.h:280
@ CC_X86StdCall
Definition: Specifiers.h:277
@ CC_X86FastCall
Definition: Specifiers.h:278
Expr * IgnoreImplicitSingleStep(Expr *E)
Definition: IgnoreExpr.h:111
SourceLocIdentKind
Definition: Expr.h:4766
PredefinedIdentKind
Definition: Expr.h:1970
@ PrettyFunctionNoVirtual
The same as PrettyFunction, except that the 'virtual' keyword is omitted for virtual member functions...
CharacterLiteralKind
Definition: Expr.h:1584
NonOdrUseReason
The reason why a DeclRefExpr does not constitute an odr-use.
Definition: Specifiers.h:170
unsigned long uint64_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define true
Definition: stdbool.h:25
#define false
Definition: stdbool.h:26
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:728
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
SourceLocation getEndLoc() const LLVM_READONLY
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:642
APValue Val
Val - This is the value the expression can be folded to.
Definition: Expr.h:644
Iterator range representation begin:end[:step].
Definition: ExprOpenMP.h:154
Helper expressions and declaration for OMPIteratorExpr class for each iteration space.
Definition: ExprOpenMP.h:111
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition: Stmt.h:1298
An adjustment to be made to the temporary created when emitting a reference binding,...
Definition: Expr.h:66
uint64_t Width
Definition: ASTContext.h:156