clang: lib/Sema/AnalysisBasedWarnings.cpp File Reference (original) (raw)

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...
class CallableVisitor
Namespaces
namespace clang
The JSON file list parser is used to communicate input to InstallAPI.
namespace clang::threadSafety
namespace clang::consumed
Functions
static void CheckUnreachable (Sema &S, AnalysisDeclContext &AC)
CheckUnreachable - Check for unreachable code.
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.
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.
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.
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.
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.
static bool DiagnoseUninitializedConstRefUse (Sema &S, const VarDecl *VD, const UninitUse &Use)
Diagnose uninitialized const reference usages.
static bool DiagnoseUninitializedUse (Sema &S, const VarDecl *VD, const UninitUse &Use, bool alwaysReportSelfInit=false)
DiagnoseUninitializedUse – Helper function for diagnosing uses of an uninitialized variable.
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)

ControlFlowKind

Enumerator
UnknownFallThrough
NeverFallThrough
MaybeFallThrough
AlwaysFallThrough
NeverFallThroughOrReturn

Definition at line 406 of file AnalysisBasedWarnings.cpp.

CheckFallThrough()

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 423 of file AnalysisBasedWarnings.cpp.

References AlwaysFallThrough, clang::CFGElement::castAs(), clang::CFGBlock::filtered_pred_start_end(), clang::CFGElement::getAs(), clang::CFGBlock::getBlockID(), clang::CFG::getEntry(), clang::CFG::getExit(), clang::CFG::getNumBlockIDs(), clang::CFGStmt::getStmt(), clang::CFGBlock::getTerminatorStmt(), clang::CFGBlock::FilteredCFGBlockIterator< IMPL, IsPred >::hasMore(), clang::CFGBlock::hasNoReturnElement(), clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, MaybeFallThrough, NeverFallThrough, NeverFallThroughOrReturn, clang::CFGBlock::rbegin(), clang::CFGBlock::rend(), clang::reachable_code::ScanReachableFromBlock(), clang::CFGBlock::succs(), and UnknownFallThrough.

Referenced by CheckFallThroughForBody().

CheckFallThroughForBody()

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 662 of file AnalysisBasedWarnings.cpp.

References AlwaysFallThrough, CheckFallThrough(), clang::sema::FunctionScopeInfo::CoroutinePromise, D, clang::SemaBase::Diag(), clang::Type::getAs(), clang::Decl::getAsFunction(), clang::Stmt::getBeginLoc(), clang::Sema::getDiagnostics(), clang::Stmt::getEndLoc(), clang::Type::getPointeeType(), clang::ValueDecl::getType(), clang::sema::FunctionScopeInfo::isCoroutine(), clang::FunctionDecl::isCPUDispatchMultiVersion(), Loc, MaybeFallThrough, NeverFallThrough, NeverFallThroughOrReturn, and UnknownFallThrough.

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

checkForRecursiveFunctionCall()

checkRecursiveFunction()

checkThrowInNonThrowingFunc()

CheckUnreachable()

CreateIfFixit()

diagnoseRepeatedUseOfWeak()

Definition at line 1365 of file AnalysisBasedWarnings.cpp.

References Block, D, clang::SemaBase::Diag(), E, clang::Function, clang::Sema::getASTContext(), clang::Stmt::getBeginLoc(), clang::Sema::getSourceManager(), clang::Stmt::getSourceRange(), clang::sema::FunctionScopeInfo::getWeakObjectUses(), int, clang::SourceManager::isBeforeInTranslationUnit(), isInLoop(), P, clang::Property, SM, and Variable.

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

DiagnoseSwitchLabelsFallthrough()

Definition at line 1274 of file AnalysisBasedWarnings.cpp.

References clang::FixItHint::CreateInsertion(), clang::SemaBase::Diag(), clang::CFGBlock::empty(), clang::Function, getFallthroughAttrSpelling(), clang::CFGBlock::getLabel(), clang::Sema::getPreprocessor(), clang::CFGBlock::getTerminatorStmt(), clang::SourceLocation::isMacroID(), Label, clang::CFGBlock::succ_begin(), and clang::CFGBlock::succ_size().

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

DiagnoseUninitializedConstRefUse()

DiagnoseUninitializedUse()

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 1016 of file AnalysisBasedWarnings.cpp.

References clang::Sema::Context, clang::SemaBase::Diag(), DiagUninitUse(), clang::DeclaratorDecl::getBeginLoc(), clang::BlockExpr::getBeginLoc(), clang::NamedDecl::getDeclName(), clang::VarDecl::getInit(), clang::Decl::getLocation(), clang::QualType::getQualifiers(), clang::ValueDecl::getType(), clang::UninitUse::getUser(), clang::Decl::hasAttr(), clang::Qualifiers::hasObjCLifetime(), clang::Initializer, clang::Type::isBlockPointerType(), and SuggestInitializationFixit().

DiagUninitUse()

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

Definition at line 836 of file AnalysisBasedWarnings.cpp.

References clang::UninitUse::AfterCall, clang::UninitUse::AfterDecl, clang::UninitUse::Always, clang::UninitUse::branch_begin(), clang::UninitUse::branch_end(), CreateIfFixit(), clang::FixItHint::CreateRemoval(), clang::FixItHint::CreateReplacement(), clang::SemaBase::Diag(), E, clang::SourceRange::getBegin(), clang::CharSourceRange::getBegin(), clang::BinaryOperator::getBeginLoc(), clang::Stmt::getBeginLoc(), clang::IfStmt::getCond(), clang::ConditionalOperator::getCond(), clang::NamedDecl::getDeclName(), clang::IfStmt::getElse(), clang::ConditionalOperator::getFalseExpr(), clang::UninitUse::getKind(), clang::Sema::getLangOpts(), clang::Decl::getLexicalDeclContext(), clang::BinaryOperator::getLHS(), clang::Decl::getLocation(), clang::BinaryOperator::getOpcode(), clang::BinaryOperator::getOpcodeStr(), clang::BinaryOperator::getOperatorLoc(), clang::Stmt::getSourceRange(), clang::VarDecl::getSourceRange(), clang::Stmt::getStmtClass(), clang::IfStmt::getThen(), clang::ConditionalOperator::getTrueExpr(), clang::UninitUse::getUser(), clang::BinaryOperator::isLogicalOp(), clang::UninitUse::Maybe, Range, clang::FixItHint::RemoveRange, and clang::UninitUse::Sometimes.

Referenced by DiagnoseUninitializedUse().

EmitDiagForCXXThrowInNonThrowingFunc()

flushDiagnostics()

getFallthroughAttrSpelling()

hasRecursiveCallInPath()

Definition at line 212 of file AnalysisBasedWarnings.cpp.

References Block, clang::CallExpr::getCallee(), clang::CallExpr::getCalleeDecl(), clang::Decl::getCanonicalDecl(), clang::CXXMemberCallExpr::getImplicitObjectArgument(), clang::CXXMemberCallExpr::getMethodDecl(), clang::CFGStmt::getStmt(), clang::Expr::IgnoreParenImpCasts(), clang::CXXMethodDecl::isVirtual(), clang::CFGElement::Statement, and clang::NestedNameSpecifier::TypeSpec.

Referenced by checkForRecursiveFunctionCall().

isEnabled()

isInLoop()

isNoexcept()

SuggestInitializationFixit()

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

Definition at line 780 of file AnalysisBasedWarnings.cpp.

References clang::FixItHint::CreateInsertion(), clang::SemaBase::Diag(), clang::QualType::getCanonicalType(), clang::NamedDecl::getDeclName(), clang::Decl::getEndLoc(), clang::Sema::getFixItZeroInitializerForType(), clang::VarDecl::getInit(), clang::Decl::getLocation(), clang::Sema::getLocForEndOfToken(), clang::ValueDecl::getType(), clang::Decl::hasAttr(), clang::Init, clang::Type::isBlockPointerType(), clang::SourceLocation::isMacroID(), and Loc.

Referenced by DiagnoseUninitializedUse().

throwEscapes()

visitReachableThrows()

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

SM