clang
20.0.0git
lib
StaticAnalyzer
Checkers
NoOwnershipChangeVisitor.h
Go to the documentation of this file.
1
//===--------------------------------------------------------------*- 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 "
clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
"
10
#include "
clang/StaticAnalyzer/Core/Checker.h
"
11
#include "
clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h
"
12
13
namespace
clang
{
14
namespace
ento {
15
16
class
NoOwnershipChangeVisitor
:
public
NoStateChangeFuncVisitor
{
17
protected
:
18
// The symbol whose (lack of) ownership change we are interested in.
19
SymbolRef
Sym
;
20
const
CheckerBase
&
Checker
;
21
22
LLVM_DUMP_METHOD
static
std::string
23
getFunctionName
(
const
ExplodedNode
*CallEnterN);
24
25
/// Heuristically guess whether the callee intended to free the resource. This
26
/// is done syntactically, because we are trying to argue about alternative
27
/// paths of execution, and as a consequence we don't have path-sensitive
28
/// information.
29
virtual
bool
doesFnIntendToHandleOwnership
(
const
Decl
*Callee,
30
ASTContext
&ACtx) = 0;
31
32
virtual
bool
hasResourceStateChanged
(
ProgramStateRef
CallEnterState,
33
ProgramStateRef
CallExitEndState) = 0;
34
35
bool
wasModifiedInFunction
(
const
ExplodedNode
*CallEnterN,
36
const
ExplodedNode
*CallExitEndN)
final
;
37
38
virtual
PathDiagnosticPieceRef
emitNote
(
const
ExplodedNode
*N) = 0;
39
40
PathDiagnosticPieceRef
maybeEmitNoteForObjCSelf
(
PathSensitiveBugReport
&R,
41
const
ObjCMethodCall
&
Call
,
42
const
ExplodedNode
*N)
final
{
43
// TODO: Implement.
44
return
nullptr
;
45
}
46
47
PathDiagnosticPieceRef
maybeEmitNoteForCXXThis
(
PathSensitiveBugReport
&R,
48
const
CXXConstructorCall
&
Call
,
49
const
ExplodedNode
*N)
final
{
50
// TODO: Implement.
51
return
nullptr
;
52
}
53
54
// Set this to final, effectively dispatch to emitNote.
55
PathDiagnosticPieceRef
56
maybeEmitNoteForParameters
(
PathSensitiveBugReport
&R,
const
CallEvent
&
Call
,
57
const
ExplodedNode
*N)
final
;
58
59
public
:
60
using
OwnerSet
=
llvm::SmallPtrSet<const MemRegion *, 8>
;
61
62
private
:
63
OwnerSet
getOwnersAtNode(
const
ExplodedNode
*N);
64
65
public
:
66
NoOwnershipChangeVisitor
(
SymbolRef
Sym
,
const
CheckerBase
*
Checker
)
67
:
NoStateChangeFuncVisitor
(bugreporter::TrackingKind::Thorough),
Sym
(
Sym
),
68
Checker
(*
Checker
) {}
69
70
void
Profile
(llvm::FoldingSetNodeID &
ID
)
const override
{
71
static
int
Tag = 0;
72
ID
.AddPointer(&Tag);
73
ID
.AddPointer(
Sym
);
74
}
75
};
76
}
// namespace ento
77
}
// namespace clang
ID
static char ID
Definition:
Arena.cpp:183
BugReporterVisitors.h
Checker.h
ProgramState_Fwd.h
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition:
ASTContext.h:187
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition:
DeclBase.h:86
clang::ento::CXXConstructorCall
Represents a call to a C++ constructor.
Definition:
CallEvent.h:979
clang::ento::CallEvent
Represents an abstract call to a function or method along a particular path.
Definition:
CallEvent.h:153
clang::ento::CheckerBase
Definition:
Checker.h:487
clang::ento::Checker
Definition:
Checker.h:512
clang::ento::ExplodedNode
Definition:
ExplodedGraph.h:66
clang::ento::NoOwnershipChangeVisitor
Definition:
NoOwnershipChangeVisitor.h:16
clang::ento::NoOwnershipChangeVisitor::getFunctionName
static LLVM_DUMP_METHOD std::string getFunctionName(const ExplodedNode *CallEnterN)
Definition:
NoOwnershipChangeVisitor.cpp:63
clang::ento::NoOwnershipChangeVisitor::maybeEmitNoteForObjCSelf
PathDiagnosticPieceRef maybeEmitNoteForObjCSelf(PathSensitiveBugReport &R, const ObjCMethodCall &Call, const ExplodedNode *N) final
Consume the information on the non-modifying stack frame in order to either emit a note or not.
Definition:
NoOwnershipChangeVisitor.h:40
clang::ento::NoOwnershipChangeVisitor::doesFnIntendToHandleOwnership
virtual bool doesFnIntendToHandleOwnership(const Decl *Callee, ASTContext &ACtx)=0
Heuristically guess whether the callee intended to free the resource.
clang::ento::NoOwnershipChangeVisitor::maybeEmitNoteForCXXThis
PathDiagnosticPieceRef maybeEmitNoteForCXXThis(PathSensitiveBugReport &R, const CXXConstructorCall &Call, const ExplodedNode *N) final
Consume the information on the non-modifying stack frame in order to either emit a note or not.
Definition:
NoOwnershipChangeVisitor.h:47
clang::ento::NoOwnershipChangeVisitor::Sym
SymbolRef Sym
Definition:
NoOwnershipChangeVisitor.h:19
clang::ento::NoOwnershipChangeVisitor::Checker
const CheckerBase & Checker
Definition:
NoOwnershipChangeVisitor.h:20
clang::ento::NoOwnershipChangeVisitor::Profile
void Profile(llvm::FoldingSetNodeID &ID) const override
Definition:
NoOwnershipChangeVisitor.h:70
clang::ento::NoOwnershipChangeVisitor::wasModifiedInFunction
bool wasModifiedInFunction(const ExplodedNode *CallEnterN, const ExplodedNode *CallExitEndN) final
Definition:
NoOwnershipChangeVisitor.cpp:71
clang::ento::NoOwnershipChangeVisitor::maybeEmitNoteForParameters
PathDiagnosticPieceRef maybeEmitNoteForParameters(PathSensitiveBugReport &R, const CallEvent &Call, const ExplodedNode *N) final
Consume the information on the non-modifying stack frame in order to either emit a note or not.
Definition:
NoOwnershipChangeVisitor.cpp:95
clang::ento::NoOwnershipChangeVisitor::NoOwnershipChangeVisitor
NoOwnershipChangeVisitor(SymbolRef Sym, const CheckerBase *Checker)
Definition:
NoOwnershipChangeVisitor.h:66
clang::ento::NoOwnershipChangeVisitor::emitNote
virtual PathDiagnosticPieceRef emitNote(const ExplodedNode *N)=0
clang::ento::NoOwnershipChangeVisitor::hasResourceStateChanged
virtual bool hasResourceStateChanged(ProgramStateRef CallEnterState, ProgramStateRef CallExitEndState)=0
clang::ento::NoStateChangeFuncVisitor
Put a diagnostic on return statement (or on } in its absence) of all inlined functions for which some...
Definition:
BugReporterVisitors.h:623
clang::ento::ObjCMethodCall
Represents any expression that calls an Objective-C method.
Definition:
CallEvent.h:1243
clang::ento::PathSensitiveBugReport
Definition:
BugReporter.h:289
clang::ento::SymExpr
Symbolic value.
Definition:
SymExpr.h:30
llvm::IntrusiveRefCntPtr< const ProgramState >
llvm::SmallPtrSet
Definition:
ASTContext.h:51
clang::ento::PathDiagnosticPieceRef
std::shared_ptr< PathDiagnosticPiece > PathDiagnosticPieceRef
Definition:
PathDiagnostic.h:492
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
clang::OMPDeclareReductionInitKind::Call
@ Call
Generated on Fri Nov 22 2024 09:50:39 for clang by
1.9.6