clang  10.0.0svn
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
clang::ento::BugReport Class Referenceabstract

This class provides an interface through which checkers can create individual bug reports. More...

#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"

Inheritance diagram for clang::ento::BugReport:
Inheritance graph
[legend]
Collaboration diagram for clang::ento::BugReport:
Collaboration graph
[legend]

Public Types

enum  Kind { Kind::Basic, Kind::PathSensitive }
 

Public Member Functions

virtual ~BugReport ()=default
 
Kind getKind () const
 
const BugTypegetBugType () const
 
StringRef getDescription () const
 A verbose warning message that is appropriate for displaying next to the source code that introduces the problem. More...
 
StringRef getShortDescription (bool UseFallback=true) const
 A short general warning message that is appropriate for displaying in the list of all reported bugs. More...
 
virtual PathDiagnosticLocation getLocation () const =0
 The primary location of the bug report that points at the undesirable behavior in the code. More...
 
virtual const DeclgetDeclWithIssue () const =0
 The smallest declaration that contains the bug location. More...
 
virtual PathDiagnosticLocation getUniqueingLocation () const =0
 Get the location on which the report should be uniqued. More...
 
virtual const DeclgetUniqueingDecl () const =0
 Get the declaration that corresponds to (usually contains) the uniqueing location. More...
 
void addNote (StringRef Msg, const PathDiagnosticLocation &Pos, ArrayRef< SourceRange > Ranges={})
 Add new item to the list of additional notes that need to be attached to this report. More...
 
ArrayRef< std::shared_ptr< PathDiagnosticNotePiece > > getNotes ()
 
void addRange (SourceRange R)
 Add a range to a bug report. More...
 
virtual ArrayRef< SourceRangegetRanges () const
 Get the SourceRanges associated with the report. More...
 
void addFixItHint (const FixItHint &F)
 Add a fix-it hint to the bug report. More...
 
llvm::ArrayRef< FixItHintgetFixits () const
 
virtual void Profile (llvm::FoldingSetNodeID &hash) const =0
 Reports are uniqued to ensure that we do not emit multiple diagnostics for each bug. More...
 

Protected Member Functions

 BugReport (Kind kind, const BugType &bt, StringRef desc)
 
 BugReport (Kind K, const BugType &BT, StringRef ShortDescription, StringRef Description)
 

Protected Attributes

Kind K
 
const BugTypeBT
 
std::string ShortDescription
 
std::string Description
 
SmallVector< SourceRange, 4 > Ranges
 
SmallVector< std::shared_ptr< PathDiagnosticNotePiece >, 4 > Notes
 
SmallVector< FixItHint, 4 > Fixits
 

Friends

class BugReportEquivClass
 
class BugReporter
 

Detailed Description

This class provides an interface through which checkers can create individual bug reports.

Definition at line 119 of file BugReporter.h.

Member Enumeration Documentation

◆ Kind

Enumerator
Basic 
PathSensitive 

Definition at line 121 of file BugReporter.h.

Constructor & Destructor Documentation

◆ BugReport() [1/2]

clang::ento::BugReport::BugReport ( Kind  kind,
const BugType bt,
StringRef  desc 
)
inlineprotected

Definition at line 136 of file BugReporter.h.

◆ BugReport() [2/2]

clang::ento::BugReport::BugReport ( Kind  K,
const BugType BT,
StringRef  ShortDescription,
StringRef  Description 
)
inlineprotected

Definition at line 139 of file BugReporter.h.

◆ ~BugReport()

virtual clang::ento::BugReport::~BugReport ( )
virtualdefault

Member Function Documentation

◆ addFixItHint()

void clang::ento::BugReport::addFixItHint ( const FixItHint F)
inline

Add a fix-it hint to the bug report.

Fix-it hints are the suggested edits to the code that would resolve the problem explained by the bug report. Fix-it hints should be as conservative as possible because it is not uncommon for the user to blindly apply all fixits to their project. Note that it is very hard to produce a good fix-it hint for most path-sensitive warnings.

Definition at line 240 of file BugReporter.h.

◆ addNote()

void clang::ento::BugReport::addNote ( StringRef  Msg,
const PathDiagnosticLocation Pos,
ArrayRef< SourceRange Ranges = {} 
)
inline

Add new item to the list of additional notes that need to be attached to this report.

If the report is path-sensitive, these notes will not be displayed as part of the execution path explanation, but will be displayed separately. Use bug visitors if you need to add an extra path note.

Definition at line 201 of file BugReporter.h.

References P.

◆ addRange()

void clang::ento::BugReport::addRange ( SourceRange  R)
inline

Add a range to a bug report.

Ranges are used to highlight regions of interest in the source code. They should be at the same source code line as the BugReport location. By default, the source range of the statement corresponding to the error node will be used; add a single invalid range to specify absence of ranges.

Definition at line 222 of file BugReporter.h.

References clang::SourceRange::isValid().

◆ getBugType()

const BugType& clang::ento::BugReport::getBugType ( ) const
inline

Definition at line 149 of file BugReporter.h.

◆ getDeclWithIssue()

virtual const Decl* clang::ento::BugReport::getDeclWithIssue ( ) const
pure virtual

The smallest declaration that contains the bug location.

This is purely cosmetic; the declaration can be displayed to the user but it does not affect whether the report is emitted.

Implemented in clang::ento::PathSensitiveBugReport, and clang::ento::BasicBugReport.

◆ getDescription()

StringRef clang::ento::BugReport::getDescription ( ) const
inline

A verbose warning message that is appropriate for displaying next to the source code that introduces the problem.

The description should be at least a full sentence starting with a capital letter. The period at the end of the warning is traditionally omitted. If the description consists of multiple sentences, periods between the sentences are encouraged, but the period at the end of the description is still omitted.

Definition at line 157 of file BugReporter.h.

◆ getFixits()

llvm::ArrayRef<FixItHint> clang::ento::BugReport::getFixits ( ) const
inline

Definition at line 244 of file BugReporter.h.

◆ getKind()

Kind clang::ento::BugReport::getKind ( ) const
inline

◆ getLocation()

virtual PathDiagnosticLocation clang::ento::BugReport::getLocation ( ) const
pure virtual

The primary location of the bug report that points at the undesirable behavior in the code.

UIs should attach the warning description to this location. The warning description should describe the bad behavior at this location.

Implemented in clang::ento::PathSensitiveBugReport, clang::ento::BasicBugReport, and clang::ento::retaincountchecker::RefLeakReport.

◆ getNotes()

ArrayRef<std::shared_ptr<PathDiagnosticNotePiece> > clang::ento::BugReport::getNotes ( )
inline

Definition at line 211 of file BugReporter.h.

◆ getRanges()

virtual ArrayRef<SourceRange> clang::ento::BugReport::getRanges ( ) const
inlinevirtual

Get the SourceRanges associated with the report.

Reimplemented in clang::ento::PathSensitiveBugReport, and clang::ento::retaincountchecker::RefCountReport.

Definition at line 229 of file BugReporter.h.

◆ getShortDescription()

StringRef clang::ento::BugReport::getShortDescription ( bool  UseFallback = true) const
inline

A short general warning message that is appropriate for displaying in the list of all reported bugs.

It should describe what kind of bug is found but does not need to try to go into details of that specific bug. Grammatical conventions of getDescription() apply here as well.

Definition at line 163 of file BugReporter.h.

◆ getUniqueingDecl()

virtual const Decl* clang::ento::BugReport::getUniqueingDecl ( ) const
pure virtual

Get the declaration that corresponds to (usually contains) the uniqueing location.

This is not actively used for uniqueing, i.e. otherwise identical reports that have different uniqueing decls will be considered equivalent.

Implemented in clang::ento::PathSensitiveBugReport, and clang::ento::BasicBugReport.

◆ getUniqueingLocation()

virtual PathDiagnosticLocation clang::ento::BugReport::getUniqueingLocation ( ) const
pure virtual

Get the location on which the report should be uniqued.

Two warnings are considered to be equivalent whenever they have the same bug types, descriptions, and uniqueing locations. Out of a class of equivalent warnings only one gets displayed to the user. For most warnings the uniqueing location coincides with their location, but sometimes it makes sense to use different locations. For example, a leak checker can place the warning at the location where the last reference to the leaking resource is dropped but at the same time unique the warning by where that resource is acquired (allocated).

Implemented in clang::ento::PathSensitiveBugReport, and clang::ento::BasicBugReport.

◆ Profile()

virtual void clang::ento::BugReport::Profile ( llvm::FoldingSetNodeID &  hash) const
pure virtual

Reports are uniqued to ensure that we do not emit multiple diagnostics for each bug.

Implemented in clang::ento::PathSensitiveBugReport, and clang::ento::BasicBugReport.

Friends And Related Function Documentation

◆ BugReportEquivClass

friend class BugReportEquivClass
friend

Definition at line 124 of file BugReporter.h.

◆ BugReporter

friend class BugReporter
friend

Definition at line 125 of file BugReporter.h.

Member Data Documentation

◆ BT

const BugType& clang::ento::BugReport::BT
protected

Definition at line 128 of file BugReporter.h.

◆ Description

std::string clang::ento::BugReport::Description
protected

Definition at line 130 of file BugReporter.h.

◆ Fixits

SmallVector<FixItHint, 4> clang::ento::BugReport::Fixits
protected

Definition at line 134 of file BugReporter.h.

◆ K

Kind clang::ento::BugReport::K
protected

Definition at line 127 of file BugReporter.h.

◆ Notes

SmallVector<std::shared_ptr<PathDiagnosticNotePiece>, 4> clang::ento::BugReport::Notes
protected

Definition at line 133 of file BugReporter.h.

◆ Ranges

SmallVector<SourceRange, 4> clang::ento::BugReport::Ranges
protected

Definition at line 132 of file BugReporter.h.

◆ ShortDescription

std::string clang::ento::BugReport::ShortDescription
protected

Definition at line 129 of file BugReporter.h.


The documentation for this class was generated from the following file: