clang 20.0.0git
Public Types | Public Member Functions | Public Attributes | List of all members
clang::UnsafeBufferUsageHandler Class Referenceabstract

The interface that lets the caller handle unsafe buffer usage analysis results by overriding this class's handle... methods. More...

#include "clang/Analysis/Analyses/UnsafeBufferUsage.h"

Public Types

using DebugNote = std::pair< SourceLocation, std::string >
 
using DebugNoteList = std::vector< DebugNote >
 
using DebugNoteByVar = std::map< const VarDecl *, DebugNoteList >
 
using FixItList = llvm::SmallVectorImpl< FixItHint >
 This analyses produces large fixits that are organized into lists of primitive fixits (individual insertions/removals/replacements).
 

Public Member Functions

 UnsafeBufferUsageHandler ()=default
 
virtual ~UnsafeBufferUsageHandler ()=default
 
virtual void handleUnsafeOperation (const Stmt *Operation, bool IsRelatedToDecl, ASTContext &Ctx)=0
 Invoked when an unsafe operation over raw pointers is found.
 
virtual void handleUnsafeLibcCall (const CallExpr *Call, unsigned PrintfInfo, ASTContext &Ctx, const Expr *UnsafeArg=nullptr)=0
 Invoked when a call to an unsafe libc function is found.
 
virtual void handleUnsafeOperationInContainer (const Stmt *Operation, bool IsRelatedToDecl, ASTContext &Ctx)=0
 Invoked when an unsafe operation with a std container is found.
 
virtual void handleUnsafeVariableGroup (const VarDecl *Variable, const VariableGroupsManager &VarGrpMgr, FixItList &&Fixes, const Decl *D, const FixitStrategy &VarTargetTypes)=0
 Invoked when a fix is suggested against a variable.
 
bool areDebugNotesRequested ()
 
void addDebugNoteForVar (const VarDecl *VD, SourceLocation Loc, std::string Text)
 
void clearDebugNotes ()
 
virtual bool isSafeBufferOptOut (const SourceLocation &Loc) const =0
 
virtual bool ignoreUnsafeBufferInContainer (const SourceLocation &Loc) const =0
 
virtual bool ignoreUnsafeBufferInLibcCall (const SourceLocation &Loc) const =0
 
virtual std::string getUnsafeBufferUsageAttributeTextAt (SourceLocation Loc, StringRef WSSuffix="") const =0
 

Public Attributes

DebugNoteByVar DebugNotesByVar
 

Detailed Description

The interface that lets the caller handle unsafe buffer usage analysis results by overriding this class's handle... methods.

Definition at line 85 of file UnsafeBufferUsage.h.

Member Typedef Documentation

◆ DebugNote

Definition at line 92 of file UnsafeBufferUsage.h.

◆ DebugNoteByVar

Definition at line 94 of file UnsafeBufferUsage.h.

◆ DebugNoteList

Definition at line 93 of file UnsafeBufferUsage.h.

◆ FixItList

This analyses produces large fixits that are organized into lists of primitive fixits (individual insertions/removals/replacements).

Definition at line 104 of file UnsafeBufferUsage.h.

Constructor & Destructor Documentation

◆ UnsafeBufferUsageHandler()

clang::UnsafeBufferUsageHandler::UnsafeBufferUsageHandler ( )
default

◆ ~UnsafeBufferUsageHandler()

virtual clang::UnsafeBufferUsageHandler::~UnsafeBufferUsageHandler ( )
virtualdefault

Member Function Documentation

◆ addDebugNoteForVar()

void clang::UnsafeBufferUsageHandler::addDebugNoteForVar ( const VarDecl VD,
SourceLocation  Loc,
std::string  Text 
)
inline

Definition at line 148 of file UnsafeBufferUsage.h.

References areDebugNotesRequested(), DebugNotesByVar, Loc, and Text.

Referenced by applyGadgets(), and getFixIts().

◆ areDebugNotesRequested()

bool clang::UnsafeBufferUsageHandler::areDebugNotesRequested ( )
inline

Definition at line 143 of file UnsafeBufferUsage.h.

Referenced by addDebugNoteForVar(), and clearDebugNotes().

◆ clearDebugNotes()

void clang::UnsafeBufferUsageHandler::clearDebugNotes ( )
inline

Definition at line 154 of file UnsafeBufferUsage.h.

References areDebugNotesRequested(), and DebugNotesByVar.

Referenced by clang::checkUnsafeBufferUsage().

◆ getUnsafeBufferUsageAttributeTextAt()

virtual std::string clang::UnsafeBufferUsageHandler::getUnsafeBufferUsageAttributeTextAt ( SourceLocation  Loc,
StringRef  WSSuffix = "" 
) const
pure virtual

◆ handleUnsafeLibcCall()

virtual void clang::UnsafeBufferUsageHandler::handleUnsafeLibcCall ( const CallExpr Call,
unsigned  PrintfInfo,
ASTContext Ctx,
const Expr UnsafeArg = nullptr 
)
pure virtual

Invoked when a call to an unsafe libc function is found.

Parameters
PrintfInfois 0 if the callee function is not a member of the printf family; is 1 if the callee is sprintf; is 2 if arguments of the call have __size_by relation but are not in a safe pattern; is 3 if string arguments do not guarantee null-termination is 4 if the callee takes va_list
UnsafeArgone of the actual arguments that is unsafe, non-null only when 2 <= PrintfInfo <= 3

◆ handleUnsafeOperation()

virtual void clang::UnsafeBufferUsageHandler::handleUnsafeOperation ( const Stmt Operation,
bool  IsRelatedToDecl,
ASTContext Ctx 
)
pure virtual

Invoked when an unsafe operation over raw pointers is found.

◆ handleUnsafeOperationInContainer()

virtual void clang::UnsafeBufferUsageHandler::handleUnsafeOperationInContainer ( const Stmt Operation,
bool  IsRelatedToDecl,
ASTContext Ctx 
)
pure virtual

Invoked when an unsafe operation with a std container is found.

◆ handleUnsafeVariableGroup()

virtual void clang::UnsafeBufferUsageHandler::handleUnsafeVariableGroup ( const VarDecl Variable,
const VariableGroupsManager VarGrpMgr,
FixItList &&  Fixes,
const Decl D,
const FixitStrategy VarTargetTypes 
)
pure virtual

Invoked when a fix is suggested against a variable.

This function groups all variables that must be fixed together (i.e their types must be changed to the same target type to prevent type mismatches) into a single fixit.

D is the declaration of the callable under analysis that owns Variable and all of its group mates.

Referenced by applyGadgets().

◆ ignoreUnsafeBufferInContainer()

virtual bool clang::UnsafeBufferUsageHandler::ignoreUnsafeBufferInContainer ( const SourceLocation Loc) const
pure virtual
Returns
true iff unsafe uses in containers should NOT be reported at Loc; false otherwise.

◆ ignoreUnsafeBufferInLibcCall()

virtual bool clang::UnsafeBufferUsageHandler::ignoreUnsafeBufferInLibcCall ( const SourceLocation Loc) const
pure virtual
Returns
true iff unsafe libc call should NOT be reported at Loc

◆ isSafeBufferOptOut()

virtual bool clang::UnsafeBufferUsageHandler::isSafeBufferOptOut ( const SourceLocation Loc) const
pure virtual
Returns
true iff buffer safety is opt-out at Loc; false otherwise.

Member Data Documentation

◆ DebugNotesByVar

DebugNoteByVar clang::UnsafeBufferUsageHandler::DebugNotesByVar

Definition at line 95 of file UnsafeBufferUsage.h.

Referenced by addDebugNoteForVar(), and clearDebugNotes().


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