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 // A template pattern is checked through its instantiations, which are
74 // traversed from the TemplateDecl itself. In the pattern the callee of
75 // a call may still be an unresolved overload set and the type of an
76 // expression may still be dependent, neither of which can be reasoned
77 // about, so don't enter it at all.
78 if (D && !isa<TemplateDecl>(D) && D->isTemplated())
79 return true;
80 llvm::SaveAndRestore SavedDecl(DeclWithIssue);
81 if (D && (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)))
82 DeclWithIssue = D;
84 }
85
86 bool TraverseLambdaExpr(LambdaExpr *L) override {
88 if (!FTD)
89 return DynamicRecursiveASTVisitor::TraverseLambdaExpr(L);
90 // The body of a generic lambda is the pattern of its call operator,
91 // but it is reached from the LambdaExpr as a statement, so TraverseDecl
92 // never gets to skip it. Traverse the capture initializers, which are
93 // evaluated in the enclosing scope, and then the call operator itself,
94 // of which the pattern is skipped like any other and the instantiations
95 // are traversed. The initializers are traversed as expressions because
96 // the variable of an init capture is declared in the pattern.
97 for (unsigned I = 0, N = L->capture_size(); I != N; ++I) {
98 if (!(L->capture_begin() + I)->isExplicit())
99 continue;
100 if (auto *Init = L->capture_init_begin()[I];
101 Init && !TraverseStmt(Init))
102 return false;
103 }
104 return TraverseDecl(FTD);
105 }
106
107 bool VisitCallExpr(CallExpr *CE) override {
108 Checker->visitCallExpr(CE, DeclWithIssue);
109 return true;
110 }
111
112 bool VisitCXXConstructExpr(CXXConstructExpr *CE) override {
113 Checker->visitConstructExpr(CE, DeclWithIssue);
114 return true;
115 }
116
117 bool VisitTypedefDecl(TypedefDecl *TD) override {
118 if (auto *RTC = Checker->Model->retainTypeChecker())
119 RTC->visitTypedef(TD);
120 return true;
121 }
122
123 bool VisitObjCMessageExpr(ObjCMessageExpr *ObjCMsgExpr) override {
124 Checker->visitObjCMessageExpr(ObjCMsgExpr, DeclWithIssue);
125 return true;
126 }
127 };
128
129 LocalVisitor visitor(this);
130 if (auto *RTC = Model->retainTypeChecker())
131 RTC->visitTranslationUnitDecl(TUD);
132 visitor.TraverseDecl(const_cast<TranslationUnitDecl *>(TUD));
133 }
134
135 template <typename CallOrConstruct>
136 void visitCallOrConstructExpr(const CallOrConstruct *CE,
137 const FunctionDecl *F, const Decl *D) const {
138 if (F) {
139 unsigned ArgIdx = 0;
140 if (auto *MemberCallExpr = dyn_cast<CXXMemberCallExpr>(CE)) {
141 checkThisArg(F, MemberCallExpr, D);
142 } else if (isa<CXXOperatorCallExpr>(CE) && isa<CXXMethodDecl>(F)) {
143 // An overloaded member operator (e.g. lambda or std::function call
144 // operator) receives the receiver object as argument 0; start the
145 // parameter loop at 1 so we don't match it against the operator's
146 // first declared parameter.
147 auto *Receiver = CE->getArg(0);
148 checkThisArg(F, Receiver, Receiver->getType(), D);
149 ArgIdx = 1;
150 }
151
152 for (auto P = F->param_begin();
153 P < F->param_end() && ArgIdx < CE->getNumArgs(); ++P, ++ArgIdx) {
154 // TODO: attributes.
155 // if ((*P)->hasAttr<SafeRefCntblRawPtrAttr>())
156 // continue;
157 checkArg(F, CE->getArg(ArgIdx), (*P)->getType(), *P, D);
158 }
159 for (; ArgIdx < CE->getNumArgs(); ++ArgIdx) {
160 auto *Arg = CE->getArg(ArgIdx);
161 checkArg(F, Arg, Arg->getType(), nullptr, D);
162 }
163 }
164 }
165
166 void visitCallExpr(const CallExpr *CE, const Decl *D) const {
167 auto *Callee = CE->getDirectCallee();
168 if (shouldSkipCall(CE, Callee))
169 return;
170
171 if (Callee)
172 visitCallOrConstructExpr(CE, Callee, D);
173 else if (auto *Decl = CE->getCalleeDecl()) {
174 if (auto *FnType = Decl->getFunctionType()) {
175 if (auto *ProtoType = dyn_cast<FunctionProtoType>(FnType)) {
176 if (auto *MemberCallExpr = dyn_cast<CXXMemberCallExpr>(CE))
177 checkThisArg(nullptr, MemberCallExpr, D);
178 unsigned ArgIdx = 0;
179 for (auto PT = ProtoType->param_type_begin();
180 PT < ProtoType->param_type_end() && ArgIdx < CE->getNumArgs();
181 ++PT, ++ArgIdx)
182 checkArg(nullptr, CE->getArg(ArgIdx), *PT, nullptr, D);
183 for (; ArgIdx < CE->getNumArgs(); ++ArgIdx) {
184 auto *Arg = CE->getArg(ArgIdx);
185 checkArg(nullptr, Arg, Arg->getType(), nullptr, D);
186 }
187 }
188 }
189 }
190 }
191
192 void visitConstructExpr(const CXXConstructExpr *CE, const Decl *D) const {
193 auto *Constructor = CE->getConstructor();
194 if (shouldSkipCall(CE, Constructor))
195 return;
196 if (Constructor)
197 visitCallOrConstructExpr(CE, Constructor, D);
198 }
199
200 void visitObjCMessageExpr(const ObjCMessageExpr *E, const Decl *D) const {
201 if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
202 return;
203
204 if (auto *Receiver = E->getInstanceReceiver()) {
205 std::optional<bool> IsUnsafe = Model->isUnsafePtr(E->getReceiverType());
206 const Expr *Origin = nullptr;
207 if (IsUnsafe && *IsUnsafe &&
208 !isPtrOriginSafe(Receiver, &Origin, E->getReceiverType())) {
209 if (isAllocInit(E))
210 return;
211 reportBugOnReceiver(E->getMethodDecl(), Receiver, D, Origin);
212 }
213 }
214
215 auto *MethodDecl = E->getMethodDecl();
216 if (!MethodDecl)
217 return;
218
219 auto ArgCount = E->getNumArgs();
220 for (unsigned i = 0; i < ArgCount; ++i) {
221 auto *Arg = E->getArg(i);
222 bool hasParam = i < MethodDecl->param_size();
223 auto *Param = hasParam ? MethodDecl->getParamDecl(i) : nullptr;
224 auto ArgType = Arg->getType();
225 std::optional<bool> IsUnsafe = Model->isUnsafePtr(ArgType);
226 if (!IsUnsafe || !(*IsUnsafe))
227 continue;
228 const Expr *Origin = nullptr;
229 if (isPtrOriginSafe(Arg, &Origin, ArgType))
230 continue;
231 reportBug(MethodDecl, Arg, Param, D, Origin);
232 }
233 }
234
235 static bool isRefCountingOperation(const CXXMethodDecl *MD) {
236 if (!MD)
237 return false;
238 auto name = safeGetName(MD);
239 return name == "ref" || name == "deref" ||
240 name == "incrementCheckedPtrCount" ||
241 name == "decrementCheckedPtrCount";
242 }
243
244 void checkThisArg(const NamedDecl *Callee,
245 const CXXMemberCallExpr *MemberCallExpr,
246 const Decl *DeclWithIssue) const {
247 if (isRefCountingOperation(MemberCallExpr->getMethodDecl()))
248 return;
249 checkThisArg(Callee, MemberCallExpr->getImplicitObjectArgument(),
250 MemberCallExpr->getObjectType(), DeclWithIssue);
251 }
252
253 void checkThisArg(const NamedDecl *Callee, const Expr *Receiver,
254 QualType ReceiverType, const Decl *DeclWithIssue) const {
255 // There is no ParmVarDecl for the implicit object parameter, so
256 // synthesize its type ('T&' per [over.match.funcs]) for the model to
257 // classify.
258 QualType ParamType = BR->getContext().getLValueReferenceType(
259 ReceiverType.getCanonicalType());
260 std::optional<bool> IsUnsafe = Model->isUnsafePtr(ParamType);
261 if (!IsUnsafe || !*IsUnsafe)
262 return;
263
264 const Expr *Origin = nullptr;
265 if (isPtrOriginSafe(Receiver, &Origin, ParamType))
266 return;
267
268 reportBugOnThis(Callee, Receiver, DeclWithIssue, Origin);
269 }
270
271 void checkArg(const NamedDecl *Callee, const Expr *Arg, QualType ParamType,
272 const ParmVarDecl *Param, const Decl *DeclWithIssue) const {
273 std::optional<bool> IsUncounted = Model->isUnsafePtr(ParamType);
274 if (!IsUncounted || !(*IsUncounted))
275 return;
276
277 if (auto *DefaultArg = dyn_cast<CXXDefaultArgExpr>(Arg))
278 Arg = DefaultArg->getExpr();
279
280 const Expr *Origin = nullptr;
281 if (isPtrOriginSafe(Arg, &Origin, ParamType))
282 return;
283
284 reportBug(Callee, Arg, Param, DeclWithIssue, Origin);
285 }
286
287 bool isPtrOriginSafe(const Expr *Arg, const Expr **Origin = nullptr,
288 QualType SinkType = QualType()) const {
289 return tryToFindPtrOrigin(
290 Arg, /*StopAtFirstRefCountedObj=*/true,
291 Model->checksForInteriorDestruction(),
292 [&](const clang::CXXRecordDecl *Record) {
293 return Model->isSafePtr(Record);
294 },
295 [&](const clang::QualType T) { return Model->isSafePtrType(T); },
296 [&](const clang::Decl *D) {
297 return Model->isSafeDecl(D, BR->getSourceManager());
298 },
299 // A temporary on the path to an argument's origin is safe: the full
300 // expression does not end until the call returns.
301 [&](const clang::Expr *ArgOrigin, bool IsSafe,
302 bool /*OriginDependsOnFullExpressionTemporary*/,
303 bool PtrIsLifetimeBoundToOrigin) {
304 if (IsSafe)
305 return true;
306 if (isNullPtr(ArgOrigin))
307 return true;
308 if (isa<IntegerLiteral>(ArgOrigin)) {
309 // FIXME: Check the value.
310 // foo(123)
311 return true;
312 }
313 if (isa<CXXBoolLiteralExpr>(ArgOrigin))
314 return true;
315 if (isa<ObjCStringLiteral>(ArgOrigin))
316 return true;
317 if (!Model->checksForInteriorDestruction() &&
318 originOutlivesCall(ArgOrigin))
319 return true;
320 if (EFA.isACallToEnsureFn(ArgOrigin)) {
321 auto *MCE = dyn_cast<CXXMemberCallExpr>(ArgOrigin);
322 assert(MCE);
323 if (isPtrOriginSafe(MCE->getImplicitObjectArgument()))
324 return true;
325 }
326 if (Model->isSafeExpr(ArgOrigin, PtrIsLifetimeBoundToOrigin, SinkType,
327 /*SinkMayEscape=*/false))
328 return true;
329 if (Origin && !*Origin)
330 *Origin = ArgOrigin;
331 return false;
332 });
333 }
334
335 template <typename CallOrConstruct>
336 bool shouldSkipCall(const CallOrConstruct *CE,
337 const FunctionDecl *Callee) const {
338 if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
339 return true;
340
341 if (Callee && TFA.isTrivial(Callee))
342 return true;
343
344 if (isTrivialBuiltinFunction(Callee))
345 return true;
346
347 if (CE->getNumArgs() == 0)
348 return false;
349
350 // If an assignment is problematic we should warn about the sole existence
351 // of object on LHS.
352 if (auto *MemberOp = dyn_cast<CXXOperatorCallExpr>(CE)) {
353 // Note: assignemnt to built-in type isn't derived from CallExpr.
354 if (MemberOp->getOperator() ==
355 OO_Equal) { // Ignore assignment to Ref/RefPtr.
356 auto *callee = MemberOp->getDirectCallee();
357 if (auto *calleeDecl = dyn_cast<CXXMethodDecl>(callee)) {
358 if (const CXXRecordDecl *classDecl = calleeDecl->getParent()) {
359 if (Model->isSafePtr(classDecl))
360 return true;
361 }
362 }
363 }
364 if (MemberOp->isAssignmentOp())
365 return false;
366 }
367
368 if (!Callee)
369 return false;
370
371 if (isMethodOnWTFContainerType(Callee))
372 return true;
373
374 auto overloadedOperatorType = Callee->getOverloadedOperator();
375 if (overloadedOperatorType == OO_EqualEqual ||
376 overloadedOperatorType == OO_ExclaimEqual ||
377 overloadedOperatorType == OO_LessEqual ||
378 overloadedOperatorType == OO_GreaterEqual ||
379 overloadedOperatorType == OO_Spaceship ||
380 overloadedOperatorType == OO_AmpAmp ||
381 overloadedOperatorType == OO_PipePipe)
382 return true;
383
384 if (isCtorOfSafePtr(Callee) || isPtrConversion(Callee))
385 return true;
386
387 auto name = safeGetName(Callee);
388 if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
389 name == "is" || name == "equal" || name == "hash" || name == "isType" ||
390 // FIXME: Most/all of these should be implemented via attributes.
391 name == "CFEqual" || name == "equalIgnoringASCIICase" ||
392 name == "equalIgnoringASCIICaseCommon" ||
393 name == "equalIgnoringNullity" || name == "toString")
394 return true;
395
396 return false;
397 }
398
399 bool isMethodOnWTFContainerType(const FunctionDecl *Decl) const {
401 return false;
402 auto *ClassDecl = Decl->getParent();
403 if (!ClassDecl || !isa<CXXRecordDecl>(ClassDecl))
404 return false;
405
406 auto *NsDecl = ClassDecl->getParent();
407 if (!NsDecl || !isa<NamespaceDecl>(NsDecl))
408 return false;
409
410 auto MethodName = safeGetName(Decl);
411 auto ClsNameStr = safeGetName(ClassDecl);
412 StringRef ClsName = ClsNameStr; // FIXME: Make safeGetName return StringRef.
413 auto NamespaceName = safeGetName(NsDecl);
414 // FIXME: These should be implemented via attributes.
415 return NamespaceName == "WTF" &&
416 (MethodName == "find" || MethodName == "findIf" ||
417 MethodName == "reverseFind" || MethodName == "reverseFindIf" ||
418 MethodName == "findIgnoringASCIICase" || MethodName == "get" ||
419 MethodName == "inlineGet" || MethodName == "contains" ||
420 MethodName == "containsIf" ||
421 MethodName == "containsIgnoringASCIICase" ||
422 MethodName == "startsWith" || MethodName == "endsWith" ||
423 MethodName == "startsWithIgnoringASCIICase" ||
424 MethodName == "endsWithIgnoringASCIICase" ||
425 MethodName == "substring") &&
426 (ClsName.ends_with("Vector") || ClsName.ends_with("Set") ||
427 ClsName.ends_with("Map") || ClsName == "StringImpl" ||
428 ClsName.ends_with("String"));
429 }
430
431 void reportBug(const NamedDecl *Callee, const Expr *CallArg,
432 const ParmVarDecl *Param, const Decl *DeclWithIssue,
433 const Expr *Origin) const {
434 assert(CallArg);
435
437 llvm::raw_svector_ostream Os(Buf);
438
439 const std::string paramName = safeGetName(Param);
440 Os << "Function argument";
441 printArgument(Os, CallArg);
442 if (!paramName.empty() || Callee)
443 Os << " (";
444 if (!paramName.empty()) {
445 Os << "parameter ";
446 printQuotedQualifiedName(Os, Param);
447 }
448 if (Callee) {
449 if (!paramName.empty())
450 Os << " ";
451 Os << "to ";
452 printQuotedQualifiedName(Os, Callee);
453 }
454 if (!paramName.empty() || Callee)
455 Os << ")";
456 Os << " is a ";
457 Model->describeHazard(Os, Origin, CallArg->getType());
458
459 bool usesDefaultArgValue = isa<CXXDefaultArgExpr>(CallArg) && Param;
460 const SourceLocation SrcLocToReport =
461 usesDefaultArgValue ? Param->getDefaultArg()->getExprLoc()
462 : CallArg->getSourceRange().getBegin();
463
464 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
465 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
466 Report->addRange(CallArg->getSourceRange());
467 Report->setDeclWithIssue(DeclWithIssue);
468 BR->emitReport(std::move(Report));
469 }
470
471 void reportBugOnThis(const NamedDecl *Callee, const Expr *CallArg,
472 const Decl *DeclWithIssue, const Expr *Origin) const {
473 assert(CallArg);
474
475 const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
476
478 llvm::raw_svector_ostream Os(Buf);
479 Os << "Function argument";
480 printArgument(Os, CallArg);
481 Os << " (parameter 'this'";
482 if (Callee) {
483 Os << " to ";
484 printQuotedQualifiedName(Os, Callee);
485 }
486 Os << ") is a ";
487 printHazardOrPointerTo(Os, CallArg, Origin);
488
489 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
490 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
491 Report->addRange(CallArg->getSourceRange());
492 Report->setDeclWithIssue(DeclWithIssue);
493 BR->emitReport(std::move(Report));
494 }
495
496 void reportBugOnReceiver(const NamedDecl *Callee, const Expr *CallArg,
497 const Decl *DeclWithIssue,
498 const Expr *Origin) const {
499 assert(CallArg);
500
501 const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
502
504 llvm::raw_svector_ostream Os(Buf);
505 Os << "Receiver";
506 printArgument(Os, CallArg);
507 if (Callee) {
508 Os << " (to ";
509 printQuotedQualifiedName(Os, Callee);
510 Os << ")";
511 }
512 Os << " is a ";
513 printHazardOrPointerTo(Os, CallArg, Origin);
514
515 PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
516 auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
517 Report->addRange(CallArg->getSourceRange());
518 Report->setDeclWithIssue(DeclWithIssue);
519 BR->emitReport(std::move(Report));
520 }
521
522 void printHazardOrPointerTo(llvm::raw_svector_ostream &Os,
523 const Expr *CallArg, const Expr *Origin) const {
524 if (Model->checksForInteriorDestruction()) {
525 Model->describeHazard(Os, Origin, CallArg->getType());
526 return;
527 }
528 // 'this' is a pointer even when the call is spelled with '.', so don't
529 // infer pointer vs reference from the argument type.
530 Os << "raw pointer to " << Model->typeName() << " ";
531 printTypeName(Os, CallArg->getType());
532 }
533
534 void printArgument(llvm::raw_svector_ostream &Os, const Expr *Arg) const {
536 llvm::raw_svector_ostream ArgOs(Buf);
537 Arg->printPretty(ArgOs, /*Helper=*/nullptr,
539 StringRef ArgCode = ArgOs.str();
540 if (ArgCode.contains('\n'))
541 return;
542 ArgCode = ArgCode.take_front(50);
543 if (ArgCode.size() == 50)
544 Os << " '" << ArgCode << "...'";
545 else
546 Os << " '" << ArgCode << "'";
547 }
548};
549
550class UncountedCallArgsChecker final : public RawPtrRefCallArgsChecker {
551public:
552 UncountedCallArgsChecker()
553 : RawPtrRefCallArgsChecker("Uncounted call argument for a raw "
554 "pointer/reference parameter",
556};
557
558class UncheckedCallArgsChecker final : public RawPtrRefCallArgsChecker {
559public:
560 UncheckedCallArgsChecker()
561 : RawPtrRefCallArgsChecker("Unchecked call argument for a raw "
562 "pointer/reference parameter",
564};
565
566class UnretainedCallArgsChecker final : public RawPtrRefCallArgsChecker {
567public:
568 UnretainedCallArgsChecker()
569 : RawPtrRefCallArgsChecker("Unretained call argument for a raw "
570 "pointer/reference parameter",
572};
573
574class UnborrowedCallArgsChecker final : public RawPtrRefCallArgsChecker {
575public:
576 UnborrowedCallArgsChecker()
577 : RawPtrRefCallArgsChecker("Unborrowed call argument for a raw "
578 "pointer/reference parameter",
580};
581
582} // namespace
583
584void ento::registerUncountedCallArgsChecker(CheckerManager &Mgr) {
585 Mgr.registerChecker<UncountedCallArgsChecker>();
586}
587
588bool ento::shouldRegisterUncountedCallArgsChecker(const CheckerManager &) {
589 return true;
590}
591
592void ento::registerUncheckedCallArgsChecker(CheckerManager &Mgr) {
593 Mgr.registerChecker<UncheckedCallArgsChecker>();
594}
595
596bool ento::shouldRegisterUncheckedCallArgsChecker(const CheckerManager &) {
597 return true;
598}
599
600void ento::registerUnretainedCallArgsChecker(CheckerManager &Mgr) {
601 Mgr.registerChecker<UnretainedCallArgsChecker>();
602}
603
604bool ento::shouldRegisterUnretainedCallArgsChecker(const CheckerManager &) {
605 return true;
606}
607
608void ento::registerUnborrowedCallArgsChecker(CheckerManager &Mgr) {
609 Mgr.registerChecker<UnborrowedCallArgsChecker>();
610}
611
612bool ento::shouldRegisterUnborrowedCallArgsChecker(const CheckerManager &) {
613 return true;
614}
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)
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:905
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Definition ExprCXX.h:1616
CXXMethodDecl * getMethodDecl() const
Retrieve the declaration of the called method.
Definition ExprCXX.cpp:773
Expr * getImplicitObjectArgument() const
Retrieve the implicit object argument for the member call.
Definition ExprCXX.cpp:754
QualType getObjectType() const
Retrieve the type of the object argument.
Definition ExprCXX.cpp:766
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
FunctionTemplateDecl * getDependentLambdaCallOperator() const
Retrieve the dependent lambda call operator of the closure type if this is a templated closure type.
Definition DeclCXX.cpp:1739
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3216
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
Definition Expr.h:3195
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3203
Decl * getCalleeDecl()
Definition Expr.h:3189
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2122
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
Definition DeclBase.cpp:308
virtual bool TraverseDecl(MaybeConst< Decl > *D)
This represents one expression.
Definition Expr.h:114
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:146
Represents a function declaration or definition.
Definition Decl.h:2071
param_iterator param_begin()
Definition Decl.h:2929
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1395
unsigned capture_size() const
Determine the number of captures in this lambda.
Definition ExprCXX.h:2054
capture_init_iterator capture_init_begin()
Retrieve the first initialization argument for this lambda expression (which initializes the first ca...
Definition ExprCXX.h:2099
CXXRecordDecl * getLambdaClass() const
Retrieve the class that corresponds to the lambda.
Definition ExprCXX.cpp:1432
This represents a decl that may have a name.
Definition Decl.h:276
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition ExprObjC.h:1435
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Definition ExprObjC.h:1300
const ObjCMethodDecl * getMethodDecl() const
Definition ExprObjC.h:1396
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:1422
Represents a parameter to a function.
Definition Decl.h:1832
QualType getCanonicalType() const
Definition TypeBase.h:8498
Encodes a location in the source.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
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
bool isTrivial(const Decl *D) const
const SourceManager & getSourceManager()
ASTContext & getContext()
virtual void emitReport(std::unique_ptr< BugReport > R)
Add the given report to the set of reports tracked by BugReporter.
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...
Top level wrappers for InstallAPI frontend operations.
bool isCtorOfSafePtr(const clang::FunctionDecl *F)
bool isTrivialBuiltinFunction(const FunctionDecl *F)
bool isa(CodeGen::Address addr)
Definition Address.h:330
std::unique_ptr< PtrRefSafetyModel > makeBorrowSafetyModel()
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
bool isPtrConversion(const FunctionDecl *F)
std::unique_ptr< PtrRefSafetyModel > makeCheckedPtrSafetyModel()
void printQuotedQualifiedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
const FunctionProtoType * T
bool isSmartPtrClass(const std::string &Name)
bool originOutlivesCall(const Expr *E)
For E referring to a ref-countable/-counted pointer/reference we return whether the pointee outlives ...
Definition ASTUtils.cpp:495
void printTypeName(llvm::raw_ostream &Os, const QualType QT)
std::string safeGetName(const T *ASTNode)
Definition ASTUtils.h:109
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
std::unique_ptr< PtrRefSafetyModel > makeRefPtrSafetyModel()
bool tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj, bool FollowLifetimeBound, 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, bool, bool)> callback)
This function de-facto defines a set of transformations that we consider safe (in heuristical sense).
Definition ASTUtils.cpp:478
bool isAllocInit(const Expr *E, const Expr **InnerExpr)
Definition ASTUtils.cpp:589
std::unique_ptr< PtrRefSafetyModel > makeRetainPtrSafetyModel()