clang 24.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, TD});
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
303 if (auto *TT = dyn_cast_or_null<TypedefType>(QT.getTypePtrOrNull())) {
304 if (auto *TD = dyn_cast<TypedefDecl>(TT->getDecl()))
305 return TD;
306 }
307 QT = QT.getCanonicalType();
308 auto PointeeQT = QT->getPointeeType();
309 auto *PointeeType = PointeeQT.getTypePtrOrNull();
310 if (!PointeeType)
311 return nullptr;
312 auto *RD = dyn_cast<RecordType>(PointeeType);
313 if (!RD)
314 return nullptr;
315 return CFPointees.lookup(RD);
316}
317
318std::optional<bool> isUncounted(const CXXRecordDecl* Class)
319{
320 // Keep isRefCounted first as it's cheaper.
321 if (!Class || isRefCounted(Class))
322 return false;
323
324 std::optional<bool> IsRefCountable = isRefCountable(Class);
325 if (!IsRefCountable)
326 return std::nullopt;
327
328 return (*IsRefCountable);
329}
330
331std::optional<bool> isUnchecked(const CXXRecordDecl *Class) {
332 if (!Class || isCheckedPtr(Class))
333 return false; // Cheaper than below
335}
336
337std::optional<bool> isUncountedPtr(const QualType T) {
338 if (T->isPointerType() || T->isReferenceType()) {
339 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
340 return isUncounted(CXXRD);
341 }
342 return false;
343}
344
345std::optional<bool> isUncheckedPtr(const QualType T) {
346 if (T->isPointerType() || T->isReferenceType()) {
347 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
348 return isUnchecked(CXXRD);
349 }
350 return false;
351}
352
353std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
354 assert(M);
355
356 const CXXRecordDecl *calleeMethodsClass = M->getParent();
357 std::string className = safeGetName(calleeMethodsClass);
358 std::string method = safeGetName(M);
359
360 if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
361 return true;
362
363 if ((isRefType(className) && (method == "get" || method == "ptr")) ||
364 ((className == "String" || className == "AtomString" ||
365 className == "AtomStringImpl" || className == "UniqueString" ||
366 className == "UniqueStringImpl" || className == "Identifier") &&
367 method == "impl"))
368 return true;
369
370 if (isRetainPtrOrOSPtr(className) && method == "get")
371 return true;
372
373 // Ref<T> -> T conversion
374 // FIXME: Currently allowing any Ref<T> -> whatever cast.
375 if (isRefType(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 }
381 }
382
383 if (isCheckedPtr(className)) {
384 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
385 QualType QT = maybeRefToRawOperator->getConversionType();
386 const Type *T = QT.getTypePtrOrNull();
387 return T && (T->isPointerType() || T->isReferenceType());
388 }
389 }
390
391 if (isRetainPtrOrOSPtr(className)) {
392 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
393 QualType QT = maybeRefToRawOperator->getConversionType();
394 const Type *T = QT.getTypePtrOrNull();
395 return T && (T->isPointerType() || T->isReferenceType() ||
396 T->isObjCObjectPointerType());
397 }
398 }
399 return false;
400}
401
403 assert(R);
404 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
405 // FIXME: String/AtomString/UniqueString
406 const auto &ClassName = safeGetName(TmplR);
407 return isRefType(ClassName);
408 }
409 return false;
410}
411
413 assert(R);
414 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
415 const auto &ClassName = safeGetName(TmplR);
416 return isCheckedPtr(ClassName);
417 }
418 return false;
419}
420
422 assert(R);
423 if (auto *TmplR = R->getTemplateInstantiationPattern())
424 return isRetainPtrOrOSPtr(safeGetName(TmplR));
425 return false;
426}
427
428bool isWeakPtr(const CXXRecordDecl *R) {
429 assert(R);
430 if (auto *TmplR = R->getTemplateInstantiationPattern())
431 return isWeakPtrClass(safeGetName(TmplR));
432 return false;
433}
434
435bool isSmartPtr(const CXXRecordDecl *R) {
436 assert(R);
437 if (auto *TmplR = R->getTemplateInstantiationPattern())
438 return isSmartPtrClass(safeGetName(TmplR));
439 return false;
440}
441
447
449 auto RetType = FD->getReturnType();
450 auto *Type = RetType.getTypePtrOrNull();
451 if (auto *MacroQualified = dyn_cast_or_null<MacroQualifiedType>(Type))
452 Type = MacroQualified->desugar().getTypePtrOrNull();
453 auto *Attr = dyn_cast_or_null<AttributedType>(Type);
454 if (!Attr)
456 auto *AnnotateType = dyn_cast_or_null<AnnotateTypeAttr>(Attr->getAttr());
457 if (!AnnotateType)
459 auto Annotation = AnnotateType->getAnnotation();
460 if (Annotation == "webkit.pointerconversion")
462 if (Annotation == "webkit.nodelete")
465}
466
468 assert(F);
469 if (isCtorOfRefCounted(F))
470 return true;
471
472 // FIXME: check # of params == 1
473 const auto FunctionName = safeGetName(F);
474 if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
475 FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
476 FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
477 FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
478 FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
479 FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||
480 FunctionName == "dynamic_objc_cast" ||
481 FunctionName == "checked_objc_cast")
482 return true;
483
485 return true;
486
487 return false;
488}
489
493
495 if (llvm::any_of(F->redecls(), isNoDeleteFunctionDecl))
496 return true;
497
498 const auto *MD = dyn_cast<CXXMethodDecl>(F);
499 if (!MD || !MD->isVirtual())
500 return false;
501
502 auto Overriders = llvm::to_vector(MD->overridden_methods());
503 while (!Overriders.empty()) {
504 const auto *Fn = Overriders.pop_back_val();
505 llvm::append_range(Overriders, Fn->overridden_methods());
507 return true;
508 }
509
510 return false;
511}
512
514 if (!F || !F->getDeclName().isIdentifier())
515 return false;
516 auto Name = F->getName();
517 return Name.starts_with("__builtin") || Name == "__libcpp_verbose_abort" ||
518 Name.starts_with("os_log") || Name.starts_with("_os_log");
519}
520
521bool isSingleton(const NamedDecl *F) {
522 assert(F);
523 // FIXME: check # of params == 1
524 if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(F)) {
525 if (!MethodDecl->isStatic())
526 return false;
527 }
528 const auto &NameStr = safeGetName(F);
529 StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
530 return Name == "singleton" || Name.ends_with("Singleton");
531}
532
533// We only care about statements so let's use the simple
534// (non-recursive) visitor.
536 : public ConstStmtVisitor<TrivialFunctionAnalysisVisitor, bool> {
537
538 // Returns false if at least one child is non-trivial.
539 bool VisitChildren(const Stmt *S) {
540 for (const Stmt *Child : S->children()) {
541 if (Child && !Visit(Child)) {
542 if (OffendingStmt && !*OffendingStmt)
543 *OffendingStmt = Child;
544 return false;
545 }
546 }
547
548 return true;
549 }
550
551 template <typename StmtOrDecl, typename CheckFunction>
552 bool WithCachedResult(const StmtOrDecl *S, CheckFunction Function) {
553 auto CacheIt = Cache.find(S);
554 if (CacheIt != Cache.end() && !OffendingStmt)
555 return CacheIt->second;
556
557 // Treat a recursive statement to be trivial until proven otherwise.
558 auto [RecursiveIt, IsNew] = RecursiveFn.insert(std::make_pair(S, true));
559 if (!IsNew)
560 return RecursiveIt->second;
561
562 bool Result = Function();
563
564 if (!Result) {
565 for (auto &It : RecursiveFn)
566 It.second = false;
567 }
568 RecursiveIt = RecursiveFn.find(S);
569 assert(RecursiveIt != RecursiveFn.end());
570 Result = RecursiveIt->second;
571 RecursiveFn.erase(RecursiveIt);
572 Cache[S] = Result;
573
574 return Result;
575 }
576
577 bool CanTriviallyDestruct(QualType Ty) {
578 if (Ty.isNull())
579 return false;
580
581 // T*, T& or T&& does not run its destructor.
582 if (Ty->isPointerOrReferenceType())
583 return true;
584
585 // FIXME: Handle a case when there is a local autorelease pool.
586 if (Ty->isObjCObjectPointerType()) {
587 auto Type = Ty.isDestructedType();
589 return true;
590 // strong lifetime in ARC could dealloc an object.
591 }
592
593 // Fundamental types (integral, nullptr_t, etc...) don't have destructors.
595 return true;
596
597 if (const auto *R = Ty->getAsCXXRecordDecl()) {
598 // C++ trivially destructible classes are fine.
599 if (R->hasDefinition() && R->hasTrivialDestructor())
600 return true;
601
602 if (HasFieldWithNonTrivialDtor(R))
603 return false;
604
605 // For Webkit, side-effects are fine as long as we don't delete objects,
606 // so check recursively.
607 if (const auto *Dtor = R->getDestructor())
608 return IsFunctionTrivial(Dtor);
609 }
610
611 // Structs in C are trivial.
612 if (Ty->isRecordType())
613 return true;
614
615 // For arrays it depends on the element type.
616 // FIXME: We should really use ASTContext::getAsArrayType instead.
617 if (const auto *AT = Ty->getAsArrayTypeUnsafe())
618 return CanTriviallyDestruct(AT->getElementType());
619
620 return false; // Otherwise it's likely not trivial.
621 }
622
623 bool HasFieldWithNonTrivialDtor(const CXXRecordDecl *Cls) {
624 auto CacheIt = FieldDtorCache.find(Cls);
625 if (CacheIt != FieldDtorCache.end())
626 return CacheIt->second;
627
628 bool Result = ([&] {
629 auto HasNonTrivialField = [&](const CXXRecordDecl *R) {
630 for (const FieldDecl *F : R->fields()) {
631 if (!CanTriviallyDestruct(F->getType()))
632 return true;
633 }
634 return false;
635 };
636
637 if (HasNonTrivialField(Cls))
638 return true;
639
640 if (!Cls->hasDefinition())
641 return false;
642
643 CXXBasePaths Paths;
644 Paths.setOrigin(const_cast<CXXRecordDecl *>(Cls));
645 return Cls->lookupInBases(
646 [&](const CXXBaseSpecifier *B, CXXBasePath &) {
647 auto *T = B->getType().getTypePtrOrNull();
648 if (!T)
649 return false;
650 auto *R = T->getAsCXXRecordDecl();
651 return R && HasNonTrivialField(R);
652 },
653 Paths, /*LookupInDependent =*/true);
654 })();
655
656 FieldDtorCache[Cls] = Result;
657
658 return Result;
659 }
660
661public:
662 using CacheTy = TrivialFunctionAnalysis::CacheTy;
663
665 const Stmt **OffendingStmt = nullptr)
666 : Cache(Cache), OffendingStmt(OffendingStmt) {}
667
668 bool IsFunctionTrivial(const Decl *D) {
669 const Stmt **SavedOffendingStmt = std::exchange(OffendingStmt, nullptr);
670 auto Result = WithCachedResult(D, [&]() {
671 auto *FnDecl = dyn_cast<FunctionDecl>(D);
672 auto *MethodDecl = dyn_cast<CXXMethodDecl>(D);
673 auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D);
674 auto *DtorDecl = dyn_cast<CXXDestructorDecl>(D);
675
676 if (FnDecl) {
677 if (isNoDeleteFunction(FnDecl))
678 return true;
679 if (MethodDecl && MethodDecl->isVirtual())
680 return false;
681 for (auto *Param : FnDecl->parameters()) {
682 if (!HasTrivialDestructor(Param))
683 return false;
684 }
685 }
686 if (CtorDecl) {
687 for (auto *CtorInit : CtorDecl->inits()) {
688 if (!Visit(CtorInit->getInit()))
689 return false;
690 }
691 }
692 // An implicit or =default special member runs no user code when it is
693 // trivial in the C++ standard sense, so it cannot delete. Such a
694 // member's synthesized body is typically absent from the AST until
695 // codegen materialises it, which the generic null-body check below
696 // would otherwise conservatively classify as non-trivial.
697 if (MethodDecl && !MethodDecl->isUserProvided()) {
698 if (CtorDecl) {
699 const CXXRecordDecl *RD = CtorDecl->getParent();
700 if ((CtorDecl->isDefaultConstructor() &&
702 (CtorDecl->isCopyConstructor() &&
704 (CtorDecl->isMoveConstructor() &&
706 return true;
707 }
708 if (DtorDecl && DtorDecl->getParent()->hasTrivialDestructor())
709 return true;
710 }
711 const Stmt *Body = D->getBody();
712 if (!Body)
713 return false;
714 return Visit(Body);
715 });
716 OffendingStmt = SavedOffendingStmt;
717 return Result;
718 }
719
721 return WithCachedResult(
722 VD, [&] { return CanTriviallyDestruct(VD->getType()); });
723 }
724
725 bool IsStatementTrivial(const Stmt *S) {
726 auto CacheIt = Cache.find(S);
727 if (CacheIt != Cache.end())
728 return CacheIt->second;
729 bool Result = Visit(S);
730 Cache[S] = Result;
731 return Result;
732 }
733
734 bool VisitStmt(const Stmt *S) {
735 // All statements are non-trivial unless overriden later.
736 // Don't even recurse into children by default.
737 return false;
738 }
739
741 // Ignore attributes.
742 return Visit(AS->getSubStmt());
743 }
744
746 // A compound statement is allowed as long each individual sub-statement
747 // is trivial.
748 return WithCachedResult(CS, [&]() { return VisitChildren(CS); });
749 }
750
752 return WithCachedResult(CBS, [&]() { return VisitChildren(CBS); });
753 }
754
755 bool VisitReturnStmt(const ReturnStmt *RS) {
756 // A return statement is allowed as long as the return value is trivial. A
757 // returned smart-pointer prvalue is special: under guaranteed copy elision
758 // the temporary *is* the function's return slot, so it is destructed by the
759 // caller, not here. Hence we may ignore that temporary's destructor.
760 if (auto *RV = RS->getRetValue())
762 return true;
763 }
764
765 bool VisitDeclStmt(const DeclStmt *DS) {
766 for (auto &Decl : DS->decls()) {
767 // FIXME: Handle DecompositionDecls.
768 if (auto *VD = dyn_cast<VarDecl>(Decl)) {
769 if (!HasTrivialDestructor(VD))
770 return false;
771 }
772 }
773 return VisitChildren(DS);
774 }
775 bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
776 bool VisitIfStmt(const IfStmt *IS) {
777 return WithCachedResult(IS, [&]() { return VisitChildren(IS); });
778 }
779 bool VisitForStmt(const ForStmt *FS) {
780 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
781 }
783 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
784 }
785 bool VisitWhileStmt(const WhileStmt *WS) {
786 return WithCachedResult(WS, [&]() { return VisitChildren(WS); });
787 }
788 bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
789 bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
790 bool VisitDefaultStmt(const DefaultStmt *DS) { return VisitChildren(DS); }
791
792 // break, continue, goto, and label statements are always trivial.
793 bool VisitBreakStmt(const BreakStmt *) { return true; }
794 bool VisitContinueStmt(const ContinueStmt *) { return true; }
795 bool VisitGotoStmt(const GotoStmt *) { return true; }
796 bool VisitLabelStmt(const LabelStmt *) { return true; }
797
799 // Unary operators are trivial if its operand is trivial except co_await.
800 return UO->getOpcode() != UO_Coawait && Visit(UO->getSubExpr());
801 }
802
804 // Binary operators are trivial if their operands are trivial.
805 return Visit(BO->getLHS()) && Visit(BO->getRHS());
806 }
807
809 // Compound assignment operator such as |= is trivial if its
810 // subexpresssions are trivial.
811 return VisitChildren(CAO);
812 }
813
815 return VisitChildren(ASE);
816 }
817
819 // Ternary operators are trivial if their conditions & values are trivial.
820 return VisitChildren(CO);
821 }
822
823 bool VisitAtomicExpr(const AtomicExpr *E) { return VisitChildren(E); }
824
826 // Any static_assert is considered trivial.
827 return true;
828 }
829
830 bool VisitCallExpr(const CallExpr *CE) {
831 if (!checkArguments(CE))
832 return false;
833
834 auto *Callee = CE->getDirectCallee();
835 if (!Callee)
836 return false;
837
838 if (isPtrConversion(Callee))
839 return true;
840
841 const auto &Name = safeGetName(Callee);
842
843 if (Callee->isInStdNamespace() &&
844 (Name == "addressof" || Name == "forward" || Name == "move"))
845 return true;
846
847 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
848 Name == "WTFReportBacktrace" ||
849 Name == "WTFCrashWithSecurityImplication" || Name == "WTFCrash" ||
850 Name == "WTFReportAssertionFailure" || Name == "isMainThread" ||
851 Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
852 Name == "isWebThread" || Name == "isUIThread" ||
853 Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
855 return true;
856
857 return IsFunctionTrivial(Callee);
858 }
859
860 bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
861 return AS->getAsmString() == "brk #0xc471";
862 }
863
864 bool
866 // Non-type template paramter is compile time constant and trivial.
867 return true;
868 }
869
871 return VisitChildren(E);
872 }
873
875 // A predefined identifier such as "func" is considered trivial.
876 return true;
877 }
878
880 // offsetof(T, D) is considered trivial.
881 return true;
882 }
883
885 if (!checkArguments(MCE))
886 return false;
887
888 bool TrivialThis = Visit(MCE->getImplicitObjectArgument());
889 if (!TrivialThis)
890 return false;
891
892 auto *Callee = MCE->getMethodDecl();
893 if (!Callee)
894 return false;
895
896 if (isa<CXXDestructorDecl>(Callee) &&
897 !CanTriviallyDestruct(MCE->getObjectType()))
898 return false;
899
900 auto Name = safeGetName(Callee);
901 if (Name == "ref" || Name == "incrementCheckedPtrCount")
902 return true;
903
904 std::optional<bool> IsGetterOfRefCounted = isGetterOfSafePtr(Callee);
905 if (IsGetterOfRefCounted && *IsGetterOfRefCounted)
906 return true;
907
908 // Recursively descend into the callee to confirm that it's trivial as well.
909 return IsFunctionTrivial(Callee);
910 }
911
913 if (!checkArguments(OCE))
914 return false;
915 auto *Callee = OCE->getCalleeDecl();
916 if (!Callee)
917 return false;
918 // Recursively descend into the callee to confirm that it's trivial as well.
919 return IsFunctionTrivial(Callee);
920 }
921
923 auto *SemanticExpr = Op->getSemanticForm();
924 return SemanticExpr && Visit(SemanticExpr);
925 }
926
928 if (auto *Expr = E->getExpr()) {
929 if (!Visit(Expr))
930 return false;
931 }
932 return true;
933 }
934
936 return Visit(E->getExpr());
937 }
938
939 bool checkArguments(const CallExpr *CE) {
940 for (const Expr *Arg : CE->arguments()) {
941 if (Arg && !Visit(Arg))
942 return false;
943 }
944 return true;
945 }
946
947 // Triviality check for a return value that may elide a smart-pointer
948 // temporary's destructor.
949 //
950 // This is only valid for *return values*: a returned class prvalue is
951 // constructed directly into the function's return slot (C++17 guaranteed copy
952 // elision), so the temporary is destructed by the caller rather than here.
953 //
954 // It is deliberately NOT applied to call/constructor arguments. An argument
955 // temporary's lifetime ends at the full-expression *in this function* (the
956 // caller destroys arguments, e.g. per the Itanium C++ ABI), so its destructor
957 // runs here and may invoke delete. Proving otherwise would require
958 // interprocedural ownership analysis, so arguments are checked normally.
960 QualType OriginalQT = Arg->getType();
961 auto *Type = OriginalQT.getTypePtrOrNull();
962 if (!Type)
963 return Visit(Arg);
964 auto *CXXRD = Type->getAsCXXRecordDecl();
965 if (!CXXRD || !isSmartPtrClass(safeGetName(CXXRD)))
966 return Visit(Arg);
967 Arg = Arg->IgnoreParenCasts();
968 if (!Arg->isPRValue())
969 return Visit(Arg);
970 if (auto *ExprWithClean = dyn_cast<ExprWithCleanups>(Arg))
971 Arg = ExprWithClean->getSubExpr()->IgnoreParenCasts();
972 if (auto *BTE = dyn_cast<CXXBindTemporaryExpr>(Arg)) {
973 // Only elide when the temporary *is* the returned object, i.e. it has the
974 // same smart-pointer type as the return value. Compare canonical,
975 // unqualified types rather than relying on exact QualType identity, which
976 // is sensitive to sugar (typedefs/aliases) and cv-qualifiers.
977 if (OriginalQT.getCanonicalType().getUnqualifiedType() ==
978 BTE->getType().getCanonicalType().getUnqualifiedType())
979 return Visit(BTE->getSubExpr());
980 }
981 return Visit(Arg);
982 }
983
985 for (const Expr *Arg : CE->arguments()) {
986 if (Arg && !Visit(Arg))
987 return false;
988 }
989
990 // Recursively descend into the callee to confirm that it's trivial.
991 return IsFunctionTrivial(CE->getConstructor());
992 }
993
997
998 bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
999
1001 return Visit(ICE->getSubExpr());
1002 }
1003
1005 return Visit(ECE->getSubExpr());
1006 }
1007
1009 return Visit(VMT->getSubExpr());
1010 }
1011
1013 if (auto *Temp = BTE->getTemporary()) {
1014 if (!IsFunctionTrivial(Temp->getDestructor()))
1015 return false;
1016 }
1017 return Visit(BTE->getSubExpr());
1018 }
1019
1021 return Visit(AILE->getCommonExpr()) && Visit(AILE->getSubExpr());
1022 }
1023
1025 return true; // The current array index in VisitArrayInitLoopExpr is always
1026 // trivial.
1027 }
1028
1030 return Visit(OVE->getSourceExpr());
1031 }
1032
1034 return Visit(EWC->getSubExpr());
1035 }
1036
1037 bool VisitParenExpr(const ParenExpr *PE) { return Visit(PE->getSubExpr()); }
1038
1040 for (const Expr *Child : ILE->inits()) {
1041 if (Child && !Visit(Child))
1042 return false;
1043 }
1044 return true;
1045 }
1046
1047 bool VisitMemberExpr(const MemberExpr *ME) {
1048 // Field access is allowed but the base pointer may itself be non-trivial.
1049 return Visit(ME->getBase());
1050 }
1051
1053 // The expression 'this' is always trivial, be it explicit or implicit.
1054 return true;
1055 }
1056
1058 // nullptr is trivial.
1059 return true;
1060 }
1061
1063 // The use of a variable is trivial.
1064 return true;
1065 }
1066
1067 // Constant literal expressions are always trivial
1068 bool VisitIntegerLiteral(const IntegerLiteral *E) { return true; }
1069 bool VisitFloatingLiteral(const FloatingLiteral *E) { return true; }
1070 bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
1071 bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
1072 bool VisitStringLiteral(const StringLiteral *E) { return true; }
1073 bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
1074
1076 // Constant expressions are trivial.
1077 return true;
1078 }
1079
1081 // An implicit value initialization is trvial.
1082 return true;
1083 }
1084
1085private:
1086 CacheTy &Cache;
1087 CacheTy FieldDtorCache;
1088 CacheTy RecursiveFn;
1089 const Stmt **OffendingStmt;
1090};
1091
1092bool TrivialFunctionAnalysis::isTrivialImpl(
1093 const Decl *D, TrivialFunctionAnalysis::CacheTy &Cache,
1094 const Stmt **OffendingStmt) {
1095 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1096 return V.IsFunctionTrivial(D);
1097}
1098
1099bool TrivialFunctionAnalysis::isTrivialImpl(
1100 const Stmt *S, TrivialFunctionAnalysis::CacheTy &Cache,
1101 const Stmt **OffendingStmt) {
1102 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1103 return V.IsStatementTrivial(S);
1104}
1105
1106bool TrivialFunctionAnalysis::hasTrivialDtorImpl(const VarDecl *VD,
1107 CacheTy &Cache) {
1109 return V.HasTrivialDestructor(VD);
1110}
1111
1112} // 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:4922
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:6033
Represents a loop initializing the elements of an array.
Definition Expr.h:5980
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5995
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:6000
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:6940
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2212
Stmt * getSubStmt()
Definition Stmt.h:2248
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:3144
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:1496
CXXTemporary * getTemporary()
Definition ExprCXX.h:1514
const Expr * getSubExpr() const
Definition ExprCXX.h:1518
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:726
Represents a call to a C++ constructor.
Definition ExprCXX.h:1551
arg_range arguments()
Definition ExprCXX.h:1675
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1614
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1273
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1380
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:136
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1754
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1791
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:182
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:2358
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:771
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:84
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:289
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition ExprCXX.h:307
Represents the this expression in C++.
Definition ExprCXX.h:1157
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:1929
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:1749
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:3128
Represents the body of a coroutine.
Definition StmtCXX.h:321
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
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:1640
decl_range decls()
Definition Stmt.h:1688
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
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:1104
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:556
bool isIdentifier() const
Predicate functions for querying what type of name this is.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2841
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:3660
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:3106
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:3204
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2897
const Expr * getSubExpr() const
Definition Expr.h:1068
Represents a function declaration or definition.
Definition Decl.h:2029
QualType getReturnType() const
Definition Decl.h:2885
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:3455
std::string getAsmString() const
Definition Stmt.cpp:574
GotoStmt - This represents a direct goto.
Definition Stmt.h:2978
IfStmt - This represents an if/then/else.
Definition Stmt.h:2268
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:6069
Describes an C or C++ initializer list.
Definition Expr.h:5314
ArrayRef< Expr * > inits() const
Definition Expr.h:5367
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2155
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4919
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4936
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:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8489
QualType getCanonicalType() const
Definition TypeBase.h:8541
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8583
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1561
const Type * getTypePtrOrNull() const
Definition TypeBase.h:8493
const TypedefDecl * getCanonicalDecl(QualType)
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:3169
Expr * getRetValue()
Definition Stmt.h:3196
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4157
Stmt - This represents one statement.
Definition Stmt.h:85
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:4663
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2518
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:1876
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition TypeBase.h:8689
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:9214
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9372
bool isPointerOrReferenceType() const
Definition TypeBase.h:8730
bool isObjCObjectPointerType() const
Definition TypeBase.h:8905
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2986
bool isRecordType() const
Definition TypeBase.h:8853
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3711
QualType getUnderlyingType() const
Definition Decl.h:3661
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:932
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2706
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:906
bool isOwnerPtr(const std::string &Name)
const FunctionProtoType * T
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:98
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:6026
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6016
std::optional< bool > isUncounted(const QualType T)
std::optional< bool > isUncheckedPtr(const QualType T)
bool isWeakPtr(const CXXRecordDecl *R)