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 
14 namespace clang {
15 class CXXBaseSpecifier;
16 class CXXMethodDecl;
17 class CXXRecordDecl;
18 class FunctionDecl;
19 class Type;
20 
21 // Ref-countability of a type is implicitly defined by Ref<T> and RefPtr<T>
22 // implementation. It can be modeled as: type T having public methods ref() and
23 // deref()
24 
25 // In WebKit there are two ref-counted templated smart pointers: RefPtr<T> and
26 // Ref<T>.
27 
28 /// \returns CXXRecordDecl of the base if the type is ref-countable, nullptr if
29 /// not, None if inconclusive.
30 llvm::Optional<const clang::CXXRecordDecl *>
31 isRefCountable(const clang::CXXBaseSpecifier *Base);
32 
33 /// \returns true if \p Class is ref-countable, false if not, None if
34 /// inconclusive.
35 llvm::Optional<bool> isRefCountable(const clang::CXXRecordDecl *Class);
36 
37 /// \returns true if \p Class is ref-counted, false if not.
38 bool isRefCounted(const clang::CXXRecordDecl *Class);
39 
40 /// \returns true if \p Class is ref-countable AND not ref-counted, false if
41 /// not, None if inconclusive.
42 llvm::Optional<bool> isUncounted(const clang::CXXRecordDecl *Class);
43 
44 /// \returns true if \p T is either a raw pointer or reference to an uncounted
45 /// class, false if not, None if inconclusive.
46 llvm::Optional<bool> isUncountedPtr(const clang::Type *T);
47 
48 /// \returns true if \p F creates ref-countable object from uncounted parameter,
49 /// false if not.
50 bool isCtorOfRefCounted(const clang::FunctionDecl *F);
51 
52 /// \returns true if \p M is getter of a ref-counted class, false if not.
53 llvm::Optional<bool> isGetterOfRefCounted(const clang::CXXMethodDecl *Method);
54 
55 /// \returns true if \p F is a conversion between ref-countable or ref-counted
56 /// pointer types.
57 bool isPtrConversion(const FunctionDecl *F);
58 
59 } // namespace clang
60 
61 #endif
62