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