clang 19.0.0git
PtrTypesSemantics.h
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#ifndef LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
10#define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
11
12#include "llvm/ADT/APInt.h"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/PointerUnion.h"
15#include <optional>
16
17namespace clang {
18class CXXBaseSpecifier;
19class CXXMethodDecl;
20class CXXRecordDecl;
21class Decl;
22class FunctionDecl;
23class Stmt;
24class Type;
25
26// Ref-countability of a type is implicitly defined by Ref<T> and RefPtr<T>
27// implementation. It can be modeled as: type T having public methods ref() and
28// deref()
29
30// In WebKit there are two ref-counted templated smart pointers: RefPtr<T> and
31// Ref<T>.
32
33/// \returns CXXRecordDecl of the base if the type has ref as a public method,
34/// nullptr if not, std::nullopt if inconclusive.
35std::optional<const clang::CXXRecordDecl *>
36hasPublicMethodInBase(const CXXBaseSpecifier *Base, const char *NameToMatch);
37
38/// \returns true if \p Class is ref-countable, false if not, std::nullopt if
39/// inconclusive.
40std::optional<bool> isRefCountable(const clang::CXXRecordDecl* Class);
41
42/// \returns true if \p Class is ref-counted, false if not.
44
45/// \returns true if \p Class is ref-countable AND not ref-counted, false if
46/// not, std::nullopt if inconclusive.
47std::optional<bool> isUncounted(const clang::CXXRecordDecl* Class);
48
49/// \returns true if \p T is either a raw pointer or reference to an uncounted
50/// class, false if not, std::nullopt if inconclusive.
51std::optional<bool> isUncountedPtr(const clang::Type* T);
52
53/// \returns true if \p F creates ref-countable object from uncounted parameter,
54/// false if not.
56
57/// \returns true if \p F returns a ref-counted object, false if not.
59
60/// \returns true if \p M is getter of a ref-counted class, false if not.
61std::optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
62
63/// \returns true if \p F is a conversion between ref-countable or ref-counted
64/// pointer types.
65bool isPtrConversion(const FunctionDecl *F);
66
67/// \returns true if \p F is a static singleton function.
68bool isSingleton(const FunctionDecl *F);
69
70/// An inter-procedural analysis facility that detects functions with "trivial"
71/// behavior with respect to reference counting, such as simple field getters.
73public:
74 /// \returns true if \p D is a "trivial" function.
75 bool isTrivial(const Decl *D) const { return isTrivialImpl(D, TheCache); }
76 bool isTrivial(const Stmt *S) const { return isTrivialImpl(S, TheCache); }
77
78private:
80
81 using CacheTy =
82 llvm::DenseMap<llvm::PointerUnion<const Decl *, const Stmt *>, bool>;
83 mutable CacheTy TheCache{};
84
85 static bool isTrivialImpl(const Decl *D, CacheTy &Cache);
86 static bool isTrivialImpl(const Stmt *S, CacheTy &Cache);
87};
88
89} // namespace clang
90
91#endif
MatchType Type
TypePropertyCache< Private > Cache
Definition: Type.cpp:4399
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2057
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Represents a function declaration or definition.
Definition: Decl.h:1971
Stmt - This represents one statement.
Definition: Stmt.h:84
An inter-procedural analysis facility that detects functions with "trivial" behavior with respect to ...
bool isTrivial(const Stmt *S) const
bool isTrivial(const Decl *D) const
The base class of the type hierarchy.
Definition: Type.h:1607
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
std::optional< bool > isGetterOfRefCounted(const CXXMethodDecl *M)
std::optional< bool > isUncountedPtr(const Type *T)
bool isPtrConversion(const FunctionDecl *F)
bool isCtorOfRefCounted(const clang::FunctionDecl *F)
std::optional< bool > isUncounted(const CXXRecordDecl *Class)
std::optional< const clang::CXXRecordDecl * > hasPublicMethodInBase(const CXXBaseSpecifier *Base, const char *NameToMatch)
std::optional< bool > isRefCountable(const CXXRecordDecl *R)
bool isSingleton(const FunctionDecl *F)
bool isRefCounted(const CXXRecordDecl *R)
bool isReturnValueRefCounted(const clang::FunctionDecl *F)
const FunctionProtoType * T
@ Class
The "class" keyword introduces the elaborated-type-specifier.