clang 10.0.0git

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