clang  14.0.0git
Classes | Namespaces | Enumerations | Functions
AnalysisBasedWarnings.cpp File Reference
#include "clang/Sema/AnalysisBasedWarnings.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/ParentMap.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/AST/StmtCXX.h"
#include "clang/AST/StmtObjC.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
#include "clang/Analysis/Analyses/CalledOnceCheck.h"
#include "clang/Analysis/Analyses/Consumed.h"
#include "clang/Analysis/Analyses/ReachableCode.h"
#include "clang/Analysis/Analyses/ThreadSafety.h"
#include "clang/Analysis/Analyses/UninitializedValues.h"
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Analysis/CFG.h"
#include "clang/Analysis/CFGStmtMap.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include <algorithm>
#include <deque>
#include <iterator>
Include dependency graph for AnalysisBasedWarnings.cpp:

Go to the source code of this file.

Classes

class  clang::sema::AnalysisBasedWarnings::InterProceduralData
 InterProceduralData aims to be a storage of whatever data should be passed between analyses of different functions. More...
 

Namespaces

 clang
 
 clang::threadSafety
 
 clang::consumed
 

Enumerations

enum  ControlFlowKind {
  UnknownFallThrough, NeverFallThrough, MaybeFallThrough, AlwaysFallThrough,
  NeverFallThroughOrReturn
}
 

Functions

static void CheckUnreachable (Sema &S, AnalysisDeclContext &AC)
 CheckUnreachable - Check for unreachable code. More...
 
static bool hasRecursiveCallInPath (const FunctionDecl *FD, CFGBlock &Block)
 
static bool checkForRecursiveFunctionCall (const FunctionDecl *FD, CFG *cfg)
 
static void checkRecursiveFunction (Sema &S, const FunctionDecl *FD, const Stmt *Body, AnalysisDeclContext &AC)
 
static bool throwEscapes (Sema &S, const CXXThrowExpr *E, CFGBlock &ThrowBlock, CFG *Body)
 Determine whether an exception thrown by E, unwinding from ThrowBlock, can reach ExitBlock. More...
 
static void visitReachableThrows (CFG *BodyCFG, llvm::function_ref< void(const CXXThrowExpr *, CFGBlock &)> Visit)
 
static void EmitDiagForCXXThrowInNonThrowingFunc (Sema &S, SourceLocation OpLoc, const FunctionDecl *FD)
 
static void checkThrowInNonThrowingFunc (Sema &S, const FunctionDecl *FD, AnalysisDeclContext &AC)
 
static bool isNoexcept (const FunctionDecl *FD)
 
static ControlFlowKind CheckFallThrough (AnalysisDeclContext &AC)
 CheckFallThrough - Check that we don't fall off the end of a Statement that should return a value. More...
 
static void CheckFallThroughForBody (Sema &S, const Decl *D, const Stmt *Body, QualType BlockType, const CheckFallThroughDiagnostics &CD, AnalysisDeclContext &AC, sema::FunctionScopeInfo *FSI)
 CheckFallThroughForBody - Check that we don't fall off the end of a function that should return a value. More...
 
static bool SuggestInitializationFixit (Sema &S, const VarDecl *VD)
 
static void CreateIfFixit (Sema &S, const Stmt *If, const Stmt *Then, const Stmt *Else, bool CondVal, FixItHint &Fixit1, FixItHint &Fixit2)
 Create a fixit to remove an if-like statement, on the assumption that its condition is CondVal. More...
 
static void DiagUninitUse (Sema &S, const VarDecl *VD, const UninitUse &Use, bool IsCapturedByBlock)
 DiagUninitUse – Helper function to produce a diagnostic for an uninitialized use of a variable. More...
 
static bool DiagnoseUninitializedConstRefUse (Sema &S, const VarDecl *VD, const UninitUse &Use)
 Diagnose uninitialized const reference usages. More...
 
static bool DiagnoseUninitializedUse (Sema &S, const VarDecl *VD, const UninitUse &Use, bool alwaysReportSelfInit=false)
 DiagnoseUninitializedUse – Helper function for diagnosing uses of an uninitialized variable. More...
 
static StringRef getFallthroughAttrSpelling (Preprocessor &PP, SourceLocation Loc)
 
static void DiagnoseSwitchLabelsFallthrough (Sema &S, AnalysisDeclContext &AC, bool PerFunction)
 
static bool isInLoop (const ASTContext &Ctx, const ParentMap &PM, const Stmt *S)
 
static void diagnoseRepeatedUseOfWeak (Sema &S, const sema::FunctionScopeInfo *CurFn, const Decl *D, const ParentMap &PM)
 
static unsigned isEnabled (DiagnosticsEngine &D, unsigned diag)
 
static void flushDiagnostics (Sema &S, const sema::FunctionScopeInfo *fscope)
 

Enumeration Type Documentation

◆ ControlFlowKind

Enumerator
UnknownFallThrough 
NeverFallThrough 
MaybeFallThrough 
AlwaysFallThrough 
NeverFallThroughOrReturn 

Definition at line 382 of file AnalysisBasedWarnings.cpp.

Function Documentation

◆ CheckFallThrough()

static ControlFlowKind CheckFallThrough ( AnalysisDeclContext AC)
static

CheckFallThrough - Check that we don't fall off the end of a Statement that should return a value.

Returns
AlwaysFallThrough iff we always fall off the end of the statement, MaybeFallThrough iff we might or might not fall off the end, NeverFallThroughOrReturn iff we never fall off the end of the statement or return. We assume NeverFallThrough iff we never fall off the end of the statement but we may return. We assume that functions not marked noreturn will return.

Definition at line 399 of file AnalysisBasedWarnings.cpp.

References clang::CFGElement::castAs(), clang::AnalysisDeclContext::getAddEHEdges(), clang::CFGElement::getAs(), clang::CFGBlock::getBlockID(), clang::AnalysisDeclContext::getCFG(), clang::CFG::getEntry(), clang::CFG::getNumBlockIDs(), clang::CFGBlock::getTerminatorStmt(), clang::CFGBlock::FilteredCFGBlockIterator< IMPL, IsPred >::hasMore(), clang::CFGBlock::hasNoReturnElement(), clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, clang::CFGBlock::rbegin(), clang::CFGBlock::rend(), clang::reachable_code::ScanReachableFromBlock(), and UnknownFallThrough.

◆ CheckFallThroughForBody()

static void CheckFallThroughForBody ( Sema S,
const Decl D,
const Stmt Body,
QualType  BlockType,
const CheckFallThroughDiagnostics &  CD,
AnalysisDeclContext AC,
sema::FunctionScopeInfo FSI 
)
static

CheckFallThroughForBody - Check that we don't fall off the end of a function that should return a value.

Check that we don't fall off the end of a noreturn function. We assume that functions and blocks not marked noreturn will return.

Definition at line 638 of file AnalysisBasedWarnings.cpp.

Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().

◆ checkForRecursiveFunctionCall()

static bool checkForRecursiveFunctionCall ( const FunctionDecl FD,
CFG cfg 
)
static

◆ checkRecursiveFunction()

static void checkRecursiveFunction ( Sema S,
const FunctionDecl FD,
const Stmt Body,
AnalysisDeclContext AC 
)
static

◆ checkThrowInNonThrowingFunc()

static void checkThrowInNonThrowingFunc ( Sema S,
const FunctionDecl FD,
AnalysisDeclContext AC 
)
static

◆ CheckUnreachable()

static void CheckUnreachable ( Sema S,
AnalysisDeclContext AC 
)
static

CheckUnreachable - Check for unreachable code.

Definition at line 110 of file AnalysisBasedWarnings.cpp.

Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().

◆ CreateIfFixit()

static void CreateIfFixit ( Sema S,
const Stmt If,
const Stmt Then,
const Stmt Else,
bool  CondVal,
FixItHint Fixit1,
FixItHint Fixit2 
)
static

Create a fixit to remove an if-like statement, on the assumption that its condition is CondVal.

Definition at line 788 of file AnalysisBasedWarnings.cpp.

◆ diagnoseRepeatedUseOfWeak()

static void diagnoseRepeatedUseOfWeak ( Sema S,
const sema::FunctionScopeInfo CurFn,
const Decl D,
const ParentMap PM 
)
static

◆ DiagnoseSwitchLabelsFallthrough()

static void DiagnoseSwitchLabelsFallthrough ( Sema S,
AnalysisDeclContext AC,
bool  PerFunction 
)
static

◆ DiagnoseUninitializedConstRefUse()

static bool DiagnoseUninitializedConstRefUse ( Sema S,
const VarDecl VD,
const UninitUse Use 
)
static

Diagnose uninitialized const reference usages.

Definition at line 980 of file AnalysisBasedWarnings.cpp.

◆ DiagnoseUninitializedUse()

static bool DiagnoseUninitializedUse ( Sema S,
const VarDecl VD,
const UninitUse Use,
bool  alwaysReportSelfInit = false 
)
static

DiagnoseUninitializedUse – Helper function for diagnosing uses of an uninitialized variable.

This manages the different forms of diagnostic emitted for particular types of uses. Returns true if the use was diagnosed as a warning. If a particular use is one we omit warnings for, returns false.

Definition at line 992 of file AnalysisBasedWarnings.cpp.

◆ DiagUninitUse()

static void DiagUninitUse ( Sema S,
const VarDecl VD,
const UninitUse Use,
bool  IsCapturedByBlock 
)
static

DiagUninitUse – Helper function to produce a diagnostic for an uninitialized use of a variable.

Definition at line 812 of file AnalysisBasedWarnings.cpp.

◆ EmitDiagForCXXThrowInNonThrowingFunc()

static void EmitDiagForCXXThrowInNonThrowingFunc ( Sema S,
SourceLocation  OpLoc,
const FunctionDecl FD 
)
static

Definition at line 338 of file AnalysisBasedWarnings.cpp.

◆ flushDiagnostics()

static void flushDiagnostics ( Sema S,
const sema::FunctionScopeInfo fscope 
)
static

◆ getFallthroughAttrSpelling()

static StringRef getFallthroughAttrSpelling ( Preprocessor PP,
SourceLocation  Loc 
)
static

◆ hasRecursiveCallInPath()

static bool hasRecursiveCallInPath ( const FunctionDecl FD,
CFGBlock Block 
)
static

◆ isEnabled()

static unsigned isEnabled ( DiagnosticsEngine D,
unsigned  diag 
)
static

◆ isInLoop()

static bool isInLoop ( const ASTContext Ctx,
const ParentMap PM,
const Stmt S 
)
static

Definition at line 1328 of file AnalysisBasedWarnings.cpp.

◆ isNoexcept()

static bool isNoexcept ( const FunctionDecl FD)
static

◆ SuggestInitializationFixit()

static bool SuggestInitializationFixit ( Sema S,
const VarDecl VD 
)
static

Definition at line 756 of file AnalysisBasedWarnings.cpp.

◆ throwEscapes()

static bool throwEscapes ( Sema S,
const CXXThrowExpr E,
CFGBlock ThrowBlock,
CFG Body 
)
static

Determine whether an exception thrown by E, unwinding from ThrowBlock, can reach ExitBlock.

Definition at line 283 of file AnalysisBasedWarnings.cpp.

◆ visitReachableThrows()

static void visitReachableThrows ( CFG BodyCFG,
llvm::function_ref< void(const CXXThrowExpr *, CFGBlock &)>  Visit 
)
static

Variable Documentation

◆ SM

Definition at line 1516 of file AnalysisBasedWarnings.cpp.