1919#include " clang/Basic/IdentifierTable.h"
2020#include " llvm/ADT/SmallPtrSet.h"
2121
22- namespace clang {
23- namespace {
24- bool typeContainsPointer (QualType T,
25- llvm::SmallPtrSet<const RecordDecl *, 4 > &VisitedRD,
26- bool &IncompleteType) {
22+ using namespace clang ;
23+ using namespace infer_alloc ;
24+
25+ static bool
26+ typeContainsPointer (QualType T,
27+ llvm::SmallPtrSet<const RecordDecl *, 4 > &VisitedRD,
28+ bool &IncompleteType) {
2729 QualType CanonicalType = T.getCanonicalType ();
2830 if (CanonicalType->isPointerType ())
2931 return true ; // base case
@@ -70,7 +72,7 @@ bool typeContainsPointer(QualType T,
7072}
7173
7274// / Infer type from a simple sizeof expression.
73- QualType inferTypeFromSizeofExpr (const Expr *E) {
75+ static QualType inferTypeFromSizeofExpr (const Expr *E) {
7476 const Expr *Arg = E->IgnoreParenImpCasts ();
7577 if (const auto *UET = dyn_cast<UnaryExprOrTypeTraitExpr>(Arg)) {
7678 if (UET->getKind () == UETT_SizeOf) {
@@ -96,7 +98,7 @@ QualType inferTypeFromSizeofExpr(const Expr *E) {
9698// /
9799// / malloc(sizeof(HasFlexArray) + sizeof(int) * 32); // infers 'HasFlexArray'
98100// /
99- QualType inferPossibleTypeFromArithSizeofExpr (const Expr *E) {
101+ static QualType inferPossibleTypeFromArithSizeofExpr (const Expr *E) {
100102 const Expr *Arg = E->IgnoreParenImpCasts ();
101103 // The argument is a lone sizeof expression.
102104 if (QualType T = inferTypeFromSizeofExpr (Arg); !T.isNull ())
@@ -132,7 +134,7 @@ QualType inferPossibleTypeFromArithSizeofExpr(const Expr *E) {
132134// / size_t my_size = sizeof(MyType);
133135// / void *x = malloc(my_size); // infers 'MyType'
134136// /
135- QualType inferPossibleTypeFromVarInitSizeofExpr (const Expr *E) {
137+ static QualType inferPossibleTypeFromVarInitSizeofExpr (const Expr *E) {
136138 const Expr *Arg = E->IgnoreParenImpCasts ();
137139 if (const auto *DRE = dyn_cast<DeclRefExpr>(Arg)) {
138140 if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl ())) {
@@ -148,21 +150,19 @@ QualType inferPossibleTypeFromVarInitSizeofExpr(const Expr *E) {
148150// /
149151// / MyType *x = (MyType *)malloc(4096); // infers 'MyType'
150152// /
151- QualType inferPossibleTypeFromCastExpr (const CallExpr *CallE,
152- const CastExpr *CastE) {
153+ static QualType inferPossibleTypeFromCastExpr (const CallExpr *CallE,
154+ const CastExpr *CastE) {
153155 if (!CastE)
154156 return QualType ();
155157 QualType PtrType = CastE->getType ();
156158 if (PtrType->isPointerType ())
157159 return PtrType->getPointeeType ();
158160 return QualType ();
159161}
160- } // anonymous namespace
161-
162- namespace infer_alloc {
163162
164- QualType inferPossibleType (const CallExpr *E, const ASTContext &Ctx,
165- const CastExpr *CastE) {
163+ QualType clang::infer_alloc::inferPossibleType (const CallExpr *E,
164+ const ASTContext &Ctx,
165+ const CastExpr *CastE) {
166166 QualType AllocType;
167167 // First check arguments.
168168 for (const Expr *Arg : E->arguments ()) {
@@ -179,7 +179,7 @@ QualType inferPossibleType(const CallExpr *E, const ASTContext &Ctx,
179179}
180180
181181std::optional<llvm::AllocTokenMetadata>
182- getAllocTokenMetadata (QualType T, const ASTContext &Ctx) {
182+ clang::infer_alloc:: getAllocTokenMetadata (QualType T, const ASTContext &Ctx) {
183183 llvm::AllocTokenMetadata ATMD;
184184
185185 // Get unique type name.
@@ -199,6 +199,3 @@ getAllocTokenMetadata(QualType T, const ASTContext &Ctx) {
199199
200200 return ATMD;
201201}
202-
203- } // namespace infer_alloc
204- } // namespace clang
0 commit comments