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