class BugReport

Declaration

class BugReport { /* full declaration omitted */ };

Description

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:119

Member Variables

protected clang::ento::BugReport::Kind K
protected const clang::ento::BugType& BT
protected std::string ShortDescription
protected std::string Description
protected SmallVector<clang::SourceRange, 4> Ranges
protected SmallVector< std::shared_ptr<PathDiagnosticNotePiece>, 4> Notes
protected SmallVector<clang::FixItHint, 4> Fixits

Method Overview

  • protected BugReport(clang::ento::BugReport::Kind K, const clang::ento::BugType & BT, llvm::StringRef ShortDescription, llvm::StringRef Description)
  • protected BugReport(clang::ento::BugReport::Kind kind, const clang::ento::BugType & bt, llvm::StringRef desc)
  • public virtual void Profile(llvm::FoldingSetNodeID & hash) const
  • public void addFixItHint(const clang::FixItHint & F)
  • public void addNote(llvm::StringRef Msg, const clang::ento::PathDiagnosticLocation & Pos, ArrayRef<clang::SourceRange> Ranges = {})
  • public void addRange(clang::SourceRange R)
  • public const clang::ento::BugType & getBugType() const
  • public virtual const clang::Decl * getDeclWithIssue() const
  • public llvm::StringRef getDescription() const
  • public llvm::ArrayRef<FixItHint> getFixits() const
  • public clang::ento::BugReport::Kind getKind() const
  • public virtual clang::ento::PathDiagnosticLocation getLocation() const
  • public ArrayRef<std::shared_ptr<PathDiagnosticNotePiece>> getNotes()
  • public virtual ArrayRef<clang::SourceRange> getRanges() const
  • public llvm::StringRef getShortDescription(bool UseFallback = true) const
  • public virtual const clang::Decl * getUniqueingDecl() const
  • public virtual clang::ento::PathDiagnosticLocation getUniqueingLocation() const
  • public virtual ~BugReport()

Methods

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:139

Parameters

clang::ento::BugReport::Kind K
const clang::ento::BugType& BT
llvm::StringRef ShortDescription
llvm::StringRef Description

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:136

Parameters

clang::ento::BugReport::Kind kind
const clang::ento::BugType& bt
llvm::StringRef desc

virtual void Profile(
    llvm::FoldingSetNodeID& hash) const

Description

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:248

Parameters

llvm::FoldingSetNodeID& hash

void addFixItHint(const clang::FixItHint& F)

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:240

Parameters

const clang::FixItHint& F

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

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:201

Parameters

llvm::StringRef Msg
const clang::ento::PathDiagnosticLocation& Pos
ArrayRef<clang::SourceRange> Ranges = {}

void addRange(clang::SourceRange R)

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:222

Parameters

clang::SourceRange R

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:149

virtual const clang::Decl* getDeclWithIssue()
    const

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:178

llvm::StringRef getDescription() const

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:157

llvm::ArrayRef<FixItHint> getFixits() const

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:244

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:147

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

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:173

ArrayRef<std::shared_ptr<PathDiagnosticNotePiece>>
getNotes()

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:211

virtual ArrayRef<clang::SourceRange> getRanges()
    const

Description

Get the SourceRanges associated with the report.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:229

llvm::StringRef getShortDescription(
    bool UseFallback = true) const

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:163

Parameters

bool UseFallback = true

virtual const clang::Decl* getUniqueingDecl()
    const

Description

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.

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:195

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

Description

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

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:189

virtual ~BugReport()

Declared at: clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:145