clang 23.0.0git
PtrTypesSemantics.cpp
Go to the documentation of this file.
1//=======- PtrTypesSemantics.cpp ---------------------------------*- C++ -*-==//
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#include "PtrTypesSemantics.h"
10#include "ASTUtils.h"
11#include "clang/AST/Attr.h"
13#include "clang/AST/Decl.h"
14#include "clang/AST/DeclCXX.h"
15#include "clang/AST/ExprCXX.h"
18#include <optional>
19
20using namespace clang;
21
22namespace {
23
24bool hasPublicMethodInBaseClass(const CXXRecordDecl *R, StringRef NameToMatch) {
25 assert(R);
26 assert(R->hasDefinition());
27
28 for (const CXXMethodDecl *MD : R->methods()) {
29 const auto MethodName = safeGetName(MD);
30 if (MethodName == NameToMatch && MD->getAccess() == AS_public)
31 return true;
32 }
33 return false;
34}
35
36} // namespace
37
38namespace clang {
39
40std::optional<const clang::CXXRecordDecl *>
41hasPublicMethodInBase(const CXXBaseSpecifier *Base, StringRef NameToMatch) {
42 assert(Base);
43
44 const Type *T = Base->getType().getTypePtrOrNull();
45 if (!T)
46 return std::nullopt;
47
48 const CXXRecordDecl *R = T->getAsCXXRecordDecl();
49 if (!R) {
50 auto CT = Base->getType().getCanonicalType();
51 if (auto *TST = dyn_cast<TemplateSpecializationType>(CT)) {
52 auto TmplName = TST->getTemplateName();
53 if (!TmplName.isNull()) {
54 if (auto *TD = TmplName.getAsTemplateDecl())
55 R = dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl());
56 }
57 }
58 if (!R)
59 return std::nullopt;
60 }
61 if (!R->hasDefinition())
62 return std::nullopt;
63
64 return hasPublicMethodInBaseClass(R, NameToMatch) ? R : nullptr;
65}
66
67std::optional<bool> isSmartPtrCompatible(const CXXRecordDecl *R,
68 StringRef IncMethodName,
69 StringRef DecMethodName) {
70 assert(R);
71
72 R = R->getDefinition();
73 if (!R)
74 return std::nullopt;
75
76 bool hasRef = hasPublicMethodInBaseClass(R, IncMethodName);
77 bool hasDeref = hasPublicMethodInBaseClass(R, DecMethodName);
78 if (hasRef && hasDeref)
79 return true;
80
81 CXXBasePaths Paths;
82 Paths.setOrigin(const_cast<CXXRecordDecl *>(R));
83
84 bool AnyInconclusiveBase = false;
85 const auto hasPublicRefInBase = [&](const CXXBaseSpecifier *Base,
86 CXXBasePath &) {
87 auto hasRefInBase = clang::hasPublicMethodInBase(Base, IncMethodName);
88 if (!hasRefInBase) {
89 AnyInconclusiveBase = true;
90 return false;
91 }
92 return (*hasRefInBase) != nullptr;
93 };
94
95 hasRef = hasRef || R->lookupInBases(hasPublicRefInBase, Paths,
96 /*LookupInDependent =*/true);
97 if (AnyInconclusiveBase)
98 return std::nullopt;
99
100 Paths.clear();
101 const auto hasPublicDerefInBase = [&](const CXXBaseSpecifier *Base,
102 CXXBasePath &) {
103 auto hasDerefInBase = clang::hasPublicMethodInBase(Base, DecMethodName);
104 if (!hasDerefInBase) {
105 AnyInconclusiveBase = true;
106 return false;
107 }
108 return (*hasDerefInBase) != nullptr;
109 };
110 hasDeref = hasDeref || R->lookupInBases(hasPublicDerefInBase, Paths,
111 /*LookupInDependent =*/true);
112 if (AnyInconclusiveBase)
113 return std::nullopt;
114
115 return hasRef && hasDeref;
116}
117
118std::optional<bool> isRefCountable(const clang::CXXRecordDecl *R) {
119 return isSmartPtrCompatible(R, "ref", "deref");
120}
121
122std::optional<bool> isCheckedPtrCapable(const clang::CXXRecordDecl *R) {
123 return isSmartPtrCompatible(R, "incrementCheckedPtrCount",
124 "decrementCheckedPtrCount");
125}
126
127bool isRefType(const std::string &Name) {
128 return Name == "Ref" || Name == "RefAllowingPartiallyDestroyed" ||
129 Name == "RefPtr" || Name == "RefPtrAllowingPartiallyDestroyed";
130}
131
132bool isRetainPtrOrOSPtr(const std::string &Name) {
133 return Name == "RetainPtr" || Name == "RetainPtrArc" ||
134 Name == "OSObjectPtr" || Name == "OSObjectPtrArc";
135}
136
137bool isCheckedPtr(const std::string &Name) {
138 return Name == "CheckedPtr" || Name == "CheckedRef";
139}
140
141bool isOwnerPtr(const std::string &Name) {
142 return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) ||
143 Name == "unique_ptr" || Name == "UniqueRef" || Name == "LazyUniqueRef";
144}
145
146static bool isWeakPtrClass(const std::string &Name) {
147 return Name == "WeakPtr" || Name == "SingleThreadPackedWeakPtr" ||
148 Name == "SingleThreadWeakPtr" || Name == "ThreadSafeWeakPtr" ||
149 Name == "ThreadSafeWeakOrStrongPtr" || Name == "InlineWeakPtr";
150}
151
152bool isSmartPtrClass(const std::string &Name) {
153 return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) ||
154 isWeakPtrClass(Name) || Name == "WeakPtrFactory" ||
155 Name == "WeakPtrFactoryWithBitField" || Name == "WeakPtrImplBase" ||
156 Name == "WeakPtrImplBaseSingleThread" ||
157 Name == "ThreadSafeWeakOrStrongPtr" ||
158 Name == "ThreadSafeWeakPtrControlBlock" ||
159 Name == "ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr";
160}
161
163 if (auto *Ctor = dyn_cast_or_null<CXXConstructorDecl>(F))
164 return safeGetName(Ctor->getParent());
165 return safeGetName(F);
166}
167
169 assert(F);
170 auto FunctionName = getConstructorName(F);
171 return isRefType(FunctionName) || FunctionName == "adoptRef" ||
172 FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
173 FunctionName == "makeUniqueRefWithoutFastMallocCheck"
174
175 || FunctionName == "String" || FunctionName == "AtomString" ||
176 FunctionName == "UniqueString"
177 // FIXME: Implement as attribute.
178 || FunctionName == "Identifier";
179}
180
182 assert(F);
184}
185
187 auto FunctionName = getConstructorName(F);
188 return isRetainPtrOrOSPtr(FunctionName) || FunctionName == "adoptNS" ||
189 FunctionName == "adoptNSNullable" || FunctionName == "adoptCF" ||
190 FunctionName == "adoptCFNullable" || FunctionName == "retainPtr" ||
191 FunctionName == "adoptNSArc" || FunctionName == "adoptOSObject" ||
192 FunctionName == "adoptOSObjectArc";
193}
194
199
201 auto FnName = safeGetName(F);
202 auto *Namespace = F->getParent();
203 if (!Namespace)
204 return false;
205 auto *TUDeck = Namespace->getParent();
206 if (!isa_and_nonnull<TranslationUnitDecl>(TUDeck))
207 return false;
208 auto NsName = safeGetName(Namespace);
209 return (NsName == "WTF" || NsName == "std") && FnName == "move";
210}
211
212template <typename Predicate>
213static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
214 QualType type = T;
215 while (!type.isNull()) {
216 if (auto *SpecialT = type->getAs<TemplateSpecializationType>()) {
217 auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
218 return Decl && Pred(Decl->getNameAsString());
219 } else if (auto *DTS = type->getAs<DeducedTemplateSpecializationType>()) {
220 auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
221 return Decl && Pred(Decl->getNameAsString());
222 } else
223 break;
224 }
225 return false;
226}
227
229 return isPtrOfType(
230 T, [](auto Name) { return isRefType(Name) || isCheckedPtr(Name); });
231}
232
234 return isPtrOfType(T, [](auto Name) { return isRetainPtrOrOSPtr(Name); });
235}
236
238 return isPtrOfType(T, [](auto Name) { return isOwnerPtr(Name); });
239}
240
241std::optional<bool> isUncounted(const QualType T) {
242 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
243 if (auto *Decl = Subst->getAssociatedDecl()) {
245 return false;
246 }
247 }
248 return isUncounted(T->getAsCXXRecordDecl());
249}
250
251std::optional<bool> isUnchecked(const QualType T) {
252 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
253 if (auto *Decl = Subst->getAssociatedDecl()) {
255 return false;
256 }
257 }
258 return isUnchecked(T->getAsCXXRecordDecl());
259}
260
262 const TranslationUnitDecl *TUD) {
263 IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount;
264 DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties;
265}
266
268 auto QT = TD->getUnderlyingType();
269 if (!QT->isPointerType())
270 return;
271
272 auto PointeeQT = QT->getPointeeType();
273 const RecordType *RT = PointeeQT->getAsCanonical<RecordType>();
274 if (!RT) {
275 if (TD->hasAttr<ObjCBridgeAttr>() || TD->hasAttr<ObjCBridgeMutableAttr>()) {
276 RecordlessTypes.insert(TD->getASTContext()
278 /*Qualifier=*/std::nullopt, TD)
279 .getTypePtr());
280 }
281 return;
282 }
283
284 for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
285 if (Redecl->getAttr<ObjCBridgeAttr>() ||
286 Redecl->getAttr<ObjCBridgeMutableAttr>()) {
287 CFPointees.insert(RT);
288 return;
289 }
290 }
291}
292
293bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
294 if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
295 return true;
296 if (auto *RT = dyn_cast_or_null<RecordType>(
298 return CFPointees.contains(RT);
299 return RecordlessTypes.contains(QT.getTypePtr());
300}
301
302std::optional<bool> isUncounted(const CXXRecordDecl* Class)
303{
304 // Keep isRefCounted first as it's cheaper.
305 if (!Class || isRefCounted(Class))
306 return false;
307
308 std::optional<bool> IsRefCountable = isRefCountable(Class);
309 if (!IsRefCountable)
310 return std::nullopt;
311
312 return (*IsRefCountable);
313}
314
315std::optional<bool> isUnchecked(const CXXRecordDecl *Class) {
316 if (!Class || isCheckedPtr(Class))
317 return false; // Cheaper than below
319}
320
321std::optional<bool> isUncountedPtr(const QualType T) {
322 if (T->isPointerType() || T->isReferenceType()) {
323 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
324 return isUncounted(CXXRD);
325 }
326 return false;
327}
328
329std::optional<bool> isUncheckedPtr(const QualType T) {
330 if (T->isPointerType() || T->isReferenceType()) {
331 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
332 return isUnchecked(CXXRD);
333 }
334 return false;
335}
336
337std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
338 assert(M);
339
340 const CXXRecordDecl *calleeMethodsClass = M->getParent();
341 std::string className = safeGetName(calleeMethodsClass);
342 std::string method = safeGetName(M);
343
344 if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
345 return true;
346
347 if ((isRefType(className) && (method == "get" || method == "ptr")) ||
348 ((className == "String" || className == "AtomString" ||
349 className == "AtomStringImpl" || className == "UniqueString" ||
350 className == "UniqueStringImpl" || className == "Identifier") &&
351 method == "impl"))
352 return true;
353
354 if (isRetainPtrOrOSPtr(className) && method == "get")
355 return true;
356
357 // Ref<T> -> T conversion
358 // FIXME: Currently allowing any Ref<T> -> whatever cast.
359 if (isRefType(className)) {
360 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
361 QualType QT = maybeRefToRawOperator->getConversionType();
362 const Type *T = QT.getTypePtrOrNull();
363 return T && (T->isPointerType() || T->isReferenceType());
364 }
365 }
366
367 if (isCheckedPtr(className)) {
368 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
369 QualType QT = maybeRefToRawOperator->getConversionType();
370 const Type *T = QT.getTypePtrOrNull();
371 return T && (T->isPointerType() || T->isReferenceType());
372 }
373 }
374
375 if (isRetainPtrOrOSPtr(className)) {
376 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
377 QualType QT = maybeRefToRawOperator->getConversionType();
378 const Type *T = QT.getTypePtrOrNull();
379 return T && (T->isPointerType() || T->isReferenceType() ||
380 T->isObjCObjectPointerType());
381 }
382 }
383 return false;
384}
385
387 assert(R);
388 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
389 // FIXME: String/AtomString/UniqueString
390 const auto &ClassName = safeGetName(TmplR);
391 return isRefType(ClassName);
392 }
393 return false;
394}
395
397 assert(R);
398 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
399 const auto &ClassName = safeGetName(TmplR);
400 return isCheckedPtr(ClassName);
401 }
402 return false;
403}
404
406 assert(R);
407 if (auto *TmplR = R->getTemplateInstantiationPattern())
408 return isRetainPtrOrOSPtr(safeGetName(TmplR));
409 return false;
410}
411
412bool isWeakPtr(const CXXRecordDecl *R) {
413 assert(R);
414 if (auto *TmplR = R->getTemplateInstantiationPattern())
415 return isWeakPtrClass(safeGetName(TmplR));
416 return false;
417}
418
419bool isSmartPtr(const CXXRecordDecl *R) {
420 assert(R);
421 if (auto *TmplR = R->getTemplateInstantiationPattern())
422 return isSmartPtrClass(safeGetName(TmplR));
423 return false;
424}
425
431
433 auto RetType = FD->getReturnType();
434 auto *Type = RetType.getTypePtrOrNull();
435 if (auto *MacroQualified = dyn_cast_or_null<MacroQualifiedType>(Type))
436 Type = MacroQualified->desugar().getTypePtrOrNull();
437 auto *Attr = dyn_cast_or_null<AttributedType>(Type);
438 if (!Attr)
440 auto *AnnotateType = dyn_cast_or_null<AnnotateTypeAttr>(Attr->getAttr());
441 if (!AnnotateType)
443 auto Annotation = AnnotateType->getAnnotation();
444 if (Annotation == "webkit.pointerconversion")
446 if (Annotation == "webkit.nodelete")
449}
450
452 assert(F);
453 if (isCtorOfRefCounted(F))
454 return true;
455
456 // FIXME: check # of params == 1
457 const auto FunctionName = safeGetName(F);
458 if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
459 FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
460 FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
461 FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
462 FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
463 FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||
464 FunctionName == "dynamic_objc_cast" ||
465 FunctionName == "checked_objc_cast")
466 return true;
467
469 return true;
470
471 return false;
472}
473
477
479 if (llvm::any_of(F->redecls(), isNoDeleteFunctionDecl))
480 return true;
481
482 const auto *MD = dyn_cast<CXXMethodDecl>(F);
483 if (!MD || !MD->isVirtual())
484 return false;
485
486 auto Overriders = llvm::to_vector(MD->overridden_methods());
487 while (!Overriders.empty()) {
488 const auto *Fn = Overriders.pop_back_val();
489 llvm::append_range(Overriders, Fn->overridden_methods());
491 return true;
492 }
493
494 return false;
495}
496
498 if (!F || !F->getDeclName().isIdentifier())
499 return false;
500 auto Name = F->getName();
501 return Name.starts_with("__builtin") || Name == "__libcpp_verbose_abort" ||
502 Name.starts_with("os_log") || Name.starts_with("_os_log");
503}
504
505bool isSingleton(const NamedDecl *F) {
506 assert(F);
507 // FIXME: check # of params == 1
508 if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(F)) {
509 if (!MethodDecl->isStatic())
510 return false;
511 }
512 const auto &NameStr = safeGetName(F);
513 StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
514 return Name == "singleton" || Name.ends_with("Singleton");
515}
516
517// We only care about statements so let's use the simple
518// (non-recursive) visitor.
520 : public ConstStmtVisitor<TrivialFunctionAnalysisVisitor, bool> {
521
522 // Returns false if at least one child is non-trivial.
523 bool VisitChildren(const Stmt *S) {
524 for (const Stmt *Child : S->children()) {
525 if (Child && !Visit(Child)) {
526 if (OffendingStmt && !*OffendingStmt)
527 *OffendingStmt = Child;
528 return false;
529 }
530 }
531
532 return true;
533 }
534
535 template <typename StmtOrDecl, typename CheckFunction>
536 bool WithCachedResult(const StmtOrDecl *S, CheckFunction Function) {
537 auto CacheIt = Cache.find(S);
538 if (CacheIt != Cache.end() && !OffendingStmt)
539 return CacheIt->second;
540
541 // Treat a recursive statement to be trivial until proven otherwise.
542 auto [RecursiveIt, IsNew] = RecursiveFn.insert(std::make_pair(S, true));
543 if (!IsNew)
544 return RecursiveIt->second;
545
546 bool Result = Function();
547
548 if (!Result) {
549 for (auto &It : RecursiveFn)
550 It.second = false;
551 }
552 RecursiveIt = RecursiveFn.find(S);
553 assert(RecursiveIt != RecursiveFn.end());
554 Result = RecursiveIt->second;
555 RecursiveFn.erase(RecursiveIt);
556 Cache[S] = Result;
557
558 return Result;
559 }
560
561 bool CanTriviallyDestruct(QualType Ty) {
562 if (Ty.isNull())
563 return false;
564
565 // T*, T& or T&& does not run its destructor.
566 if (Ty->isPointerOrReferenceType())
567 return true;
568
569 // FIXME: Handle a case when there is a local autorelease pool.
570 if (Ty->isObjCObjectPointerType()) {
571 auto Type = Ty.isDestructedType();
573 return true;
574 // strong lifetime in ARC could dealloc an object.
575 }
576
577 // Fundamental types (integral, nullptr_t, etc...) don't have destructors.
579 return true;
580
581 if (const auto *R = Ty->getAsCXXRecordDecl()) {
582 // C++ trivially destructible classes are fine.
583 if (R->hasDefinition() && R->hasTrivialDestructor())
584 return true;
585
586 if (HasFieldWithNonTrivialDtor(R))
587 return false;
588
589 // For Webkit, side-effects are fine as long as we don't delete objects,
590 // so check recursively.
591 if (const auto *Dtor = R->getDestructor())
592 return IsFunctionTrivial(Dtor);
593 }
594
595 // Structs in C are trivial.
596 if (Ty->isRecordType())
597 return true;
598
599 // For arrays it depends on the element type.
600 // FIXME: We should really use ASTContext::getAsArrayType instead.
601 if (const auto *AT = Ty->getAsArrayTypeUnsafe())
602 return CanTriviallyDestruct(AT->getElementType());
603
604 return false; // Otherwise it's likely not trivial.
605 }
606
607 bool HasFieldWithNonTrivialDtor(const CXXRecordDecl *Cls) {
608 auto CacheIt = FieldDtorCache.find(Cls);
609 if (CacheIt != FieldDtorCache.end())
610 return CacheIt->second;
611
612 bool Result = ([&] {
613 auto HasNonTrivialField = [&](const CXXRecordDecl *R) {
614 for (const FieldDecl *F : R->fields()) {
615 if (!CanTriviallyDestruct(F->getType()))
616 return true;
617 }
618 return false;
619 };
620
621 if (HasNonTrivialField(Cls))
622 return true;
623
624 if (!Cls->hasDefinition())
625 return false;
626
627 CXXBasePaths Paths;
628 Paths.setOrigin(const_cast<CXXRecordDecl *>(Cls));
629 return Cls->lookupInBases(
630 [&](const CXXBaseSpecifier *B, CXXBasePath &) {
631 auto *T = B->getType().getTypePtrOrNull();
632 if (!T)
633 return false;
634 auto *R = T->getAsCXXRecordDecl();
635 return R && HasNonTrivialField(R);
636 },
637 Paths, /*LookupInDependent =*/true);
638 })();
639
640 FieldDtorCache[Cls] = Result;
641
642 return Result;
643 }
644
645public:
646 using CacheTy = TrivialFunctionAnalysis::CacheTy;
647
649 const Stmt **OffendingStmt = nullptr)
650 : Cache(Cache), OffendingStmt(OffendingStmt) {}
651
652 bool IsFunctionTrivial(const Decl *D) {
653 const Stmt **SavedOffendingStmt = std::exchange(OffendingStmt, nullptr);
654 auto Result = WithCachedResult(D, [&]() {
655 auto *FnDecl = dyn_cast<FunctionDecl>(D);
656 auto *MethodDecl = dyn_cast<CXXMethodDecl>(D);
657 auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D);
658 auto *DtorDecl = dyn_cast<CXXDestructorDecl>(D);
659
660 if (FnDecl) {
661 if (isNoDeleteFunction(FnDecl))
662 return true;
663 if (MethodDecl && MethodDecl->isVirtual())
664 return false;
665 for (auto *Param : FnDecl->parameters()) {
666 if (!HasTrivialDestructor(Param))
667 return false;
668 }
669 }
670 if (CtorDecl) {
671 for (auto *CtorInit : CtorDecl->inits()) {
672 if (!Visit(CtorInit->getInit()))
673 return false;
674 }
675 }
676 // An implicit or =default special member runs no user code when it is
677 // trivial in the C++ standard sense, so it cannot delete. Such a
678 // member's synthesized body is typically absent from the AST until
679 // codegen materialises it, which the generic null-body check below
680 // would otherwise conservatively classify as non-trivial.
681 if (MethodDecl && !MethodDecl->isUserProvided()) {
682 if (CtorDecl) {
683 const CXXRecordDecl *RD = CtorDecl->getParent();
684 if ((CtorDecl->isDefaultConstructor() &&
686 (CtorDecl->isCopyConstructor() &&
688 (CtorDecl->isMoveConstructor() &&
690 return true;
691 }
692 if (DtorDecl && DtorDecl->getParent()->hasTrivialDestructor())
693 return true;
694 }
695 const Stmt *Body = D->getBody();
696 if (!Body)
697 return false;
698 return Visit(Body);
699 });
700 OffendingStmt = SavedOffendingStmt;
701 return Result;
702 }
703
705 return WithCachedResult(
706 VD, [&] { return CanTriviallyDestruct(VD->getType()); });
707 }
708
709 bool IsStatementTrivial(const Stmt *S) {
710 auto CacheIt = Cache.find(S);
711 if (CacheIt != Cache.end())
712 return CacheIt->second;
713 bool Result = Visit(S);
714 Cache[S] = Result;
715 return Result;
716 }
717
718 bool VisitStmt(const Stmt *S) {
719 // All statements are non-trivial unless overriden later.
720 // Don't even recurse into children by default.
721 return false;
722 }
723
725 // Ignore attributes.
726 return Visit(AS->getSubStmt());
727 }
728
730 // A compound statement is allowed as long each individual sub-statement
731 // is trivial.
732 return WithCachedResult(CS, [&]() { return VisitChildren(CS); });
733 }
734
736 return WithCachedResult(CBS, [&]() { return VisitChildren(CBS); });
737 }
738
739 bool VisitReturnStmt(const ReturnStmt *RS) {
740 // A return statement is allowed as long as the return value is trivial. A
741 // returned smart-pointer prvalue is special: under guaranteed copy elision
742 // the temporary *is* the function's return slot, so it is destructed by the
743 // caller, not here. Hence we may ignore that temporary's destructor.
744 if (auto *RV = RS->getRetValue())
746 return true;
747 }
748
749 bool VisitDeclStmt(const DeclStmt *DS) {
750 for (auto &Decl : DS->decls()) {
751 // FIXME: Handle DecompositionDecls.
752 if (auto *VD = dyn_cast<VarDecl>(Decl)) {
753 if (!HasTrivialDestructor(VD))
754 return false;
755 }
756 }
757 return VisitChildren(DS);
758 }
759 bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
760 bool VisitIfStmt(const IfStmt *IS) {
761 return WithCachedResult(IS, [&]() { return VisitChildren(IS); });
762 }
763 bool VisitForStmt(const ForStmt *FS) {
764 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
765 }
767 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
768 }
769 bool VisitWhileStmt(const WhileStmt *WS) {
770 return WithCachedResult(WS, [&]() { return VisitChildren(WS); });
771 }
772 bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
773 bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
774 bool VisitDefaultStmt(const DefaultStmt *DS) { return VisitChildren(DS); }
775
776 // break, continue, goto, and label statements are always trivial.
777 bool VisitBreakStmt(const BreakStmt *) { return true; }
778 bool VisitContinueStmt(const ContinueStmt *) { return true; }
779 bool VisitGotoStmt(const GotoStmt *) { return true; }
780 bool VisitLabelStmt(const LabelStmt *) { return true; }
781
783 // Unary operators are trivial if its operand is trivial except co_await.
784 return UO->getOpcode() != UO_Coawait && Visit(UO->getSubExpr());
785 }
786
788 // Binary operators are trivial if their operands are trivial.
789 return Visit(BO->getLHS()) && Visit(BO->getRHS());
790 }
791
793 // Compound assignment operator such as |= is trivial if its
794 // subexpresssions are trivial.
795 return VisitChildren(CAO);
796 }
797
799 return VisitChildren(ASE);
800 }
801
803 // Ternary operators are trivial if their conditions & values are trivial.
804 return VisitChildren(CO);
805 }
806
807 bool VisitAtomicExpr(const AtomicExpr *E) { return VisitChildren(E); }
808
810 // Any static_assert is considered trivial.
811 return true;
812 }
813
814 bool VisitCallExpr(const CallExpr *CE) {
815 if (!checkArguments(CE))
816 return false;
817
818 auto *Callee = CE->getDirectCallee();
819 if (!Callee)
820 return false;
821
822 if (isPtrConversion(Callee))
823 return true;
824
825 const auto &Name = safeGetName(Callee);
826
827 if (Callee->isInStdNamespace() &&
828 (Name == "addressof" || Name == "forward" || Name == "move"))
829 return true;
830
831 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
832 Name == "WTFReportBacktrace" ||
833 Name == "WTFCrashWithSecurityImplication" || Name == "WTFCrash" ||
834 Name == "WTFReportAssertionFailure" || Name == "isMainThread" ||
835 Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
836 Name == "isWebThread" || Name == "isUIThread" ||
837 Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
839 return true;
840
841 return IsFunctionTrivial(Callee);
842 }
843
844 bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
845 return AS->getAsmString() == "brk #0xc471";
846 }
847
848 bool
850 // Non-type template paramter is compile time constant and trivial.
851 return true;
852 }
853
855 return VisitChildren(E);
856 }
857
859 // A predefined identifier such as "func" is considered trivial.
860 return true;
861 }
862
864 // offsetof(T, D) is considered trivial.
865 return true;
866 }
867
869 if (!checkArguments(MCE))
870 return false;
871
872 bool TrivialThis = Visit(MCE->getImplicitObjectArgument());
873 if (!TrivialThis)
874 return false;
875
876 auto *Callee = MCE->getMethodDecl();
877 if (!Callee)
878 return false;
879
880 if (isa<CXXDestructorDecl>(Callee) &&
881 !CanTriviallyDestruct(MCE->getObjectType()))
882 return false;
883
884 auto Name = safeGetName(Callee);
885 if (Name == "ref" || Name == "incrementCheckedPtrCount")
886 return true;
887
888 std::optional<bool> IsGetterOfRefCounted = isGetterOfSafePtr(Callee);
889 if (IsGetterOfRefCounted && *IsGetterOfRefCounted)
890 return true;
891
892 // Recursively descend into the callee to confirm that it's trivial as well.
893 return IsFunctionTrivial(Callee);
894 }
895
897 if (!checkArguments(OCE))
898 return false;
899 auto *Callee = OCE->getCalleeDecl();
900 if (!Callee)
901 return false;
902 // Recursively descend into the callee to confirm that it's trivial as well.
903 return IsFunctionTrivial(Callee);
904 }
905
907 auto *SemanticExpr = Op->getSemanticForm();
908 return SemanticExpr && Visit(SemanticExpr);
909 }
910
912 if (auto *Expr = E->getExpr()) {
913 if (!Visit(Expr))
914 return false;
915 }
916 return true;
917 }
918
920 return Visit(E->getExpr());
921 }
922
923 bool checkArguments(const CallExpr *CE) {
924 for (const Expr *Arg : CE->arguments()) {
925 if (Arg && !Visit(Arg))
926 return false;
927 }
928 return true;
929 }
930
931 // Triviality check for a return value that may elide a smart-pointer
932 // temporary's destructor.
933 //
934 // This is only valid for *return values*: a returned class prvalue is
935 // constructed directly into the function's return slot (C++17 guaranteed copy
936 // elision), so the temporary is destructed by the caller rather than here.
937 //
938 // It is deliberately NOT applied to call/constructor arguments. An argument
939 // temporary's lifetime ends at the full-expression *in this function* (the
940 // caller destroys arguments, e.g. per the Itanium C++ ABI), so its destructor
941 // runs here and may invoke delete. Proving otherwise would require
942 // interprocedural ownership analysis, so arguments are checked normally.
944 QualType OriginalQT = Arg->getType();
945 auto *Type = OriginalQT.getTypePtrOrNull();
946 if (!Type)
947 return Visit(Arg);
948 auto *CXXRD = Type->getAsCXXRecordDecl();
949 if (!CXXRD || !isSmartPtrClass(safeGetName(CXXRD)))
950 return Visit(Arg);
951 Arg = Arg->IgnoreParenCasts();
952 if (!Arg->isPRValue())
953 return Visit(Arg);
954 if (auto *ExprWithClean = dyn_cast<ExprWithCleanups>(Arg))
955 Arg = ExprWithClean->getSubExpr()->IgnoreParenCasts();
956 if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Arg)) {
957 // Only elide when the temporary *is* the returned object, i.e. it has the
958 // same smart-pointer type as the return value. Compare canonical,
959 // unqualified types rather than relying on exact QualType identity, which
960 // is sensitive to sugar (typedefs/aliases) and cv-qualifiers.
961 if (OriginalQT.getCanonicalType().getUnqualifiedType() ==
962 BTE->getType().getCanonicalType().getUnqualifiedType())
963 return Visit(BTE->getSubExpr());
964 }
965 return Visit(Arg);
966 }
967
969 for (const Expr *Arg : CE->arguments()) {
970 if (Arg && !Visit(Arg))
971 return false;
972 }
973
974 // Recursively descend into the callee to confirm that it's trivial.
975 return IsFunctionTrivial(CE->getConstructor());
976 }
977
981
982 bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
983
985 return Visit(ICE->getSubExpr());
986 }
987
989 return Visit(ECE->getSubExpr());
990 }
991
993 return Visit(VMT->getSubExpr());
994 }
995
997 if (auto *Temp = BTE->getTemporary()) {
998 if (!IsFunctionTrivial(Temp->getDestructor()))
999 return false;
1000 }
1001 return Visit(BTE->getSubExpr());
1002 }
1003
1005 return Visit(AILE->getCommonExpr()) && Visit(AILE->getSubExpr());
1006 }
1007
1009 return true; // The current array index in VisitArrayInitLoopExpr is always
1010 // trivial.
1011 }
1012
1014 return Visit(OVE->getSourceExpr());
1015 }
1016
1018 return Visit(EWC->getSubExpr());
1019 }
1020
1021 bool VisitParenExpr(const ParenExpr *PE) { return Visit(PE->getSubExpr()); }
1022
1024 for (const Expr *Child : ILE->inits()) {
1025 if (Child && !Visit(Child))
1026 return false;
1027 }
1028 return true;
1029 }
1030
1031 bool VisitMemberExpr(const MemberExpr *ME) {
1032 // Field access is allowed but the base pointer may itself be non-trivial.
1033 return Visit(ME->getBase());
1034 }
1035
1037 // The expression 'this' is always trivial, be it explicit or implicit.
1038 return true;
1039 }
1040
1042 // nullptr is trivial.
1043 return true;
1044 }
1045
1047 // The use of a variable is trivial.
1048 return true;
1049 }
1050
1051 // Constant literal expressions are always trivial
1052 bool VisitIntegerLiteral(const IntegerLiteral *E) { return true; }
1053 bool VisitFloatingLiteral(const FloatingLiteral *E) { return true; }
1054 bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
1055 bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
1056 bool VisitStringLiteral(const StringLiteral *E) { return true; }
1057 bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
1058
1060 // Constant expressions are trivial.
1061 return true;
1062 }
1063
1065 // An implicit value initialization is trvial.
1066 return true;
1067 }
1068
1069private:
1070 CacheTy &Cache;
1071 CacheTy FieldDtorCache;
1072 CacheTy RecursiveFn;
1073 const Stmt **OffendingStmt;
1074};
1075
1076bool TrivialFunctionAnalysis::isTrivialImpl(
1077 const Decl *D, TrivialFunctionAnalysis::CacheTy &Cache,
1078 const Stmt **OffendingStmt) {
1079 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1080 return V.IsFunctionTrivial(D);
1081}
1082
1083bool TrivialFunctionAnalysis::isTrivialImpl(
1084 const Stmt *S, TrivialFunctionAnalysis::CacheTy &Cache,
1085 const Stmt **OffendingStmt) {
1086 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1087 return V.IsStatementTrivial(S);
1088}
1089
1090bool TrivialFunctionAnalysis::hasTrivialDtorImpl(const VarDecl *VD,
1091 CacheTy &Cache) {
1093 return V.HasTrivialDestructor(VD);
1094}
1095
1096} // namespace clang
#define V(N, I)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
TypePropertyCache< Private > Cache
Definition Type.cpp:4918
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6024
Represents a loop initializing the elements of an array.
Definition Expr.h:5971
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5986
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5991
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2727
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6931
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2213
Stmt * getSubStmt()
Definition Stmt.h:2249
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4044
Expr * getLHS() const
Definition Expr.h:4094
Expr * getRHS() const
Definition Expr.h:4096
BreakStmt - This represents a break.
Definition Stmt.h:3145
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
void setOrigin(const CXXRecordDecl *Rec)
void clear()
Clear the base-paths results.
Represents a base class of a C++ class.
Definition DeclCXX.h:146
QualType getType() const
Retrieves the type of the base class.
Definition DeclCXX.h:249
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
CXXTemporary * getTemporary()
Definition ExprCXX.h:1515
const Expr * getSubExpr() const
Definition ExprCXX.h:1519
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
arg_range arguments()
Definition ExprCXX.h:1676
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1615
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1112
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1792
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Definition ExprCXX.cpp:748
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition ExprCXX.cpp:729
QualType getObjectType() const
Retrieve the type of the object argument.
Definition ExprCXX.cpp:741
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2284
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:772
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:85
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
Definition DeclCXX.h:1251
bool hasTrivialMoveConstructor() const
Determine whether this class has a trivial move constructor (C++11 [class.copy]p12)
Definition DeclCXX.h:1312
bool hasTrivialCopyConstructor() const
Determine whether this class has a trivial copy constructor (C++ [class.copy]p6, C++11 [class....
Definition DeclCXX.h:1289
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
bool hasDefinition() const
Definition DeclCXX.h:561
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:290
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:308
Represents the this expression in C++.
Definition ExprCXX.h:1158
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2949
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3132
arg_range arguments()
Definition Expr.h:3201
Decl * getCalleeDecl()
Definition Expr.h:3126
CaseStmt - Represent a case statement.
Definition Stmt.h:1930
Expr * getSubExpr()
Definition Expr.h:3732
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4306
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
ConditionalOperator - The ?
Definition Expr.h:4397
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1088
ContinueStmt - This represents a continue.
Definition Stmt.h:3129
Represents the body of a coroutine.
Definition StmtCXX.h:320
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1276
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
decl_range decls()
Definition Stmt.h:1689
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:547
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition DeclBase.h:1100
bool hasAttr() const
Definition DeclBase.h:585
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition DeclBase.cpp:553
bool isIdentifier() const
Predicate functions for querying what type of name this is.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2842
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3934
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3661
This represents one expression.
Definition Expr.h:112
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Definition Expr.cpp:3104
bool isPRValue() const
Definition Expr.h:285
QualType getType() const
Definition Expr.h:144
Represents a member of a struct/union/class.
Definition Decl.h:3182
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2898
const Expr * getSubExpr() const
Definition Expr.h:1068
Represents a function declaration or definition.
Definition Decl.h:2018
QualType getReturnType() const
Definition Decl.h:2863
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3456
std::string getAsmString() const
Definition Stmt.cpp:574
GotoStmt - This represents a direct goto.
Definition Stmt.h:2979
IfStmt - This represents an if/then/else.
Definition Stmt.h:2269
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3859
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6060
Describes an C or C++ initializer list.
Definition Expr.h:5305
ArrayRef< Expr * > inits() const
Definition Expr.h:5358
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2156
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3370
Expr * getBase() const
Definition Expr.h:3447
This represents a decl that may have a name.
Definition Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition Expr.h:2533
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1184
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1234
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2188
const Expr * getSubExpr() const
Definition Expr.h:2205
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2011
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8447
QualType getCanonicalType() const
Definition TypeBase.h:8499
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8541
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1560
const Type * getTypePtrOrNull() const
Definition TypeBase.h:8451
bool isUnretained(const QualType, bool ignoreARC=false)
void visitTranslationUnitDecl(const TranslationUnitDecl *)
void visitTypedef(const TypedefDecl *)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3170
Expr * getRetValue()
Definition Stmt.h:3197
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4154
Stmt - This represents one statement.
Definition Stmt.h:86
child_range children()
Definition Stmt.cpp:304
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1805
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4664
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2519
The top declaration context.
Definition Decl.h:105
bool VisitStringLiteral(const StringLiteral *E)
bool VisitStaticAssertDecl(const StaticAssertDecl *SAD)
bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE)
bool VisitCXXThisExpr(const CXXThisExpr *CTE)
bool VisitUnaryOperator(const UnaryOperator *UO)
bool VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE)
bool VisitPredefinedExpr(const PredefinedExpr *E)
bool VisitContinueStmt(const ContinueStmt *)
bool VisitSwitchStmt(const SwitchStmt *SS)
bool VisitGCCAsmStmt(const GCCAsmStmt *AS)
bool VisitCompoundAssignOperator(const CompoundAssignOperator *CAO)
bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E)
bool VisitFixedPointLiteral(const FixedPointLiteral *E)
bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E)
bool VisitDeclRefExpr(const DeclRefExpr *DRE)
bool VisitIntegerLiteral(const IntegerLiteral *E)
bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *VMT)
bool VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *E)
bool VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *Op)
bool VisitFloatingLiteral(const FloatingLiteral *E)
TrivialFunctionAnalysis::CacheTy CacheTy
bool VisitConditionalOperator(const ConditionalOperator *CO)
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E)
bool VisitCompoundStmt(const CompoundStmt *CS)
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *IVIE)
bool VisitConstantExpr(const ConstantExpr *CE)
bool VisitImplicitCastExpr(const ImplicitCastExpr *ICE)
bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE)
bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E)
bool VisitOpaqueValueExpr(const OpaqueValueExpr *OVE)
bool VisitExprWithCleanups(const ExprWithCleanups *EWC)
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE)
bool VisitCXXNewExpr(const CXXNewExpr *NE)
bool VisitBinaryOperator(const BinaryOperator *BO)
bool VisitCoroutineBodyStmt(const CoroutineBodyStmt *CBS)
bool VisitCXXMemberCallExpr(const CXXMemberCallExpr *MCE)
bool VisitCXXForRangeStmt(const CXXForRangeStmt *FS)
bool VisitCharacterLiteral(const CharacterLiteral *E)
bool VisitInitListExpr(const InitListExpr *ILE)
bool VisitAttributedStmt(const AttributedStmt *AS)
bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E)
bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E)
bool VisitExplicitCastExpr(const ExplicitCastExpr *ECE)
bool VisitArrayInitIndexExpr(const ArrayInitIndexExpr *AIIE)
bool VisitDefaultStmt(const DefaultStmt *DS)
bool VisitOffsetOfExpr(const OffsetOfExpr *OE)
bool VisitCXXConstructExpr(const CXXConstructExpr *CE)
TrivialFunctionAnalysisVisitor(CacheTy &Cache, const Stmt **OffendingStmt=nullptr)
bool VisitReturnStmt(const ReturnStmt *RS)
The base class of the type hierarchy.
Definition TypeBase.h:1875
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition TypeBase.h:8647
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9172
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9330
bool isPointerOrReferenceType() const
Definition TypeBase.h:8688
bool isObjCObjectPointerType() const
Definition TypeBase.h:8863
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2985
bool isRecordType() const
Definition TypeBase.h:8811
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3689
QualType getUnderlyingType() const
Definition Decl.h:3639
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2631
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2250
Expr * getSubExpr() const
Definition Expr.h:2291
Opcode getOpcode() const
Definition Expr.h:2286
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:924
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2707
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool isCocoaObjectRef(QualType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isCtorOfSafePtr(const clang::FunctionDecl *F)
bool isTrivialBuiltinFunction(const FunctionDecl *F)
bool isa(CodeGen::Address addr)
Definition Address.h:330
static bool isNoDeleteFunctionDecl(const FunctionDecl *F)
bool isPtrConversion(const FunctionDecl *F)
static bool isWeakPtrClass(const std::string &Name)
std::optional< bool > isCheckedPtrCapable(const clang::CXXRecordDecl *R)
std::optional< bool > isUnchecked(const QualType T)
bool isCtorOfRefCounted(const clang::FunctionDecl *F)
bool isRefOrCheckedPtrType(const clang::QualType T)
@ AS_public
Definition Specifiers.h:125
bool isRetainPtrOrOSPtrType(const clang::QualType T)
bool isCtorOfRetainPtrOrOSPtr(const clang::FunctionDecl *F)
@ Result
The result type of a method or function.
Definition TypeBase.h:905
bool isOwnerPtr(const std::string &Name)
std::optional< bool > isRefCountable(const clang::CXXRecordDecl *R)
std::optional< const clang::CXXRecordDecl * > hasPublicMethodInBase(const CXXBaseSpecifier *Base, StringRef NameToMatch)
static WebKitAnnotation typeAnnotationForReturnType(const FunctionDecl *FD)
bool isSmartPtrClass(const std::string &Name)
std::string getConstructorName(const clang::FunctionDecl *F)
bool isRefCounted(const CXXRecordDecl *R)
static bool isPtrOfType(const clang::QualType T, Predicate Pred)
std::optional< bool > isSmartPtrCompatible(const CXXRecordDecl *R, StringRef IncMethodName, StringRef DecMethodName)
bool isNoDeleteFunction(const FunctionDecl *F)
bool isOwnerPtrType(const clang::QualType T)
bool isSmartPtr(const CXXRecordDecl *R)
std::optional< bool > isGetterOfSafePtr(const CXXMethodDecl *M)
bool isRetainPtrOrOSPtr(const std::string &Name)
bool isRefType(const std::string &Name)
std::optional< bool > isUncountedPtr(const QualType T)
std::string safeGetName(const T *ASTNode)
Definition ASTUtils.h:95
bool isCtorOfCheckedPtr(const clang::FunctionDecl *F)
bool isSingleton(const NamedDecl *F)
bool isCheckedPtr(const std::string &Name)
bool isStdOrWTFMove(const clang::FunctionDecl *F)
@ None
The alignment was not explicit in code.
Definition ASTContext.h:176
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5991
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5981
std::optional< bool > isUncounted(const QualType T)
std::optional< bool > isUncheckedPtr(const QualType T)
bool isWeakPtr(const CXXRecordDecl *R)