clang 20.0.0git
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]

Public Types

enum class  Kind { Basic , 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.
 
StringRef getShortDescription (bool UseFallback=true) const
 A short general warning message that is appropriate for displaying in the list of all reported bugs.
 
virtual PathDiagnosticLocation getLocation () const =0
 The primary location of the bug report that points at the undesirable behavior in the code.
 
virtual const DeclgetDeclWithIssue () const =0
 The smallest declaration that contains the bug location.
 
virtual PathDiagnosticLocation getUniqueingLocation () const =0
 Get the location on which the report should be uniqued.
 
virtual const DeclgetUniqueingDecl () const =0
 Get the declaration that corresponds to (usually contains) the uniqueing location.
 
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.
 
ArrayRef< std::shared_ptr< PathDiagnosticNotePiece > > getNotes ()
 
void addRange (SourceRange R)
 Add a range to a bug report.
 
virtual ArrayRef< SourceRangegetRanges () const
 Get the SourceRanges associated with the report.
 
void addFixItHint (const FixItHint &F)
 Add a fix-it hint to the bug report.
 
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.
 

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

enum class clang::ento::BugReport::Kind
strong
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.

References Fixits.

Referenced by clang::ento::BugReporter::EmitBasicReport().

◆ 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.

◆ 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(), and Ranges.

Referenced by clang::ento::BugReporter::EmitBasicReport().

◆ getBugType()

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

◆ 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::BasicBugReport, and clang::ento::PathSensitiveBugReport.

Referenced by clang::ento::BugSuppression::isSuppressed().

◆ 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.

References Description.

Referenced by generateDiagnosticForBasicReport(), generateEmptyDiagnosticForReport(), and clang::ento::BugReporterVisitor::getDefaultEndPath().

◆ getFixits()

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

Definition at line 244 of file BugReporter.h.

References Fixits.

◆ 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::BasicBugReport, clang::ento::PathSensitiveBugReport, and clang::ento::retaincountchecker::RefLeakReport.

Referenced by clang::ento::BugSuppression::isSuppressed().

◆ getNotes()

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

Definition at line 211 of file BugReporter.h.

References Notes.

◆ 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.

References Ranges.

◆ 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.

References Description, and ShortDescription.

Referenced by generateDiagnosticForBasicReport(), generateEmptyDiagnosticForReport(), clang::ento::BasicBugReport::Profile(), and clang::ento::PathSensitiveBugReport::Profile().

◆ 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::BasicBugReport, and clang::ento::PathSensitiveBugReport.

◆ 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::BasicBugReport, and clang::ento::PathSensitiveBugReport.

Referenced by clang::ento::BugSuppression::isSuppressed().

◆ 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::BasicBugReport, and clang::ento::PathSensitiveBugReport.

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

◆ Description

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

Definition at line 130 of file BugReporter.h.

Referenced by getDescription(), and getShortDescription().

◆ Fixits

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

Definition at line 134 of file BugReporter.h.

Referenced by addFixItHint(), and getFixits().

◆ K

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

Definition at line 127 of file BugReporter.h.

Referenced by getKind().

◆ Notes

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

Definition at line 133 of file BugReporter.h.

Referenced by getNotes().

◆ Ranges

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

◆ ShortDescription

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

Definition at line 129 of file BugReporter.h.

Referenced by getShortDescription().


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