clang 24.0.0git
RawPtrRefCallArgsChecker.cpp
Go to the documentation of this file.
1//=======- RawPtrRefCallArgsChecker.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 "ASTUtils.h"
10#include "DiagOutputUtils.h"
11#include "PtrTypesSemantics.h"
13#include "clang/AST/Decl.h"
14#include "clang/AST/DeclCXX.h"
18#include "clang/Lex/Lexer.h"
23#include "llvm/Support/SaveAndRestore.h"
24#include <optional>
25
26using namespace clang;
27using namespace ento;
28
29namespace {
30
31class RawPtrRefCallArgsChecker
32 : public Checker<check::ASTDecl<TranslationUnitDecl>> {
33 BugType Bug;
34
35 TrivialFunctionAnalysis TFA;
36 EnsureFunctionAnalysis EFA;
37
38protected:
39 mutable BugReporter *BR;
40 const std::unique_ptr<PtrRefSafetyModel> Model;
41
42public:
43 RawPtrRefCallArgsChecker(const char *description,
44 std::unique_ptr<PtrRefSafetyModel> Model)
45 : Bug(this, description, "WebKit coding guidelines"),
46 Model(std::move(Model)) {}
47
48 void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
49 BugReporter &BRArg) const {
50 BR = &BRArg;
51
52 // The calls to checkAST* from AnalysisConsumer don't
53 // visit template instantiations or lambda classes. We
54 // want to visit those, so we make our own RecursiveASTVisitor.
55 struct LocalVisitor : DynamicRecursiveASTVisitor {
56 const RawPtrRefCallArgsChecker *Checker;
57 Decl *DeclWithIssue{nullptr};
58
59 explicit LocalVisitor(const RawPtrRefCallArgsChecker *Checker)
60 : Checker(Checker) {
61 assert(Checker);
62 ShouldVisitTemplateInstantiations = true;
63 ShouldVisitImplicitCode = false;
64 }
65
66 bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) override {
68 return true;
69 return DynamicRecursiveASTVisitor::TraverseClassTemplateDecl(Decl);
70 }
71
72 bool TraverseDecl(Decl *D) override {
73 llvm::SaveAndRestore SavedDecl(DeclWithIssue);
74 if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
75 DeclWithIssue = D;
77 }
78
79 bool VisitCallExpr(CallExpr *CE) override {
80 Checker->visitCallExpr(CE, DeclWithIssue);
81 return true;
82 }
83
84 bool VisitCXXConstructExpr(CXXConstructExpr *CE) override {
85 Checker->visitConstructExpr(CE, DeclWithIssue);
86 return true;
87 }
88
89 bool VisitTypedefDecl(TypedefDecl *TD) override {
90 if (auto *RTC = Checker->Model->retainTypeChecker())
91 RTC->visitTypedef(TD);
92 return true;
93 }
94
95 bool VisitObjCMessageExpr(ObjCMessageExpr *ObjCMsgExpr) override {
96 Checker->visitObjCMessageExpr(ObjCMsgExpr, DeclWithIssue);
97 return true;
98 }
99 };
100
101 LocalVisitor visitor(this);
102 if (auto *RTC = Model->retainTypeChecker())
103 RTC->visitTranslationUnitDecl(TUD);
104 visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
105 }
106
107 template <typename CallOrConstrcut>
108 void visitCallOrConstructExpr(const CallOrConstrcut *CE,
109 const FunctionDecl *F, const Decl *D) const {
110 if (F) {
111 // Skip the first argument for overloaded member operators (e. g. lambda
112 // or std::function call operator).
113 unsigned ArgIdx =
114 isa<CXXOperatorCallExpr>(CE) && isa_and_nonnull<CXXMethodDecl>(F);
115
116 if (auto *MemberCallExpr = dyn_cast<CXXMemberCallExpr>(CE))
117 checkThisArg(F, MemberCallExpr, D);
118
119 if (ArgIdx) {
120 auto *Arg = CE->getArg(0);
121 QualType ArgType = Arg->getType().getCanonicalType();
122 std::optional<bool> IsUnsafe = Model->isUnsafeType(ArgType);
123 if (IsUnsafe && *IsUnsafe && !isPtrOriginSafe(Arg))
124 reportBugOnThis(F, Arg, D);
125 }
126
127 for (auto P = F->param_begin();
128 P < F->param_end() && ArgIdx < CE->getNumArgs(); ++P, ++ArgIdx) {
129 // TODO: attributes.
130 // if ((*P)->hasAttr<SafeRefCntblRawPtrAttr>())
131 // continue;
132 checkArg(F, CE->getArg(ArgIdx), (*P)->getType(), *P, D);
133 }
134 for (; ArgIdx < CE->getNumArgs(); ++ArgIdx) {
135 auto *Arg = CE->getArg(ArgIdx);
136 checkArg(F, Arg, Arg->getType(), nullptr, D);
137 }
138 }
139 }
140
141 void visitCallExpr(const CallExpr *CE, const Decl *D) const {
142 auto *Callee = CE->getDirectCallee();
143 if (shouldSkipCall(CE, Callee))
144 return;
145
146 if (Callee)
147 visitCallOrConstructExpr(CE, Callee, D);
148 else if (auto *Decl = CE->getCalleeDecl()) {
149 if (auto *FnType = Decl->getFunctionType()) {
150 if (auto *ProtoType = dyn_cast<FunctionProtoType>(FnType)) {
151 if (auto *MemberCallExpr = dyn_cast<CXXMemberCallExpr>(CE))
152 checkThisArg(nullptr, MemberCallExpr, D);
153 unsigned ArgIdx = 0;
154 for (auto PT = ProtoType->param_type_begin();
155 PT < ProtoType->param_type_end() && ArgIdx < CE->getNumArgs();
156 ++PT, ++ArgIdx)
157 checkArg(nullptr, CE->getArg(ArgIdx), *PT, nullptr, D);
158 for (; ArgIdx < CE->getNumArgs(); ++ArgIdx) {
159 auto *Arg = CE->getArg(ArgIdx);
160 checkArg(nullptr, Arg, Arg->getType(), nullptr, D);
161 }
162 }
163 }
164 }
165 }
166
167 void visitConstructExpr(const CXXConstructExpr *CE, const Decl *D) const {
168 auto *Constructor = CE->getConstructor();
169 if (shouldSkipCall(CE, Constructor))
170 return;
171 if (Constructor)
172 visitCallOrConstructExpr(CE, Constructor, D);
173 }
174
175 void visitObjCMessageExpr(const ObjCMessageExpr *E, const Decl *D) const {
176 if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
177 return;
178
179 if (auto *Receiver = E->getInstanceReceiver()) {
180 std::optional<bool> IsUnsafe = Model->isUnsafePtr(E->getReceiverType());
181 if (IsUnsafe && *IsUnsafe && !isPtrOriginSafe(Receiver)) {
182 if (isAllocInit(E))
183 return;
184 auto SelectorName = E->getSelector().getNameForSlot(0);
185 if (SelectorName == "isEqual" || SelectorName == "isEqualToString")
186 return;
187 reportBugOnReceiver(E->getMethodDecl(), Receiver, D);
188 }
189 }
190
191 auto *MethodDecl = E->getMethodDecl();
192 if (!MethodDecl)
193 return;
194
195 auto ArgCount = E->getNumArgs();
196 for (unsigned i = 0; i < ArgCount; ++i) {
197 auto *Arg = E->getArg(i);
198 bool hasParam = i < MethodDecl->param_size();
199 auto *Param = hasParam ? MethodDecl->getParamDecl(i) : nullptr;
200 auto ArgType = Arg->getType();
201 std::optional<bool> IsUnsafe = Model->isUnsafePtr(ArgType);
202 if (!IsUnsafe || !(*IsUnsafe))
203 continue;
204 if (isPtrOriginSafe(Arg))
205 continue;
206 reportBug(MethodDecl, Arg, Param, D);
207 }
208 }
209
210 void checkThisArg(const NamedDecl *Callee,
211 const CXXMemberCallExpr *MemberCallExpr,
212 const Decl *DeclWithIssue) const {
213 if (auto *MD = MemberCallExpr->getMethodDecl()) {
214 auto name = safeGetName(MD);
215 if (name == "ref" || name == "deref")
216 return;
217 if (name == "incrementCheckedPtrCount" ||
218 name == "decrementCheckedPtrCount")
219 return;
220 }
221 auto *ThisExpr = MemberCallExpr->getImplicitObjectArgument();
222 QualType ArgType = MemberCallExpr->getObjectType().getCanonicalType();
223 std::optional<bool> IsUnsafe = Model->isUnsafeType(ArgType);
224 if (!IsUnsafe || !*IsUnsafe)
225 return;
226
227 if (isPtrOriginSafe(ThisExpr))
228 return;
229
230 reportBugOnThis(Callee, ThisExpr, DeclWithIssue);
231 }
232
233 void checkArg(const NamedDecl *Callee, const Expr *Arg, QualType ParamType,
234 const ParmVarDecl *Param, const Decl *DeclWithIssue) const {
235 std::optional<bool> IsUncounted = Model->isUnsafePtr(ParamType);
236 if (!IsUncounted || !(*IsUncounted))
237 return;
238
239 if (auto *DefaultArg = dyn_cast<CXXDefaultArgExpr>(Arg))
240 Arg = DefaultArg->getExpr();
241
242 if (isPtrOriginSafe(Arg))
243 return;
244
245 reportBug(Callee, Arg, Param, DeclWithIssue);
246 }
247
248 bool isPtrOriginSafe(const Expr *Arg) const {
249 return tryToFindPtrOrigin(
250 Arg, /*StopAtFirstRefCountedObj=*/true,
251 [&](const clang::CXXRecordDecl *Record) {
252 return Model->isSafePtr(Record);
253 },
254 [&](const clang::QualType T) { return Model->isSafePtrType(T); },
255 [&](const clang::Decl *D) {
256 return Model->isSafeDecl(D, BR->getSourceManager());
257 },
258 [&](const clang::Expr *ArgOrigin, bool IsSafe) {
259 if (IsSafe)
260 return true;
261 if (isNullPtr(ArgOrigin))
262 return true;
263 if (isa<IntegerLiteral>(ArgOrigin)) {
264 // FIXME: Check the value.
265 // foo(123)
266 return true;
267 }
268 if (isa<CXXBoolLiteralExpr>(ArgOrigin))
269 return true;
270 if (isa<ObjCStringLiteral>(ArgOrigin))
271 return true;
272 if (isASafeCallArg(ArgOrigin))
273 return true;
274 if (EFA.isACallToEnsureFn(ArgOrigin)) {
275 auto *MCE = dyn_cast<CXXMemberCallExpr>(ArgOrigin);
276 assert(MCE);
277 if (isPtrOriginSafe(MCE->getImplicitObjectArgument()))
278 return true;
279 }
280 if (Model->isSafeExpr(ArgOrigin))
281 return true;
282 return false;
283 });
284 }
285
286 template <typename CallOrConstruct>
287 bool shouldSkipCall(const CallOrConstruct *CE,
288 const FunctionDecl *Callee) const {
289 if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
290 return true;
291
292 if (Callee && TFA.isTrivial(Callee))
293 return true;
294
295 if (isTrivialBuiltinFunction(Callee))
296 return true;
297
298 if (CE->getNumArgs() == 0)
299 return false;
300
301 // If an assignment is problematic we should warn about the sole existence
302 // of object on LHS.
303 if (auto *MemberOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
304 // Note: assignemnt to built-in type isn't derived from CallExpr.
305 if (MemberOp->getOperator() ==
306 OO_Equal) { // Ignore assignment to Ref/RefPtr.
307 auto *callee = MemberOp->getDirectCallee();
308 if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
309 if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
310 if (Model->isSafePtr(classDecl))
311 return true;
312 }
313 }
314 }
315 if (MemberOp->isAssignmentOp())
316 return false;
317 }
318
319 if (!Callee)
320 return false;
321
322 if (isMethodOnWTFContainerType(Callee))
323 return true;
324
325 auto overloadedOperatorType = Callee->getOverloadedOperator();
326 if (overloadedOperatorType == OO_EqualEqual ||
327 overloadedOperatorType == OO_ExclaimEqual ||
328 overloadedOperatorType == OO_LessEqual ||
329 overloadedOperatorType == OO_GreaterEqual ||
330 overloadedOperatorType == OO_Spaceship ||
331 overloadedOperatorType == OO_AmpAmp ||
332 overloadedOperatorType == OO_PipePipe)
333 return true;
334
335 if (isCtorOfSafePtr(Callee) || isPtrConversion(Callee))
336 return true;
337
338 auto name = safeGetName(Callee);
339 if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
340 name == "is" || name == "equal" || name == "hash" || name == "isType" ||
341 // FIXME: Most/all of these should be implemented via attributes.
342 name == "CFEqual" || name == "equalIgnoringASCIICase" ||
343 name == "equalIgnoringASCIICaseCommon" ||
344 name == "equalIgnoringNullity" || name == "toString")
345 return true;
346
347 return false;
348 }
349
350 bool isMethodOnWTFContainerType(const FunctionDecl *Decl) const {
351 if (!isa<CXXMethodDecl>(Decl))
352 return false;
353 auto *ClassDecl = Decl->getParent();
354 if (!ClassDecl || !isa<CXXRecordDecl>(ClassDecl))
355 return false;
356
357 auto *NsDecl = ClassDecl->getParent();
358 if (!NsDecl || !isa<NamespaceDecl>(NsDecl))
359 return false;
360
361 auto MethodName = safeGetName(Decl);
362 auto ClsNameStr = safeGetName(ClassDecl);
363 StringRef ClsName = ClsNameStr; // FIXME: Make safeGetName return StringRef.
364 auto NamespaceName = safeGetName(NsDecl);
365 // FIXME: These should be implemented via attributes.
366 return NamespaceName == "WTF" &&
367 (MethodName == "find" || MethodName == "findIf" ||
368 MethodName == "reverseFind" || MethodName == "reverseFindIf" ||
369 MethodName == "findIgnoringASCIICase" || MethodName == "get" ||
370 MethodName == "inlineGet" || MethodName == "contains" ||
371 MethodName == "containsIf" ||
372 MethodName == "containsIgnoringASCIICase" ||
373 MethodName == "startsWith" || MethodName == "endsWith" ||
374 MethodName == "startsWithIgnoringASCIICase" ||
375 MethodName == "endsWithIgnoringASCIICase" ||
376 MethodName == "substring") &&
377 (ClsName.ends_with("Vector") || ClsName.ends_with("Set") ||
378 ClsName.ends_with("Map") || ClsName == "StringImpl" ||
379 ClsName.ends_with("String"));
380 }
381
382 void reportBug(const NamedDecl *Callee, const Expr *CallArg,
383 const ParmVarDecl *Param, const Decl *DeclWithIssue) const {
384 assert(CallArg);
385
386 SmallString<100> Buf;
387 llvm::raw_svector_ostream Os(Buf);
388
389 const std::string paramName = safeGetName(Param);
390 Os << "Function argument";
391 printArgument(Os, CallArg);
392 if (!paramName.empty() || Callee)
393 Os << " (";
394 if (!paramName.empty()) {
395 Os << "parameter ";
396 printQuotedQualifiedName(Os, Param);
397 }
398 if (Callee) {
399 if (!paramName.empty())
400 Os << " ";
401 Os << "to ";
402 printQuotedQualifiedName(Os, Callee);
403 }
404 if (!paramName.empty() || Callee)
405 Os << ")";
406 Os << " is a ";
407 auto *ArgType = CallArg->getType().getTypePtr();
408
409 if (printPointer(Os, ArgType) == PrintDeclKind::Pointer) {
410 auto *RTC = Model->retainTypeChecker();
411 assert(RTC);
412 if (auto *Decl = RTC->getCanonicalDecl(CallArg->getType())) {
413 printQuotedQualifiedName(Os, Decl);
414 } else {
415 auto Typedef = ArgType->getAs<TypedefType>();
416 assert(Typedef);
417 printQuotedQualifiedName(Os, Typedef->getDecl());
418 }
419 } else {
420 Os << " ";
421 printTypeName(Os, CallArg->getType());
422 }
423
424 bool usesDefaultArgValue = isa<CXXDefaultArgExpr>(CallArg) && Param;
425 const SourceLocation SrcLocToReport =
426 usesDefaultArgValue ? Param->getDefaultArg()->getExprLoc()
427 : CallArg->getSourceRange().getBegin();
428
429 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
430 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
431 Report->addRange(CallArg->getSourceRange());
432 Report->setDeclWithIssue(DeclWithIssue);
433 BR->emitReport(std::move(Report));
434 }
435
436 void reportBugOnThis(const NamedDecl *Callee, const Expr *CallArg,
437 const Decl *DeclWithIssue) const {
438 assert(CallArg);
439
440 const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
441
442 SmallString<100> Buf;
443 llvm::raw_svector_ostream Os(Buf);
444 Os << "Function argument";
445 printArgument(Os, CallArg);
446 Os << " (parameter 'this'";
447 if (Callee) {
448 Os << " to ";
449 printQuotedQualifiedName(Os, Callee);
450 }
451 Os << ") is a raw pointer to " << Model->typeName() << " ";
452 printTypeName(Os, CallArg->getType());
453
454 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
455 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
456 Report->addRange(CallArg->getSourceRange());
457 Report->setDeclWithIssue(DeclWithIssue);
458 BR->emitReport(std::move(Report));
459 }
460
461 void reportBugOnReceiver(const NamedDecl *Callee, const Expr *CallArg,
462 const Decl *DeclWithIssue) const {
463 assert(CallArg);
464
465 const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
466
467 SmallString<100> Buf;
468 llvm::raw_svector_ostream Os(Buf);
469 Os << "Receiver";
470 printArgument(Os, CallArg);
471 if (Callee) {
472 Os << " (to ";
473 printQuotedQualifiedName(Os, Callee);
474 Os << ")";
475 }
476 Os << " is a raw pointer to " << Model->typeName() << " ";
477 printTypeName(Os, CallArg->getType());
478
479 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
480 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
481 Report->addRange(CallArg->getSourceRange());
482 Report->setDeclWithIssue(DeclWithIssue);
483 BR->emitReport(std::move(Report));
484 }
485
486 void printArgument(llvm::raw_svector_ostream &Os, const Expr *Arg) const {
487 SmallString<100> Buf;
488 llvm::raw_svector_ostream ArgOs(Buf);
489 Arg->printPretty(ArgOs, /*Helper=*/nullptr,
490 BR->getContext().getPrintingPolicy());
491 StringRef ArgCode = ArgOs.str();
492 if (ArgCode.contains('\n'))
493 return;
494 ArgCode = ArgCode.take_front(50);
495 if (ArgCode.size() == 50)
496 Os << " '" << ArgCode << "...'";
497 else
498 Os << " '" << ArgCode << "'";
499 }
500
501 enum class PrintDeclKind { Pointee, Pointer };
502 PrintDeclKind printPointer(llvm::raw_svector_ostream &Os,
503 const Type *T) const {
504 // Retain/OS types are frequently spelled through a typedef (e.g. CFXXXRef);
505 // print the typedef name rather than desugaring to the pointee.
506 if (Model->retainTypeChecker() && isa<TypedefType>(T)) {
507 Os << Model->typeName() << " ";
508 return PrintDeclKind::Pointer;
509 }
512 Os << "raw " << (IsPtr ? "pointer" : "reference") << " to "
513 << Model->typeName();
514 return PrintDeclKind::Pointee;
515 }
516};
517
518class UncountedCallArgsChecker final : public RawPtrRefCallArgsChecker {
519public:
520 UncountedCallArgsChecker()
521 : RawPtrRefCallArgsChecker("Uncounted call argument for a raw "
522 "pointer/reference parameter",
524};
525
526class UncheckedCallArgsChecker final : public RawPtrRefCallArgsChecker {
527public:
528 UncheckedCallArgsChecker()
529 : RawPtrRefCallArgsChecker("Unchecked call argument for a raw "
530 "pointer/reference parameter",
532};
533
534class UnretainedCallArgsChecker final : public RawPtrRefCallArgsChecker {
535public:
536 UnretainedCallArgsChecker()
537 : RawPtrRefCallArgsChecker("Unretained call argument for a raw "
538 "pointer/reference parameter",
540};
541
542} // namespace
543
544void ento::registerUncountedCallArgsChecker(CheckerManager &Mgr) {
545 Mgr.registerChecker<UncountedCallArgsChecker>();
546}
547
548bool ento::shouldRegisterUncountedCallArgsChecker(const CheckerManager &) {
549 return true;
550}
551
552void ento::registerUncheckedCallArgsChecker(CheckerManager &Mgr) {
553 Mgr.registerChecker<UncheckedCallArgsChecker>();
554}
555
556bool ento::shouldRegisterUncheckedCallArgsChecker(const CheckerManager &) {
557 return true;
558}
559
560void ento::registerUnretainedCallArgsChecker(CheckerManager &Mgr) {
561 Mgr.registerChecker<UnretainedCallArgsChecker>();
562}
563
564bool ento::shouldRegisterUnretainedCallArgsChecker(const CheckerManager &) {
565 return true;
566}
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Record Record
Definition MachO.h:31
Defines the clang::SourceLocation class and associated facilities.
static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP, llvm::raw_ostream &OS, bool IncludeType)
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1614
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
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3153
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3132
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3140
Decl * getCalleeDecl()
Definition Expr.h:3126
virtual bool TraverseDecl(MaybeConst< Decl > *D)
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
QualType getType() const
Definition Expr.h:144
param_iterator param_begin()
Definition Decl.h:2826
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition ExprObjC.h:1436
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition ExprObjC.h:1301
Selector getSelector() const
Definition ExprObjC.cpp:301
const ObjCMethodDecl * getMethodDecl() const
Definition ExprObjC.h:1397
QualType getReceiverType() const
Retrieve the receiver type to which this message is being directed.
Definition ExprObjC.cpp:308
unsigned getNumArgs() const
Return the number of actual arguments in this message, not counting the receiver.
Definition ExprObjC.h:1423
Expr * getDefaultArg()
Definition Decl.cpp:2989
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8495
QualType getCanonicalType() const
Definition TypeBase.h:8547
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
SourceLocation getBegin() const
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9325
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition Type.cpp:690
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
Definition Checker.h:565
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
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
bool isPtrConversion(const FunctionDecl *F)
std::unique_ptr< PtrRefSafetyModel > makeCheckedPtrSafetyModel()
void printQuotedQualifiedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, std::function< bool(const clang::CXXRecordDecl *)> isSafePtr, std::function< bool(const clang::QualType)> isSafePtrType, std::function< bool(const clang::Decl *)> isSafeGlobalDecl, std::function< bool(const clang::Expr *, bool)> callback)
This function de-facto defines a set of transformations that we consider safe (in heuristical sense).
Definition ASTUtils.cpp:25
bool isASafeCallArg(const Expr *E)
For E referring to a ref-countable/-counted pointer/reference we return whether it's a safe call argu...
Definition ASTUtils.cpp:247
const FunctionProtoType * T
bool isSmartPtrClass(const std::string &Name)
@ Type
The name was classified as a type.
Definition Sema.h:564
void printTypeName(llvm::raw_ostream &Os, const QualType QT)
std::string safeGetName(const T *ASTNode)
Definition ASTUtils.h:98
bool isNullPtr(const clang::Expr *E)
Definition ASTUtils.cpp:287
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
std::unique_ptr< PtrRefSafetyModel > makeRefPtrSafetyModel()
bool isAllocInit(const Expr *E, const Expr **InnerExpr)
Definition ASTUtils.cpp:341
std::unique_ptr< PtrRefSafetyModel > makeRetainPtrSafetyModel()