clang 23.0.0git
PtrTypesSemantics.cpp
Go to the documentation of this file.
1//=======- PtrTypesSemantics.cpp ---------------------------------*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "PtrTypesSemantics.h"
10#include "ASTUtils.h"
11#include "clang/AST/Attr.h"
13#include "clang/AST/Decl.h"
14#include "clang/AST/DeclCXX.h"
15#include "clang/AST/ExprCXX.h"
18#include <optional>
19
20using namespace clang;
21
22namespace {
23
24bool hasPublicMethodInBaseClass(const CXXRecordDecl *R, StringRef NameToMatch) {
25 assert(R);
26 assert(R->hasDefinition());
27
28 for (const CXXMethodDecl *MD : R->methods()) {
29 const auto MethodName = safeGetName(MD);
30 if (MethodName == NameToMatch && MD->getAccess() == AS_public)
31 return true;
32 }
33 return false;
34}
35
36} // namespace
37
38namespace clang {
39
40std::optional<const clang::CXXRecordDecl *>
41hasPublicMethodInBase(const CXXBaseSpecifier *Base, StringRef NameToMatch) {
42 assert(Base);
43
44 const Type *T = Base->getType().getTypePtrOrNull();
45 if (!T)
46 return std::nullopt;
47
48 const CXXRecordDecl *R = T->getAsCXXRecordDecl();
49 if (!R) {
50 auto CT = Base->getType().getCanonicalType();
51 if (auto *TST = dyn_cast<TemplateSpecializationType>(CT)) {
52 auto TmplName = TST->getTemplateName();
53 if (!TmplName.isNull()) {
54 if (auto *TD = TmplName.getAsTemplateDecl())
55 R = dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl());
56 }
57 }
58 if (!R)
59 return std::nullopt;
60 }
61 if (!R->hasDefinition())
62 return std::nullopt;
63
64 return hasPublicMethodInBaseClass(R, NameToMatch) ? R : nullptr;
65}
66
67std::optional<bool> isSmartPtrCompatible(const CXXRecordDecl *R,
68 StringRef IncMethodName,
69 StringRef DecMethodName) {
70 assert(R);
71
72 R = R->getDefinition();
73 if (!R)
74 return std::nullopt;
75
76 bool hasRef = hasPublicMethodInBaseClass(R, IncMethodName);
77 bool hasDeref = hasPublicMethodInBaseClass(R, DecMethodName);
78 if (hasRef && hasDeref)
79 return true;
80
81 CXXBasePaths Paths;
82 Paths.setOrigin(const_cast<CXXRecordDecl *>(R));
83
84 bool AnyInconclusiveBase = false;
85 const auto hasPublicRefInBase = [&](const CXXBaseSpecifier *Base,
86 CXXBasePath &) {
87 auto hasRefInBase = clang::hasPublicMethodInBase(Base, IncMethodName);
88 if (!hasRefInBase) {
89 AnyInconclusiveBase = true;
90 return false;
91 }
92 return (*hasRefInBase) != nullptr;
93 };
94
95 hasRef = hasRef || R->lookupInBases(hasPublicRefInBase, Paths,
96 /*LookupInDependent =*/true);
97 if (AnyInconclusiveBase)
98 return std::nullopt;
99
100 Paths.clear();
101 const auto hasPublicDerefInBase = [&](const CXXBaseSpecifier *Base,
102 CXXBasePath &) {
103 auto hasDerefInBase = clang::hasPublicMethodInBase(Base, DecMethodName);
104 if (!hasDerefInBase) {
105 AnyInconclusiveBase = true;
106 return false;
107 }
108 return (*hasDerefInBase) != nullptr;
109 };
110 hasDeref = hasDeref || R->lookupInBases(hasPublicDerefInBase, Paths,
111 /*LookupInDependent =*/true);
112 if (AnyInconclusiveBase)
113 return std::nullopt;
114
115 return hasRef && hasDeref;
116}
117
118std::optional<bool> isRefCountable(const clang::CXXRecordDecl *R) {
119 return isSmartPtrCompatible(R, "ref", "deref");
120}
121
122std::optional<bool> isCheckedPtrCapable(const clang::CXXRecordDecl *R) {
123 return isSmartPtrCompatible(R, "incrementCheckedPtrCount",
124 "decrementCheckedPtrCount");
125}
126
127bool isRefType(const std::string &Name) {
128 return Name == "Ref" || Name == "RefAllowingPartiallyDestroyed" ||
129 Name == "RefPtr" || Name == "RefPtrAllowingPartiallyDestroyed";
130}
131
132bool isRetainPtrOrOSPtr(const std::string &Name) {
133 return Name == "RetainPtr" || Name == "RetainPtrArc" ||
134 Name == "OSObjectPtr" || Name == "OSObjectPtrArc";
135}
136
137bool isCheckedPtr(const std::string &Name) {
138 return Name == "CheckedPtr" || Name == "CheckedRef";
139}
140
141bool isOwnerPtr(const std::string &Name) {
142 return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) ||
143 Name == "unique_ptr" || Name == "UniqueRef" || Name == "LazyUniqueRef";
144}
145
146static bool isWeakPtrClass(const std::string &Name) {
147 return Name == "WeakPtr" || Name == "SingleThreadPackedWeakPtr" ||
148 Name == "SingleThreadWeakPtr" || Name == "ThreadSafeWeakPtr" ||
149 Name == "ThreadSafeWeakOrStrongPtr" || Name == "InlineWeakPtr";
150}
151
152bool isSmartPtrClass(const std::string &Name) {
153 return isRefType(Name) || isCheckedPtr(Name) || isRetainPtrOrOSPtr(Name) ||
154 isWeakPtrClass(Name) || Name == "WeakPtrFactory" ||
155 Name == "WeakPtrFactoryWithBitField" || Name == "WeakPtrImplBase" ||
156 Name == "WeakPtrImplBaseSingleThread" ||
157 Name == "ThreadSafeWeakOrStrongPtr" ||
158 Name == "ThreadSafeWeakPtrControlBlock" ||
159 Name == "ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr";
160}
161
163 if (auto *Ctor = dyn_cast_or_null<CXXConstructorDecl>(F))
164 return safeGetName(Ctor->getParent());
165 return safeGetName(F);
166}
167
169 assert(F);
170 auto FunctionName = getConstructorName(F);
171 return isRefType(FunctionName) || FunctionName == "adoptRef" ||
172 FunctionName == "UniqueRef" || FunctionName == "makeUniqueRef" ||
173 FunctionName == "makeUniqueRefWithoutFastMallocCheck"
174
175 || FunctionName == "String" || FunctionName == "AtomString" ||
176 FunctionName == "UniqueString"
177 // FIXME: Implement as attribute.
178 || FunctionName == "Identifier";
179}
180
182 assert(F);
184}
185
187 auto FunctionName = getConstructorName(F);
188 return isRetainPtrOrOSPtr(FunctionName) || FunctionName == "adoptNS" ||
189 FunctionName == "adoptNSNullable" || FunctionName == "adoptCF" ||
190 FunctionName == "adoptCFNullable" || FunctionName == "retainPtr" ||
191 FunctionName == "adoptNSArc" || FunctionName == "adoptOSObject" ||
192 FunctionName == "adoptOSObjectArc";
193}
194
199
201 auto FnName = safeGetName(F);
202 auto *Namespace = F->getParent();
203 if (!Namespace)
204 return false;
205 auto *TUDeck = Namespace->getParent();
206 if (!isa_and_nonnull<TranslationUnitDecl>(TUDeck))
207 return false;
208 auto NsName = safeGetName(Namespace);
209 return (NsName == "WTF" || NsName == "std") && FnName == "move";
210}
211
212template <typename Predicate>
213static bool isPtrOfType(const clang::QualType T, Predicate Pred) {
214 QualType type = T;
215 while (!type.isNull()) {
216 if (auto *SpecialT = type->getAs<TemplateSpecializationType>()) {
217 auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
218 return Decl && Pred(Decl->getNameAsString());
219 } else if (auto *DTS = type->getAs<DeducedTemplateSpecializationType>()) {
220 auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
221 return Decl && Pred(Decl->getNameAsString());
222 } else
223 break;
224 }
225 return false;
226}
227
229 return isPtrOfType(
230 T, [](auto Name) { return isRefType(Name) || isCheckedPtr(Name); });
231}
232
234 return isPtrOfType(T, [](auto Name) { return isRetainPtrOrOSPtr(Name); });
235}
236
238 return isPtrOfType(T, [](auto Name) { return isOwnerPtr(Name); });
239}
240
241std::optional<bool> isUncounted(const QualType T) {
242 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
243 if (auto *Decl = Subst->getAssociatedDecl()) {
245 return false;
246 }
247 }
248 return isUncounted(T->getAsCXXRecordDecl());
249}
250
251std::optional<bool> isUnchecked(const QualType T) {
252 if (auto *Subst = dyn_cast<SubstTemplateTypeParmType>(T)) {
253 if (auto *Decl = Subst->getAssociatedDecl()) {
255 return false;
256 }
257 }
258 return isUnchecked(T->getAsCXXRecordDecl());
259}
260
262 const TranslationUnitDecl *TUD) {
263 IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount;
264 DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties;
265}
266
268 auto QT = TD->getUnderlyingType();
269 if (!QT->isPointerType())
270 return;
271
272 auto PointeeQT = QT->getPointeeType();
273 const RecordType *RT = PointeeQT->getAsCanonical<RecordType>();
274 if (!RT) {
275 if (TD->hasAttr<ObjCBridgeAttr>() || TD->hasAttr<ObjCBridgeMutableAttr>()) {
276 RecordlessTypes.insert(TD->getASTContext()
278 /*Qualifier=*/std::nullopt, TD)
279 .getTypePtr());
280 }
281 return;
282 }
283
284 for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
285 if (Redecl->getAttr<ObjCBridgeAttr>() ||
286 Redecl->getAttr<ObjCBridgeMutableAttr>()) {
287 CFPointees.insert(RT);
288 return;
289 }
290 }
291}
292
293bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
294 if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
295 return true;
296 if (auto *RT = dyn_cast_or_null<RecordType>(
298 return CFPointees.contains(RT);
299 return RecordlessTypes.contains(QT.getTypePtr());
300}
301
302std::optional<bool> isUncounted(const CXXRecordDecl* Class)
303{
304 // Keep isRefCounted first as it's cheaper.
305 if (!Class || isRefCounted(Class))
306 return false;
307
308 std::optional<bool> IsRefCountable = isRefCountable(Class);
309 if (!IsRefCountable)
310 return std::nullopt;
311
312 return (*IsRefCountable);
313}
314
315std::optional<bool> isUnchecked(const CXXRecordDecl *Class) {
316 if (!Class || isCheckedPtr(Class))
317 return false; // Cheaper than below
319}
320
321std::optional<bool> isUncountedPtr(const QualType T) {
322 if (T->isPointerType() || T->isReferenceType()) {
323 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
324 return isUncounted(CXXRD);
325 }
326 return false;
327}
328
329std::optional<bool> isUncheckedPtr(const QualType T) {
330 if (T->isPointerType() || T->isReferenceType()) {
331 if (auto *CXXRD = T->getPointeeCXXRecordDecl())
332 return isUnchecked(CXXRD);
333 }
334 return false;
335}
336
337std::optional<bool> isGetterOfSafePtr(const CXXMethodDecl *M) {
338 assert(M);
339
340 const CXXRecordDecl *calleeMethodsClass = M->getParent();
341 std::string className = safeGetName(calleeMethodsClass);
342 std::string method = safeGetName(M);
343
344 if (isCheckedPtr(className) && (method == "get" || method == "ptr"))
345 return true;
346
347 if ((isRefType(className) && (method == "get" || method == "ptr")) ||
348 ((className == "String" || className == "AtomString" ||
349 className == "AtomStringImpl" || className == "UniqueString" ||
350 className == "UniqueStringImpl" || className == "Identifier") &&
351 method == "impl"))
352 return true;
353
354 if (isRetainPtrOrOSPtr(className) && method == "get")
355 return true;
356
357 // Ref<T> -> T conversion
358 // FIXME: Currently allowing any Ref<T> -> whatever cast.
359 if (isRefType(className)) {
360 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
361 QualType QT = maybeRefToRawOperator->getConversionType();
362 const Type *T = QT.getTypePtrOrNull();
363 return T && (T->isPointerType() || T->isReferenceType());
364 }
365 }
366
367 if (isCheckedPtr(className)) {
368 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
369 QualType QT = maybeRefToRawOperator->getConversionType();
370 const Type *T = QT.getTypePtrOrNull();
371 return T && (T->isPointerType() || T->isReferenceType());
372 }
373 }
374
375 if (isRetainPtrOrOSPtr(className)) {
376 if (auto *maybeRefToRawOperator = dyn_cast<CXXConversionDecl>(M)) {
377 QualType QT = maybeRefToRawOperator->getConversionType();
378 const Type *T = QT.getTypePtrOrNull();
379 return T && (T->isPointerType() || T->isReferenceType() ||
380 T->isObjCObjectPointerType());
381 }
382 }
383 return false;
384}
385
387 assert(R);
388 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
389 // FIXME: String/AtomString/UniqueString
390 const auto &ClassName = safeGetName(TmplR);
391 return isRefType(ClassName);
392 }
393 return false;
394}
395
397 assert(R);
398 if (auto *TmplR = R->getTemplateInstantiationPattern()) {
399 const auto &ClassName = safeGetName(TmplR);
400 return isCheckedPtr(ClassName);
401 }
402 return false;
403}
404
406 assert(R);
407 if (auto *TmplR = R->getTemplateInstantiationPattern())
408 return isRetainPtrOrOSPtr(safeGetName(TmplR));
409 return false;
410}
411
412bool isWeakPtr(const CXXRecordDecl *R) {
413 assert(R);
414 if (auto *TmplR = R->getTemplateInstantiationPattern())
415 return isWeakPtrClass(safeGetName(TmplR));
416 return false;
417}
418
419bool isSmartPtr(const CXXRecordDecl *R) {
420 assert(R);
421 if (auto *TmplR = R->getTemplateInstantiationPattern())
422 return isSmartPtrClass(safeGetName(TmplR));
423 return false;
424}
425
431
433 auto RetType = FD->getReturnType();
434 auto *Type = RetType.getTypePtrOrNull();
435 if (auto *MacroQualified = dyn_cast_or_null<MacroQualifiedType>(Type))
436 Type = MacroQualified->desugar().getTypePtrOrNull();
437 auto *Attr = dyn_cast_or_null<AttributedType>(Type);
438 if (!Attr)
440 auto *AnnotateType = dyn_cast_or_null<AnnotateTypeAttr>(Attr->getAttr());
441 if (!AnnotateType)
443 auto Annotation = AnnotateType->getAnnotation();
444 if (Annotation == "webkit.pointerconversion")
446 if (Annotation == "webkit.nodelete")
449}
450
452 assert(F);
453 if (isCtorOfRefCounted(F))
454 return true;
455
456 // FIXME: check # of params == 1
457 const auto FunctionName = safeGetName(F);
458 if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
459 FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
460 FunctionName == "checkedDowncast" || FunctionName == "bit_cast" ||
461 FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast" ||
462 FunctionName == "bridge_cast" || FunctionName == "bridge_id_cast" ||
463 FunctionName == "dynamic_cf_cast" || FunctionName == "checked_cf_cast" ||
464 FunctionName == "dynamic_objc_cast" ||
465 FunctionName == "checked_objc_cast")
466 return true;
467
469 return true;
470
471 return false;
472}
473
477
479 if (llvm::any_of(F->redecls(), isNoDeleteFunctionDecl))
480 return true;
481
482 const auto *MD = dyn_cast<CXXMethodDecl>(F);
483 if (!MD || !MD->isVirtual())
484 return false;
485
486 auto Overriders = llvm::to_vector(MD->overridden_methods());
487 while (!Overriders.empty()) {
488 const auto *Fn = Overriders.pop_back_val();
489 llvm::append_range(Overriders, Fn->overridden_methods());
491 return true;
492 }
493
494 return false;
495}
496
498 if (!F || !F->getDeclName().isIdentifier())
499 return false;
500 auto Name = F->getName();
501 return Name.starts_with("__builtin") || Name == "__libcpp_verbose_abort" ||
502 Name.starts_with("os_log") || Name.starts_with("_os_log");
503}
504
505bool isSingleton(const NamedDecl *F) {
506 assert(F);
507 // FIXME: check # of params == 1
508 if (auto *MethodDecl = dyn_cast<CXXMethodDecl>(F)) {
509 if (!MethodDecl->isStatic())
510 return false;
511 }
512 const auto &NameStr = safeGetName(F);
513 StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
514 return Name == "singleton" || Name.ends_with("Singleton");
515}
516
517// We only care about statements so let's use the simple
518// (non-recursive) visitor.
520 : public ConstStmtVisitor<TrivialFunctionAnalysisVisitor, bool> {
521
522 // Returns false if at least one child is non-trivial.
523 bool VisitChildren(const Stmt *S) {
524 for (const Stmt *Child : S->children()) {
525 if (Child && !Visit(Child)) {
526 if (OffendingStmt && !*OffendingStmt)
527 *OffendingStmt = Child;
528 return false;
529 }
530 }
531
532 return true;
533 }
534
535 template <typename StmtOrDecl, typename CheckFunction>
536 bool WithCachedResult(const StmtOrDecl *S, CheckFunction Function) {
537 auto CacheIt = Cache.find(S);
538 if (CacheIt != Cache.end() && !OffendingStmt)
539 return CacheIt->second;
540
541 // Treat a recursive statement to be trivial until proven otherwise.
542 auto [RecursiveIt, IsNew] = RecursiveFn.insert(std::make_pair(S, true));
543 if (!IsNew)
544 return RecursiveIt->second;
545
546 bool Result = Function();
547
548 if (!Result) {
549 for (auto &It : RecursiveFn)
550 It.second = false;
551 }
552 RecursiveIt = RecursiveFn.find(S);
553 assert(RecursiveIt != RecursiveFn.end());
554 Result = RecursiveIt->second;
555 RecursiveFn.erase(RecursiveIt);
556 Cache[S] = Result;
557
558 return Result;
559 }
560
561 bool CanTriviallyDestruct(QualType Ty) {
562 if (Ty.isNull())
563 return false;
564
565 // T*, T& or T&& does not run its destructor.
566 if (Ty->isPointerOrReferenceType())
567 return true;
568
569 // Fundamental types (integral, nullptr_t, etc...) don't have destructors.
571 return true;
572
573 if (const auto *R = Ty->getAsCXXRecordDecl()) {
574 // C++ trivially destructible classes are fine.
575 if (R->hasDefinition() && R->hasTrivialDestructor())
576 return true;
577
578 if (HasFieldWithNonTrivialDtor(R))
579 return false;
580
581 // For Webkit, side-effects are fine as long as we don't delete objects,
582 // so check recursively.
583 if (const auto *Dtor = R->getDestructor())
584 return IsFunctionTrivial(Dtor);
585 }
586
587 // Structs in C are trivial.
588 if (Ty->isRecordType())
589 return true;
590
591 // For arrays it depends on the element type.
592 // FIXME: We should really use ASTContext::getAsArrayType instead.
593 if (const auto *AT = Ty->getAsArrayTypeUnsafe())
594 return CanTriviallyDestruct(AT->getElementType());
595
596 return false; // Otherwise it's likely not trivial.
597 }
598
599 bool HasFieldWithNonTrivialDtor(const CXXRecordDecl *Cls) {
600 auto CacheIt = FieldDtorCache.find(Cls);
601 if (CacheIt != FieldDtorCache.end())
602 return CacheIt->second;
603
604 bool Result = ([&] {
605 auto HasNonTrivialField = [&](const CXXRecordDecl *R) {
606 for (const FieldDecl *F : R->fields()) {
607 if (!CanTriviallyDestruct(F->getType()))
608 return true;
609 }
610 return false;
611 };
612
613 if (HasNonTrivialField(Cls))
614 return true;
615
616 if (!Cls->hasDefinition())
617 return false;
618
619 CXXBasePaths Paths;
620 Paths.setOrigin(const_cast<CXXRecordDecl *>(Cls));
621 return Cls->lookupInBases(
622 [&](const CXXBaseSpecifier *B, CXXBasePath &) {
623 auto *T = B->getType().getTypePtrOrNull();
624 if (!T)
625 return false;
626 auto *R = T->getAsCXXRecordDecl();
627 return R && HasNonTrivialField(R);
628 },
629 Paths, /*LookupInDependent =*/true);
630 })();
631
632 FieldDtorCache[Cls] = Result;
633
634 return Result;
635 }
636
637public:
638 using CacheTy = TrivialFunctionAnalysis::CacheTy;
639
641 const Stmt **OffendingStmt = nullptr)
642 : Cache(Cache), OffendingStmt(OffendingStmt) {}
643
644 bool IsFunctionTrivial(const Decl *D) {
645 const Stmt **SavedOffendingStmt = std::exchange(OffendingStmt, nullptr);
646 auto Result = WithCachedResult(D, [&]() {
647 if (auto *FnDecl = dyn_cast<FunctionDecl>(D)) {
648 if (isNoDeleteFunction(FnDecl))
649 return true;
650 if (auto *MD = dyn_cast<CXXMethodDecl>(D); MD && MD->isVirtual())
651 return false;
652 for (auto *Param : FnDecl->parameters()) {
653 if (!HasTrivialDestructor(Param))
654 return false;
655 }
656 }
657 if (auto *CtorDecl = dyn_cast<CXXConstructorDecl>(D)) {
658 for (auto *CtorInit : CtorDecl->inits()) {
659 if (!Visit(CtorInit->getInit()))
660 return false;
661 }
662 }
663 const Stmt *Body = D->getBody();
664 if (!Body)
665 return false;
666 return Visit(Body);
667 });
668 OffendingStmt = SavedOffendingStmt;
669 return Result;
670 }
671
673 return WithCachedResult(
674 VD, [&] { return CanTriviallyDestruct(VD->getType()); });
675 }
676
677 bool IsStatementTrivial(const Stmt *S) {
678 auto CacheIt = Cache.find(S);
679 if (CacheIt != Cache.end())
680 return CacheIt->second;
681 bool Result = Visit(S);
682 Cache[S] = Result;
683 return Result;
684 }
685
686 bool VisitStmt(const Stmt *S) {
687 // All statements are non-trivial unless overriden later.
688 // Don't even recurse into children by default.
689 return false;
690 }
691
693 // Ignore attributes.
694 return Visit(AS->getSubStmt());
695 }
696
698 // A compound statement is allowed as long each individual sub-statement
699 // is trivial.
700 return WithCachedResult(CS, [&]() { return VisitChildren(CS); });
701 }
702
704 return WithCachedResult(CBS, [&]() { return VisitChildren(CBS); });
705 }
706
707 bool VisitReturnStmt(const ReturnStmt *RS) {
708 // A return statement is allowed as long as the return value is trivial.
709 if (auto *RV = RS->getRetValue())
710 return Visit(RV);
711 return true;
712 }
713
714 bool VisitDeclStmt(const DeclStmt *DS) {
715 for (auto &Decl : DS->decls()) {
716 // FIXME: Handle DecompositionDecls.
717 if (auto *VD = dyn_cast<VarDecl>(Decl)) {
718 if (!HasTrivialDestructor(VD))
719 return false;
720 }
721 }
722 return VisitChildren(DS);
723 }
724 bool VisitDoStmt(const DoStmt *DS) { return VisitChildren(DS); }
725 bool VisitIfStmt(const IfStmt *IS) {
726 return WithCachedResult(IS, [&]() { return VisitChildren(IS); });
727 }
728 bool VisitForStmt(const ForStmt *FS) {
729 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
730 }
732 return WithCachedResult(FS, [&]() { return VisitChildren(FS); });
733 }
734 bool VisitWhileStmt(const WhileStmt *WS) {
735 return WithCachedResult(WS, [&]() { return VisitChildren(WS); });
736 }
737 bool VisitSwitchStmt(const SwitchStmt *SS) { return VisitChildren(SS); }
738 bool VisitCaseStmt(const CaseStmt *CS) { return VisitChildren(CS); }
739 bool VisitDefaultStmt(const DefaultStmt *DS) { return VisitChildren(DS); }
740
741 // break, continue, goto, and label statements are always trivial.
742 bool VisitBreakStmt(const BreakStmt *) { return true; }
743 bool VisitContinueStmt(const ContinueStmt *) { return true; }
744 bool VisitGotoStmt(const GotoStmt *) { return true; }
745 bool VisitLabelStmt(const LabelStmt *) { return true; }
746
748 // Unary operators are trivial if its operand is trivial except co_await.
749 return UO->getOpcode() != UO_Coawait && Visit(UO->getSubExpr());
750 }
751
753 // Binary operators are trivial if their operands are trivial.
754 return Visit(BO->getLHS()) && Visit(BO->getRHS());
755 }
756
758 // Compound assignment operator such as |= is trivial if its
759 // subexpresssions are trivial.
760 return VisitChildren(CAO);
761 }
762
764 return VisitChildren(ASE);
765 }
766
768 // Ternary operators are trivial if their conditions & values are trivial.
769 return VisitChildren(CO);
770 }
771
772 bool VisitAtomicExpr(const AtomicExpr *E) { return VisitChildren(E); }
773
775 // Any static_assert is considered trivial.
776 return true;
777 }
778
779 bool VisitCallExpr(const CallExpr *CE) {
780 if (!checkArguments(CE))
781 return false;
782
783 auto *Callee = CE->getDirectCallee();
784 if (!Callee)
785 return false;
786
787 if (isPtrConversion(Callee))
788 return true;
789
790 const auto &Name = safeGetName(Callee);
791
792 if (Callee->isInStdNamespace() &&
793 (Name == "addressof" || Name == "forward" || Name == "move"))
794 return true;
795
796 if (Name == "WTFCrashWithInfo" || Name == "WTFBreakpointTrap" ||
797 Name == "WTFReportBacktrace" ||
798 Name == "WTFCrashWithSecurityImplication" || Name == "WTFCrash" ||
799 Name == "WTFReportAssertionFailure" || Name == "isMainThread" ||
800 Name == "isMainThreadOrGCThread" || Name == "isMainRunLoop" ||
801 Name == "isWebThread" || Name == "isUIThread" ||
802 Name == "mayBeGCThread" || Name == "compilerFenceForCrash" ||
804 return true;
805
806 return IsFunctionTrivial(Callee);
807 }
808
809 bool VisitGCCAsmStmt(const GCCAsmStmt *AS) {
810 return AS->getAsmString() == "brk #0xc471";
811 }
812
813 bool
815 // Non-type template paramter is compile time constant and trivial.
816 return true;
817 }
818
820 return VisitChildren(E);
821 }
822
824 // A predefined identifier such as "func" is considered trivial.
825 return true;
826 }
827
829 // offsetof(T, D) is considered trivial.
830 return true;
831 }
832
834 if (!checkArguments(MCE))
835 return false;
836
837 bool TrivialThis = Visit(MCE->getImplicitObjectArgument());
838 if (!TrivialThis)
839 return false;
840
841 auto *Callee = MCE->getMethodDecl();
842 if (!Callee)
843 return false;
844
845 if (isa<CXXDestructorDecl>(Callee) &&
846 !CanTriviallyDestruct(MCE->getObjectType()))
847 return false;
848
849 auto Name = safeGetName(Callee);
850 if (Name == "ref" || Name == "incrementCheckedPtrCount")
851 return true;
852
853 std::optional<bool> IsGetterOfRefCounted = isGetterOfSafePtr(Callee);
854 if (IsGetterOfRefCounted && *IsGetterOfRefCounted)
855 return true;
856
857 // Recursively descend into the callee to confirm that it's trivial as well.
858 return IsFunctionTrivial(Callee);
859 }
860
862 if (!checkArguments(OCE))
863 return false;
864 auto *Callee = OCE->getCalleeDecl();
865 if (!Callee)
866 return false;
867 // Recursively descend into the callee to confirm that it's trivial as well.
868 return IsFunctionTrivial(Callee);
869 }
870
872 auto *SemanticExpr = Op->getSemanticForm();
873 return SemanticExpr && Visit(SemanticExpr);
874 }
875
877 if (auto *Expr = E->getExpr()) {
878 if (!Visit(Expr))
879 return false;
880 }
881 return true;
882 }
883
885 return Visit(E->getExpr());
886 }
887
888 bool checkArguments(const CallExpr *CE) {
889 for (const Expr *Arg : CE->arguments()) {
890 if (Arg && !Visit(Arg))
891 return false;
892 }
893 return true;
894 }
895
897 for (const Expr *Arg : CE->arguments()) {
898 if (Arg && !Visit(Arg))
899 return false;
900 }
901
902 // Recursively descend into the callee to confirm that it's trivial.
903 return IsFunctionTrivial(CE->getConstructor());
904 }
905
909
910 bool VisitCXXNewExpr(const CXXNewExpr *NE) { return VisitChildren(NE); }
911
913 return Visit(ICE->getSubExpr());
914 }
915
917 return Visit(ECE->getSubExpr());
918 }
919
921 return Visit(VMT->getSubExpr());
922 }
923
925 if (auto *Temp = BTE->getTemporary()) {
926 if (!IsFunctionTrivial(Temp->getDestructor()))
927 return false;
928 }
929 return Visit(BTE->getSubExpr());
930 }
931
933 return Visit(AILE->getCommonExpr()) && Visit(AILE->getSubExpr());
934 }
935
937 return true; // The current array index in VisitArrayInitLoopExpr is always
938 // trivial.
939 }
940
942 return Visit(OVE->getSourceExpr());
943 }
944
946 return Visit(EWC->getSubExpr());
947 }
948
949 bool VisitParenExpr(const ParenExpr *PE) { return Visit(PE->getSubExpr()); }
950
952 for (const Expr *Child : ILE->inits()) {
953 if (Child && !Visit(Child))
954 return false;
955 }
956 return true;
957 }
958
959 bool VisitMemberExpr(const MemberExpr *ME) {
960 // Field access is allowed but the base pointer may itself be non-trivial.
961 return Visit(ME->getBase());
962 }
963
964 bool VisitCXXThisExpr(const CXXThisExpr *CTE) {
965 // The expression 'this' is always trivial, be it explicit or implicit.
966 return true;
967 }
968
970 // nullptr is trivial.
971 return true;
972 }
973
974 bool VisitDeclRefExpr(const DeclRefExpr *DRE) {
975 // The use of a variable is trivial.
976 return true;
977 }
978
979 // Constant literal expressions are always trivial
980 bool VisitIntegerLiteral(const IntegerLiteral *E) { return true; }
981 bool VisitFloatingLiteral(const FloatingLiteral *E) { return true; }
982 bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
983 bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
984 bool VisitStringLiteral(const StringLiteral *E) { return true; }
985 bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
986
988 // Constant expressions are trivial.
989 return true;
990 }
991
993 // An implicit value initialization is trvial.
994 return true;
995 }
996
997private:
998 CacheTy &Cache;
999 CacheTy FieldDtorCache;
1000 CacheTy RecursiveFn;
1001 const Stmt **OffendingStmt;
1002};
1003
1004bool TrivialFunctionAnalysis::isTrivialImpl(
1005 const Decl *D, TrivialFunctionAnalysis::CacheTy &Cache,
1006 const Stmt **OffendingStmt) {
1007 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1008 return V.IsFunctionTrivial(D);
1009}
1010
1011bool TrivialFunctionAnalysis::isTrivialImpl(
1012 const Stmt *S, TrivialFunctionAnalysis::CacheTy &Cache,
1013 const Stmt **OffendingStmt) {
1014 TrivialFunctionAnalysisVisitor V(Cache, OffendingStmt);
1015 return V.IsStatementTrivial(S);
1016}
1017
1018bool TrivialFunctionAnalysis::hasTrivialDtorImpl(const VarDecl *VD,
1019 CacheTy &Cache) {
1021 return V.HasTrivialDestructor(VD);
1022}
1023
1024} // 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:4914
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:6021
Represents a loop initializing the elements of an array.
Definition Expr.h:5968
OpaqueValueExpr * getCommonExpr() const
Get the common subexpression shared by all initializations (the source array).
Definition Expr.h:5983
Expr * getSubExpr() const
Get the initializer to use for each array element.
Definition Expr.h:5988
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:6928
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2213
Stmt * getSubStmt()
Definition Stmt.h:2249
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4041
Expr * getLHS() const
Definition Expr.h:4091
Expr * getRHS() const
Definition Expr.h:4093
BreakStmt - This represents a break.
Definition Stmt.h:3145
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
void setOrigin(const CXXRecordDecl *Rec)
void clear()
Clear the base-paths results.
Represents a base class of a C++ class.
Definition DeclCXX.h:146
QualType getType() const
Retrieves the type of the base class.
Definition DeclCXX.h:249
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
CXXTemporary * getTemporary()
Definition ExprCXX.h:1515
const Expr * getSubExpr() const
Definition ExprCXX.h:1519
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
arg_range arguments()
Definition ExprCXX.h:1676
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1615
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1112
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:135
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will call.
Definition ExprCXX.h:1792
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Definition ExprCXX.cpp:748
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition ExprCXX.cpp:729
QualType getObjectType() const
Retrieve the type of the object argument.
Definition ExprCXX.cpp:741
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h: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:1930
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:1750
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:3129
Represents the body of a coroutine.
Definition StmtCXX.h:320
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1273
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
decl_range decls()
Definition Stmt.h:1689
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:547
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition DeclBase.h:1100
bool hasAttr() const
Definition DeclBase.h:585
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
Definition DeclBase.cpp:553
bool isIdentifier() const
Predicate functions for querying what type of name this is.
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2842
ExplicitCastExpr - An explicit cast written in the source code.
Definition Expr.h: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:3182
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2898
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:3456
std::string getAsmString() const
Definition Stmt.cpp:574
GotoStmt - This represents a direct goto.
Definition Stmt.h:2979
IfStmt - This represents an if/then/else.
Definition Stmt.h:2269
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3856
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6057
Describes an C or C++ initializer list.
Definition Expr.h:5302
ArrayRef< Expr * > inits() const
Definition Expr.h:5355
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2156
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h: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:8445
QualType getCanonicalType() const
Definition TypeBase.h:8497
const Type * getTypePtrOrNull() const
Definition TypeBase.h:8449
bool isUnretained(const QualType, bool ignoreARC=false)
void visitTranslationUnitDecl(const TranslationUnitDecl *)
void visitTypedef(const TypedefDecl *)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3170
Expr * getRetValue()
Definition Stmt.h:3197
Represents a C++11 static_assert declaration.
Definition DeclCXX.h: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:2519
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:1875
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition TypeBase.h:8645
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:9170
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition TypeBase.h:9328
bool isPointerOrReferenceType() const
Definition TypeBase.h:8686
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2983
bool isRecordType() const
Definition TypeBase.h:8809
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3689
QualType getUnderlyingType() const
Definition Decl.h:3639
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h: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:2707
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool isCocoaObjectRef(QualType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isCtorOfSafePtr(const clang::FunctionDecl *F)
bool isTrivialBuiltinFunction(const FunctionDecl *F)
bool isa(CodeGen::Address addr)
Definition Address.h:330
static bool isNoDeleteFunctionDecl(const FunctionDecl *F)
bool isPtrConversion(const FunctionDecl *F)
static bool isWeakPtrClass(const std::string &Name)
std::optional< bool > isCheckedPtrCapable(const clang::CXXRecordDecl *R)
std::optional< bool > isUnchecked(const QualType T)
bool isCtorOfRefCounted(const clang::FunctionDecl *F)
bool isRefOrCheckedPtrType(const clang::QualType T)
@ AS_public
Definition Specifiers.h:125
bool isRetainPtrOrOSPtrType(const clang::QualType T)
bool isCtorOfRetainPtrOrOSPtr(const clang::FunctionDecl *F)
@ Result
The result type of a method or function.
Definition TypeBase.h:905
bool isOwnerPtr(const std::string &Name)
std::optional< bool > isRefCountable(const clang::CXXRecordDecl *R)
std::optional< const clang::CXXRecordDecl * > hasPublicMethodInBase(const CXXBaseSpecifier *Base, StringRef NameToMatch)
static WebKitAnnotation typeAnnotationForReturnType(const FunctionDecl *FD)
bool isSmartPtrClass(const std::string &Name)
std::string getConstructorName(const clang::FunctionDecl *F)
bool isRefCounted(const CXXRecordDecl *R)
static bool isPtrOfType(const clang::QualType T, Predicate Pred)
std::optional< bool > isSmartPtrCompatible(const CXXRecordDecl *R, StringRef IncMethodName, StringRef DecMethodName)
bool isNoDeleteFunction(const FunctionDecl *F)
bool isOwnerPtrType(const clang::QualType T)
bool isSmartPtr(const CXXRecordDecl *R)
std::optional< bool > isGetterOfSafePtr(const CXXMethodDecl *M)
bool isRetainPtrOrOSPtr(const std::string &Name)
bool isRefType(const std::string &Name)
std::optional< bool > isUncountedPtr(const QualType T)
std::string safeGetName(const T *ASTNode)
Definition ASTUtils.h:95
bool isCtorOfCheckedPtr(const clang::FunctionDecl *F)
bool isSingleton(const NamedDecl *F)
bool isCheckedPtr(const std::string &Name)
bool isStdOrWTFMove(const clang::FunctionDecl *F)
@ None
The alignment was not explicit in code.
Definition ASTContext.h:182
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5989
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5979
std::optional< bool > isUncounted(const QualType T)
std::optional< bool > isUncheckedPtr(const QualType T)
bool isWeakPtr(const CXXRecordDecl *R)