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) || Name == "unique_ptr" ||
143 Name == "UniqueRef" || Name == "LazyUniqueRef";
144}
145
146bool isSmartPtrClass(const std::string &Name) {
147 return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) ||
148 Name == "WeakPtr" || Name == "WeakPtrFactory" ||
149 Name == "WeakPtrFactoryWithBitField" || Name == "WeakPtrImplBase" ||
150 Name == "WeakPtrImplBaseSingleThread" || Name == "ThreadSafeWeakPtr" ||
151 Name == "ThreadSafeWeakOrStrongPtr" ||
152 Name == "ThreadSafeWeakPtrControlBlock" ||
153 Name == "ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr";
154}
155
157 assert(F);
158 const std::string &FunctionName = safeGetName(F);
159
160 return isRefType(FunctionName) || FunctionName == "adoptRef" ||
161 FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
162 FunctionName == "makeUniqueRefWithoutFastMallocCheck"
163
164 || FunctionName == "String" || FunctionName == "AtomString" ||
165 FunctionName == "UniqueString"
166 // FIXME: Implement as attribute.
167 || FunctionName == "Identifier";
168}
169
171 assert(F);
172 return isCheckedPtr(safeGetName(F));
173}
174
176 const std::string &FunctionName = safeGetName(F);
177 return FunctionName == "RetainPtr" || FunctionName == "adoptNS" ||
178 FunctionName == "adoptNSNullable" || FunctionName == "adoptCF" ||
179 FunctionName == "adoptCFNullable" || FunctionName == "retainPtr" ||
180 FunctionName == "RetainPtrArc" || FunctionName == "adoptNSArc" ||
181 FunctionName == "adoptOSObject" || FunctionName == "adoptOSObjectArc";
182}
183
188
190 auto FnName = safeGetName(F);
191 auto *Namespace = F->getParent();
192 if (!Namespace)
193 return false;
194 auto *TUDeck = Namespace->getParent();
195 if (!isa_and_nonnull<TranslationUnitDecl>(TUDeck))
196 return false;
197 auto NsName = safeGetName(Namespace);
198 return (NsName == "WTF" || NsName == "std") && FnName == "move";
199}
200
201template <typename Predicate>
202static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
203 QualType type = T;
204 while (!type.isNull()) {
205 if (auto *SpecialT = type->getAs<TemplateSpecializationType>()) {
206 auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
207 return Decl && Pred(Decl->getNameAsString());
208 } else if (auto *DTS = type->getAs<DeducedTemplateSpecializationType>()) {
209 auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
210 return Decl && Pred(Decl->getNameAsString());
211 } else
212 break;
213 }
214 return false;
215}
216
218 return isPtrOfType(
219 T, [](auto Name) { return isRefType(Name) || isCheckedPtr(Name); });
220}
221
223 return isPtrOfType(T, [](auto Name) { return isRetainPtrOrOSPtr(Name); });
224}
225
227 return isPtrOfType(T, [](auto Name) { return isOwnerPtr(Name); });
228}
229
230std::optional<bool> isUncounted(const QualType T) {
231 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
232 if (auto *Decl = Subst->getAssociatedDecl()) {
234 return false;
235 }
236 }
237 return isUncounted(T->getAsCXXRecordDecl());
238}
239
240std::optional<bool> isUnchecked(const QualType T) {
241 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
242 if (auto *Decl = Subst->getAssociatedDecl()) {
244 return false;
245 }
246 }
247 return isUnchecked(T->getAsCXXRecordDecl());
248}
249
251 const TranslationUnitDecl *TUD) {
252 IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount;
253 DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties;
254}
255
257 auto QT = TD->getUnderlyingType();
258 if (!QT->isPointerType())
259 return;
260
261 auto PointeeQT = QT->getPointeeType();
262 const RecordType *RT = PointeeQT->getAsCanonical<RecordType>();
263 if (!RT) {
264 if (TD->hasAttr<ObjCBridgeAttr>() || TD->hasAttr<ObjCBridgeMutableAttr>()) {
265 RecordlessTypes.insert(TD->getASTContext()
267 /*Qualifier=*/std::nullopt, TD)
268 .getTypePtr());
269 }
270 return;
271 }
272
273 for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
274 if (Redecl->getAttr<ObjCBridgeAttr>() ||
275 Redecl->getAttr<ObjCBridgeMutableAttr>()) {
276 CFPointees.insert(RT);
277 return;
278 }
279 }
280}
281
282bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
283 if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
284 return true;
285 if (auto *RT = dyn_cast_or_null<RecordType>(
287 return CFPointees.contains(RT);
288 return RecordlessTypes.contains(QT.getTypePtr());
289}
290
291std::optional<bool> isUncounted(const CXXRecordDecl* Class)
292{
293 // Keep isRefCounted first as it's cheaper.
294 if (!Class || isRefCounted(Class))
295 return false;
296
297 std::optional<bool> IsRefCountable = isRefCountable(Class);
298 if (!IsRefCountable)
299 return std::nullopt;
300
301 return (*IsRefCountable);
302}
303
304std::optional<bool> isUnchecked(const CXXRecordDecl *Class) {
305 if (!Class || isCheckedPtr(Class))
306 return false; // Cheaper than below
308}
309
310std::optional<bool> isUncountedPtr(const QualType T) {
311 if (T->isPointerType() || T->isReferenceType()) {
312 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
313 return isUncounted(CXXRD);
314 }
315 return false;
316}
317
318std::optional<bool> isUncheckedPtr(const QualType T) {
319 if (T->isPointerType() || T->isReferenceType()) {
320 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
321 return isUnchecked(CXXRD);
322 }
323 return false;
324}
325
326std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
327 assert(M);
328
329 if (isa<CXXMethodDecl>(M)) {
330 const CXXRecordDecl *calleeMethodsClass = M->getParent();
331 auto className = safeGetName(calleeMethodsClass);
332 auto method = safeGetName(M);
333
334 if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
335 return true;
336
337 if ((isRefType(className) && (method == "get" || method == "ptr")) ||
338 ((className == "String" || className == "AtomString" ||
339 className == "AtomStringImpl" || className == "UniqueString" ||
340 className == "UniqueStringImpl" || className == "Identifier") &&
341 method == "impl"))
342 return true;
343
344 if (isRetainPtrOrOSPtr(className) && method == "get")
345 return true;
346
347 // Ref<T> -> T conversion
348 // FIXME: Currently allowing any Ref<T> -> whatever cast.
349 if (isRefType(className)) {
350 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
351 auto QT = maybeRefToRawOperator->getConversionType();
352 auto *T = QT.getTypePtrOrNull();
353 return T && (T->isPointerType() || T->isReferenceType());
354 }
355 }
356
357 if (isCheckedPtr(className)) {
358 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
359 auto QT = maybeRefToRawOperator->getConversionType();
360 auto *T = QT.getTypePtrOrNull();
361 return T && (T->isPointerType() || T->isReferenceType());
362 }
363 }
364
365 if (isRetainPtrOrOSPtr(className)) {
366 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
367 auto QT = maybeRefToRawOperator->getConversionType();
368 auto *T = QT.getTypePtrOrNull();
369 return T && (T->isPointerType() || T->isReferenceType() ||
370 T->isObjCObjectPointerType());
371 }
372 }
373 }
374 return false;
375}
376
378 assert(R);
379 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
380 // FIXME: String/AtomString/UniqueString
381 const auto &ClassName = safeGetName(TmplR);
382 return isRefType(ClassName);
383 }
384 return false;
385}
386
388 assert(R);
389 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
390 const auto &ClassName = safeGetName(TmplR);
391 return isCheckedPtr(ClassName);
392 }
393 return false;
394}
395
397 assert(R);
398 if (auto *TmplR = R->getTemplateInstantiationPattern())
399 return isRetainPtrOrOSPtr(safeGetName(TmplR));
400 return false;
401}
402
403bool isSmartPtr(const CXXRecordDecl *R) {
404 assert(R);
405 if (auto *TmplR = R->getTemplateInstantiationPattern())
406 return isSmartPtrClass(safeGetName(TmplR));
407 return false;
408}
409
415
417 auto RetType = FD->getReturnType();
418 auto *Type = RetType.getTypePtrOrNull();
419 if (auto *MacroQualified = dyn_cast_or_null<MacroQualifiedType>(Type))
420 Type = MacroQualified->desugar().getTypePtrOrNull();
421 auto *Attr = dyn_cast_or_null<AttributedType>(Type);
422 if (!Attr)
424 auto *AnnotateType = dyn_cast_or_null<AnnotateTypeAttr>(Attr->getAttr());
425 if (!AnnotateType)
427 auto Annotation = AnnotateType->getAnnotation();
428 if (Annotation == "webkit.pointerconversion")
430 if (Annotation == "webkit.nodelete")
433}
434
436 assert(F);
437 if (isCtorOfRefCounted(F))
438 return true;
439
440 // FIXME: check # of params == 1
441 const auto FunctionName = safeGetName(F);
442 if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
443 FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
444 FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
445 FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
446 FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
447 FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||
448 FunctionName == "dynamic_objc_cast" ||
449 FunctionName == "checked_objc_cast")
450 return true;
451
453 return true;
454
455 return false;
456}
457
461
463 if (llvm::any_of(F->redecls(), isNoDeleteFunctionDecl))
464 return true;
465
466 const auto *MD = dyn_cast<CXXMethodDecl>(F);
467 if (!MD || !MD->isVirtual())
468 return false;
469
470 auto Overriders = llvm::to_vector(MD->overridden_methods());
471 while (!Overriders.empty()) {
472 const auto *Fn = Overriders.pop_back_val();
473 llvm::append_range(Overriders, Fn->overridden_methods());
475 return true;
476 }
477
478 return false;
479}
480
482 if (!F || !F->getDeclName().isIdentifier())
483 return false;
484 auto Name = F->getName();
485 return Name.starts_with("__builtin") || Name == "__libcpp_verbose_abort" ||
486 Name.starts_with("os_log") || Name.starts_with("_os_log");
487}
488
489bool isSingleton(const NamedDecl *F) {
490 assert(F);
491 // FIXME: check # of params == 1
492 if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(F)) {
493 if (!MethodDecl->isStatic())
494 return false;
495 }
496 const auto &NameStr = safeGetName(F);
497 StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
498 return Name == "singleton" || Name.ends_with("Singleton");
499}
500
501// We only care about statements so let's use the simple
502// (non-recursive) visitor.
504 : public ConstStmtVisitor<TrivialFunctionAnalysisVisitor, bool> {
505
506 // Returns false if at least one child is non-trivial.
507 bool VisitChildren(const Stmt *S) {
508 for (const Stmt *Child : S->children()) {
509 if (Child && !Visit(Child)) {
510 if (OffendingStmt && !*OffendingStmt)
511 *OffendingStmt = Child;
512 return false;
513 }
514 }
515
516 return true;
517 }
518
519 template <typename StmtOrDecl, typename CheckFunction>
520 bool WithCachedResult(const StmtOrDecl *S, CheckFunction Function) {
521 auto CacheIt = Cache.find(S);
522 if (CacheIt != Cache.end() && !OffendingStmt)
523 return CacheIt->second;
524
525 // Treat a recursive statement to be trivial until proven otherwise.
526 auto [RecursiveIt, IsNew] = RecursiveFn.insert(std::make_pair(S, true));
527 if (!IsNew)
528 return RecursiveIt->second;
529
530 bool Result = Function();
531
532 if (!Result) {
533 for (auto &It : RecursiveFn)
534 It.second = false;
535 }
536 RecursiveIt = RecursiveFn.find(S);
537 assert(RecursiveIt != RecursiveFn.end());
538 Result = RecursiveIt->second;
539 RecursiveFn.erase(RecursiveIt);
540 Cache[S] = Result;
541
542 return Result;
543 }
544
545 bool CanTriviallyDestruct(QualType Ty) {
546 if (Ty.isNull())
547 return false;
548
549 // T*, T& or T&& does not run its destructor.
550 if (Ty->isPointerOrReferenceType())
551 return true;
552
553 // Fundamental types (integral, nullptr_t, etc...) don't have destructors.
555 return true;
556
557 if (const auto *R = Ty->getAsCXXRecordDecl()) {
558 // C++ trivially destructible classes are fine.
559 if (R->hasDefinition() && R->hasTrivialDestructor())
560 return true;
561
562 if (HasFieldWithNonTrivialDtor(R))
563 return false;
564
565 // For Webkit, side-effects are fine as long as we don't delete objects,
566 // so check recursively.
567 if (const auto *Dtor = R->getDestructor())
568 return IsFunctionTrivial(Dtor);
569 }
570
571 // Structs in C are trivial.
572 if (Ty->isRecordType())
573 return true;
574
575 // For arrays it depends on the element type.
576 // FIXME: We should really use ASTContext::getAsArrayType instead.
577 if (const auto *AT = Ty->getAsArrayTypeUnsafe())
578 return CanTriviallyDestruct(AT->getElementType());
579
580 return false; // Otherwise it's likely not trivial.
581 }
582
583 bool HasFieldWithNonTrivialDtor(const CXXRecordDecl *Cls) {
584 auto CacheIt = FieldDtorCache.find(Cls);
585 if (CacheIt != FieldDtorCache.end())
586 return CacheIt->second;
587
588 bool Result = ([&] {
589 auto HasNonTrivialField = [&](const CXXRecordDecl *R) {
590 for (const FieldDecl *F : R->fields()) {
591 if (!CanTriviallyDestruct(F->getType()))
592 return true;
593 }
594 return false;
595 };
596
597 if (HasNonTrivialField(Cls))
598 return true;
599
600 if (!Cls->hasDefinition())
601 return false;
602
603 CXXBasePaths Paths;
604 Paths.setOrigin(const_cast<CXXRecordDecl *>(Cls));
605 return Cls->lookupInBases(
606 [&](const CXXBaseSpecifier *B, CXXBasePath &) {
607 auto *T = B->getType().getTypePtrOrNull();
608 if (!T)
609 return false;
610 auto *R = T->getAsCXXRecordDecl();
611 return R && HasNonTrivialField(R);
612 },
613 Paths, /*LookupInDependent =*/true);
614 })();
615
616 FieldDtorCache[Cls] = Result;
617
618 return Result;
619 }
620
621public:
622 using CacheTy = TrivialFunctionAnalysis::CacheTy;
623
625 const Stmt **OffendingStmt = nullptr)
626 : Cache(Cache), OffendingStmt(OffendingStmt) {}
627
628 bool IsFunctionTrivial(const Decl *D) {
629 const Stmt **SavedOffendingStmt = std::exchange(OffendingStmt, nullptr);
630 auto Result = WithCachedResult(D, [&]() {
631 if (auto *FnDecl = dyn_cast<FunctionDecl>(D)) {
632 if (isNoDeleteFunction(FnDecl))
633 return true;
634 if (auto *MD = dyn_cast<CXXMethodDecl>(D); MD && MD->isVirtual())
635 return false;
636 for (auto *Param : FnDecl->parameters()) {
637 if (!HasTrivialDestructor(Param))
638 return false;
639 }
640 }
641 if (auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D)) {
642 for (auto *CtorInit : CtorDecl->inits()) {
643 if (!Visit(CtorInit->getInit()))
644 return false;
645 }
646 }
647 const Stmt *Body = D->getBody();
648 if (!Body)
649 return false;
650 return Visit(Body);
651 });
652 OffendingStmt = SavedOffendingStmt;
653 return Result;
654 }
655
657 return WithCachedResult(
658 VD, [&] { return CanTriviallyDestruct(VD->getType()); });
659 }
660
661 bool IsStatementTrivial(const Stmt *S) {
662 auto CacheIt = Cache.find(S);
663 if (CacheIt != Cache.end())
664 return CacheIt->second;
665 bool Result = Visit(S);
666 Cache[S] = Result;
667 return Result;
668 }
669
670 bool VisitStmt(const Stmt *S) {
671 // All statements are non-trivial unless overriden later.
672 // Don't even recurse into children by default.
673 return false;
674 }
675
677 // Ignore attributes.
678 return Visit(AS->getSubStmt());
679 }
680
682 // A compound statement is allowed as long each individual sub-statement
683 // is trivial.
684 return WithCachedResult(CS, [&]() { return VisitChildren(CS); });
685 }
686
688 return WithCachedResult(CBS, [&]() { return VisitChildren(CBS); });
689 }
690
691 bool VisitReturnStmt(const ReturnStmt *RS) {
692 // A return statement is allowed as long as the return value is trivial.
693 if (auto *RV = RS->getRetValue())
694 return Visit(RV);
695 return true;
696 }
697
698 bool VisitDeclStmt(const DeclStmt *DS) {
699 for (auto &Decl : DS->decls()) {
700 // FIXME: Handle DecompositionDecls.
701 if (auto *VD = dyn_cast<VarDecl>(Decl)) {
702 if (!HasTrivialDestructor(VD))
703 return false;
704 }
705 }
706 return VisitChildren(DS);
707 }
708 bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
709 bool VisitIfStmt(const IfStmt *IS) {
710 return WithCachedResult(IS, [&]() { return VisitChildren(IS); });
711 }
712 bool VisitForStmt(const ForStmt *FS) {
713 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
714 }
716 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
717 }
718 bool VisitWhileStmt(const WhileStmt *WS) {
719 return WithCachedResult(WS, [&]() { return VisitChildren(WS); });
720 }
721 bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
722 bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
723 bool VisitDefaultStmt(const DefaultStmt *DS) { return VisitChildren(DS); }
724
725 // break, continue, goto, and label statements are always trivial.
726 bool VisitBreakStmt(const BreakStmt *) { return true; }
727 bool VisitContinueStmt(const ContinueStmt *) { return true; }
728 bool VisitGotoStmt(const GotoStmt *) { return true; }
729 bool VisitLabelStmt(const LabelStmt *) { return true; }
730
732 // Unary operators are trivial if its operand is trivial except co_await.
733 return UO->getOpcode() != UO_Coawait && Visit(UO->getSubExpr());
734 }
735
737 // Binary operators are trivial if their operands are trivial.
738 return Visit(BO->getLHS()) && Visit(BO->getRHS());
739 }
740
742 // Compound assignment operator such as |= is trivial if its
743 // subexpresssions are trivial.
744 return VisitChildren(CAO);
745 }
746
748 return VisitChildren(ASE);
749 }
750
752 // Ternary operators are trivial if their conditions & values are trivial.
753 return VisitChildren(CO);
754 }
755
756 bool VisitAtomicExpr(const AtomicExpr *E) { return VisitChildren(E); }
757
759 // Any static_assert is considered trivial.
760 return true;
761 }
762
763 bool VisitCallExpr(const CallExpr *CE) {
764 if (!checkArguments(CE))
765 return false;
766
767 auto *Callee = CE->getDirectCallee();
768 if (!Callee)
769 return false;
770
771 if (isPtrConversion(Callee))
772 return true;
773
774 const auto &Name = safeGetName(Callee);
775
776 if (Callee->isInStdNamespace() &&
777 (Name == "addressof" || Name == "forward" || Name == "move"))
778 return true;
779
780 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
781 Name == "WTFReportBacktrace" ||
782 Name == "WTFCrashWithSecurityImplication" || Name == "WTFCrash" ||
783 Name == "WTFReportAssertionFailure" || Name == "isMainThread" ||
784 Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
785 Name == "isWebThread" || Name == "isUIThread" ||
786 Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
788 return true;
789
790 return IsFunctionTrivial(Callee);
791 }
792
793 bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
794 return AS->getAsmString() == "brk #0xc471";
795 }
796
797 bool
799 // Non-type template paramter is compile time constant and trivial.
800 return true;
801 }
802
804 return VisitChildren(E);
805 }
806
808 // A predefined identifier such as "func" is considered trivial.
809 return true;
810 }
811
813 // offsetof(T, D) is considered trivial.
814 return true;
815 }
816
818 if (!checkArguments(MCE))
819 return false;
820
821 bool TrivialThis = Visit(MCE->getImplicitObjectArgument());
822 if (!TrivialThis)
823 return false;
824
825 auto *Callee = MCE->getMethodDecl();
826 if (!Callee)
827 return false;
828
829 if (isa<CXXDestructorDecl>(Callee) &&
830 !CanTriviallyDestruct(MCE->getObjectType()))
831 return false;
832
833 auto Name = safeGetName(Callee);
834 if (Name == "ref" || Name == "incrementCheckedPtrCount")
835 return true;
836
837 std::optional<bool> IsGetterOfRefCounted = isGetterOfSafePtr(Callee);
838 if (IsGetterOfRefCounted && *IsGetterOfRefCounted)
839 return true;
840
841 // Recursively descend into the callee to confirm that it's trivial as well.
842 return IsFunctionTrivial(Callee);
843 }
844
846 if (!checkArguments(OCE))
847 return false;
848 auto *Callee = OCE->getCalleeDecl();
849 if (!Callee)
850 return false;
851 // Recursively descend into the callee to confirm that it's trivial as well.
852 return IsFunctionTrivial(Callee);
853 }
854
856 auto *SemanticExpr = Op->getSemanticForm();
857 return SemanticExpr && Visit(SemanticExpr);
858 }
859
861 if (auto *Expr = E->getExpr()) {
862 if (!Visit(Expr))
863 return false;
864 }
865 return true;
866 }
867
869 return Visit(E->getExpr());
870 }
871
872 bool checkArguments(const CallExpr *CE) {
873 for (const Expr *Arg : CE->arguments()) {
874 if (Arg && !Visit(Arg))
875 return false;
876 }
877 return true;
878 }
879
881 for (const Expr *Arg : CE->arguments()) {
882 if (Arg && !Visit(Arg))
883 return false;
884 }
885
886 // Recursively descend into the callee to confirm that it's trivial.
887 return IsFunctionTrivial(CE->getConstructor());
888 }
889
893
894 bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
895
897 return Visit(ICE->getSubExpr());
898 }
899
901 return Visit(ECE->getSubExpr());
902 }
903
905 return Visit(VMT->getSubExpr());
906 }
907
909 if (auto *Temp = BTE->getTemporary()) {
910 if (!IsFunctionTrivial(Temp->getDestructor()))
911 return false;
912 }
913 return Visit(BTE->getSubExpr());
914 }
915
917 return Visit(AILE->getCommonExpr()) && Visit(AILE->getSubExpr());
918 }
919
921 return true; // The current array index in VisitArrayInitLoopExpr is always
922 // trivial.
923 }
924
926 return Visit(OVE->getSourceExpr());
927 }
928
930 return Visit(EWC->getSubExpr());
931 }
932
933 bool VisitParenExpr(const ParenExpr *PE) { return Visit(PE->getSubExpr()); }
934
936 for (const Expr *Child : ILE->inits()) {
937 if (Child && !Visit(Child))
938 return false;
939 }
940 return true;
941 }
942
943 bool VisitMemberExpr(const MemberExpr *ME) {
944 // Field access is allowed but the base pointer may itself be non-trivial.
945 return Visit(ME->getBase());
946 }
947
948 bool VisitCXXThisExpr(const CXXThisExpr *CTE) {
949 // The expression 'this' is always trivial, be it explicit or implicit.
950 return true;
951 }
952
954 // nullptr is trivial.
955 return true;
956 }
957
958 bool VisitDeclRefExpr(const DeclRefExpr *DRE) {
959 // The use of a variable is trivial.
960 return true;
961 }
962
963 // Constant literal expressions are always trivial
964 bool VisitIntegerLiteral(const IntegerLiteral *E) { return true; }
965 bool VisitFloatingLiteral(const FloatingLiteral *E) { return true; }
966 bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
967 bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
968 bool VisitStringLiteral(const StringLiteral *E) { return true; }
969 bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
970
972 // Constant expressions are trivial.
973 return true;
974 }
975
977 // An implicit value initialization is trvial.
978 return true;
979 }
980
981private:
982 CacheTy &Cache;
983 CacheTy FieldDtorCache;
984 CacheTy RecursiveFn;
985 const Stmt **OffendingStmt;
986};
987
988bool TrivialFunctionAnalysis::isTrivialImpl(
989 const Decl *D, TrivialFunctionAnalysis::CacheTy &Cache,
990 const Stmt **OffendingStmt) {
991 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
992 return V.IsFunctionTrivial(D);
993}
994
995bool TrivialFunctionAnalysis::isTrivialImpl(
996 const Stmt *S, TrivialFunctionAnalysis::CacheTy &Cache,
997 const Stmt **OffendingStmt) {
998 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
999 return V.IsStatementTrivial(S);
1000}
1001
1002bool TrivialFunctionAnalysis::hasTrivialDtorImpl(const VarDecl *VD,
1003 CacheTy &Cache) {
1005 return V.HasTrivialDestructor(VD);
1006}
1007
1008} // 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:4913
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:6022
Represents a loop initializing the elements of an array.
Definition Expr.h:5969
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5984
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5989
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2724
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6929
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2209
Stmt * getSubStmt()
Definition Stmt.h:2245
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
Expr * getLHS() const
Definition Expr.h:4091
Expr * getRHS() const
Definition Expr.h:4093
BreakStmt - This represents a break.
Definition Stmt.h:3141
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:1107
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:743
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition ExprCXX.cpp:724
QualType getObjectType() const
Retrieve the type of the object argument.
Definition ExprCXX.cpp:736
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2132
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2271
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 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:2946
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3129
arg_range arguments()
Definition Expr.h:3198
Decl * getCalleeDecl()
Definition Expr.h:3123
CaseStmt - Represent a case statement.
Definition Stmt.h:1926
Expr * getSubExpr()
Definition Expr.h:3729
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4303
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1746
ConditionalOperator - The ?
Definition Expr.h:4394
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:1085
ContinueStmt - This represents a continue.
Definition Stmt.h:3125
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:1273
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1637
decl_range decls()
Definition Stmt.h:1685
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:2838
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h:3931
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
Represents a member of a struct/union/class.
Definition Decl.h:3178
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2894
const Expr * getSubExpr() const
Definition Expr.h:1065
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:3452
std::string getAsmString() const
Definition Stmt.cpp:574
GotoStmt - This represents a direct goto.
Definition Stmt.h:2975
IfStmt - This represents an if/then/else.
Definition Stmt.h:2265
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3856
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6058
Describes an C or C++ initializer list.
Definition Expr.h:5302
ArrayRef< Expr * > inits() const
Definition Expr.h:5352
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2152
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:3367
Expr * getBase() const
Definition Expr.h:3444
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:2530
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1181
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1231
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2185
const Expr * getSubExpr() const
Definition Expr.h:2202
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2008
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:8436
QualType getCanonicalType() const
Definition TypeBase.h:8488
const Type * getTypePtrOrNull() const
Definition TypeBase.h:8440
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:3166
Expr * getRetValue()
Definition Stmt.h:3193
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4141
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:1802
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:2515
The top declaration context.
Definition Decl.h:105
bool VisitMemberExpr(const MemberExpr *ME)
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:1871
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition TypeBase.h:8636
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:9161
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9319
bool isPointerOrReferenceType() const
Definition TypeBase.h:8677
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2976
bool isRecordType() const
Definition TypeBase.h:8800
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3685
QualType getUnderlyingType() const
Definition Decl.h:3635
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2628
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2247
Expr * getSubExpr() const
Definition Expr.h:2288
Opcode getOpcode() const
Definition Expr.h:2283
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:2703
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)
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)
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:180
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5982
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5972
std::optional< bool > isUncounted(const QualType T)
std::optional< bool > isUncheckedPtr(const QualType T)