clang
6.0.0
|
#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/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/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>
Go to the source code of this file.
Namespaces | |
clang | |
Dataflow Directional Tag Classes. | |
clang::threadSafety | |
clang::consumed | |
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 | isThrowCaught (const CXXThrowExpr *Throw, const CXXCatchStmt *Catch) |
static bool | isThrowCaughtByHandlers (const CXXThrowExpr *CE, const CXXTryStmt *TryStmt) |
static bool | doesThrowEscapePath (CFGBlock Block, SourceLocation &OpLoc) |
static bool | hasThrowOutNonThrowingFunc (SourceLocation &OpLoc, CFG *BodyCFG) |
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, const BlockExpr *blkExpr, const CheckFallThroughDiagnostics &CD, AnalysisDeclContext &AC) |
CheckFallThroughForFunctionDef - 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 | 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) |
enum ControlFlowKind |
Enumerator | |
---|---|
UnknownFallThrough | |
NeverFallThrough | |
MaybeFallThrough | |
AlwaysFallThrough | |
NeverFallThroughOrReturn |
Definition at line 437 of file AnalysisBasedWarnings.cpp.
enum RecursiveState |
Enumerator | |
---|---|
FoundNoPath | |
FoundPath | |
FoundPathWithNoRecursiveCall |
Definition at line 205 of file AnalysisBasedWarnings.cpp.
enum ThrowState |
Enumerator | |
---|---|
FoundNoPathForThrow | |
FoundPathForThrow | |
FoundPathWithNoThrowOutFunction |
Definition at line 284 of file AnalysisBasedWarnings.cpp.
|
static |
CheckFallThrough - Check that we don't fall off the end of a Statement that should return a value.
Definition at line 454 of file AnalysisBasedWarnings.cpp.
References clang::AnalysisDeclContext::getAddEHEdges(), clang::AnalysisDeclContext::getCFG(), clang::CFG::getEntry(), clang::CFG::getNumBlockIDs(), clang::CFGBlock::FilterOptions::IgnoreDefaultsWithCoveredEnums, clang::reachable_code::ScanReachableFromBlock(), and UnknownFallThrough.
Referenced by CheckFallThroughForBody().
|
static |
CheckFallThroughForFunctionDef - 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 690 of file AnalysisBasedWarnings.cpp.
References AlwaysFallThrough, CheckFallThrough(), clang::sema::FunctionScopeInfo::CoroutinePromise, clang::Sema::Diag(), clang::Type::getAs(), clang::Sema::getCurFunction(), clang::Sema::getDiagnostics(), clang::Stmt::getLocEnd(), clang::Stmt::getLocStart(), clang::Type::getPointeeType(), clang::Expr::getType(), clang::ValueDecl::getType(), clang::sema::FunctionScopeInfo::isCoroutine(), MaybeFallThrough, NeverFallThrough, NeverFallThroughOrReturn, and UnknownFallThrough.
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Definition at line 213 of file AnalysisBasedWarnings.cpp.
References FoundNoPath, FoundPathWithNoRecursiveCall, clang::CFGBlock::getBlockID(), clang::CFG::getEntry(), clang::CFG::getExit(), and clang::CFG::getNumBlockIDs().
Referenced by checkRecursiveFunction().
|
static |
Definition at line 259 of file AnalysisBasedWarnings.cpp.
References checkForRecursiveFunctionCall(), clang::Sema::Diag(), clang::FunctionDecl::getCanonicalDecl(), clang::AnalysisDeclContext::getCFG(), clang::CFG::getExit(), clang::Stmt::getLocStart(), clang::FunctionDecl::getTemplatedKind(), clang::CFGBlock::pred_empty(), clang::FunctionDecl::TK_MemberSpecialization, and clang::FunctionDecl::TK_NonTemplate.
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Definition at line 414 of file AnalysisBasedWarnings.cpp.
References EmitDiagForCXXThrowInNonThrowingFunc(), clang::AnalysisDeclContext::getCFG(), clang::CFG::getExit(), hasThrowOutNonThrowingFunc(), and clang::CFGBlock::pred_empty().
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
CheckUnreachable - Check for unreachable code.
Definition at line 109 of file AnalysisBasedWarnings.cpp.
References clang::reachable_code::FindUnreachableCode(), clang::AnalysisDeclContext::getDecl(), clang::Decl::getLocStart(), clang::Sema::getPreprocessor(), clang::Sema::getSourceManager(), and clang::SourceManager::isInMainFile().
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Create a fixit to remove an if-like statement, on the assumption that its condition is CondVal.
Definition at line 835 of file AnalysisBasedWarnings.cpp.
References clang::FixItHint::CreateRemoval(), clang::CharSourceRange::getCharRange(), clang::Stmt::getLocEnd(), clang::Sema::getLocForEndOfToken(), clang::Stmt::getLocStart(), and clang::Stmt::getSourceRange().
|
static |
Definition at line 1396 of file AnalysisBasedWarnings.cpp.
References clang::Sema::getASTContext(), and clang::sema::FunctionScopeInfo::getWeakObjectUses().
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Definition at line 1292 of file AnalysisBasedWarnings.cpp.
References clang::FixItHint::CreateInsertion(), clang::Sema::Diag(), clang::AnalysisDeclContext::getASTContext(), clang::AnalysisDeclContext::getBody(), clang::AnalysisDeclContext::getCFG(), clang::AnalysisDeclContext::getDecl(), getFallthroughAttrSpelling(), clang::ASTContext::getLangOpts(), clang::Sema::getLangOpts(), clang::Stmt::getLocStart(), clang::Sema::getPreprocessor(), clang::SourceLocation::isMacroID(), and Label.
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
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 1033 of file AnalysisBasedWarnings.cpp.
References clang::Sema::Context, clang::Sema::Diag(), DiagUninitUse(), clang::NamedDecl::getDeclName(), clang::VarDecl::getInit(), clang::Decl::getLocation(), clang::DeclaratorDecl::getLocStart(), clang::BlockExpr::getLocStart(), clang::ValueDecl::getType(), clang::UninitUse::getUser(), clang::Decl::hasAttr(), clang::Type::isBlockPointerType(), and SuggestInitializationFixit().
|
static |
DiagUninitUse – Helper function to produce a diagnostic for an uninitialized use of a variable.
Definition at line 861 of file AnalysisBasedWarnings.cpp.
References clang::UninitUse::AfterCall, clang::UninitUse::AfterDecl, clang::UninitUse::Always, clang::Sema::Diag(), clang::NamedDecl::getDeclName(), clang::UninitUse::getKind(), clang::Decl::getLexicalDeclContext(), clang::Decl::getLocation(), clang::Stmt::getLocStart(), clang::Stmt::getSourceRange(), clang::VarDecl::getSourceRange(), clang::UninitUse::getUser(), clang::UninitUse::Maybe, and clang::UninitUse::Sometimes.
Referenced by DiagnoseUninitializedUse().
|
static |
Definition at line 331 of file AnalysisBasedWarnings.cpp.
References clang::CFGElement::Statement.
|
static |
Definition at line 394 of file AnalysisBasedWarnings.cpp.
References clang::Sema::Diag(), clang::DeclarationName::getCXXOverloadedOperator(), clang::NamedDecl::getDeclName(), clang::FunctionDecl::getExceptionSpecSourceRange(), clang::Sema::getLangOpts(), clang::Decl::getLocation(), clang::Sema::getSourceManager(), clang::TypeSourceInfo::getType(), clang::DeclaratorDecl::getTypeSourceInfo(), and clang::SourceManager::isInSystemHeader().
Referenced by checkThrowInNonThrowingFunc().
|
static |
Definition at line 2065 of file AnalysisBasedWarnings.cpp.
References clang::Sema::Diag(), clang::sema::AnalysisBasedWarnings::IssueWarnings(), and clang::sema::FunctionScopeInfo::PossiblyUnreachableDiags.
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Definition at line 1264 of file AnalysisBasedWarnings.cpp.
References clang::Preprocessor::getIdentifierInfo(), clang::Preprocessor::getLangOpts(), and clang::Preprocessor::getLastMacroWithSpelling().
Referenced by DiagnoseSwitchLabelsFallthrough().
|
static |
Definition at line 173 of file AnalysisBasedWarnings.cpp.
References clang::CallExpr::getCallee(), clang::CallExpr::getCalleeDecl(), clang::Decl::getCanonicalDecl(), clang::CXXMemberCallExpr::getImplicitObjectArgument(), clang::CXXMemberCallExpr::getMethodDecl(), clang::Expr::IgnoreParenImpCasts(), clang::CXXMethodDecl::isVirtual(), clang::CFGElement::Statement, and clang::NestedNameSpecifier::TypeSpec.
|
static |
Definition at line 353 of file AnalysisBasedWarnings.cpp.
References FoundNoPathForThrow, FoundPathWithNoThrowOutFunction, clang::CFGBlock::getBlockID(), clang::CFG::getEntry(), clang::CFG::getExit(), and clang::CFG::getNumBlockIDs().
Referenced by checkThrowInNonThrowingFunc().
|
static |
Definition at line 2033 of file AnalysisBasedWarnings.cpp.
References clang::DiagnosticsEngine::isIgnored().
Referenced by clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(), and clang::Sema::CheckAssignmentOperands().
|
static |
Definition at line 1370 of file AnalysisBasedWarnings.cpp.
References clang::Stmt::getStmtClass().
|
static |
Definition at line 426 of file AnalysisBasedWarnings.cpp.
References clang::Type::castAs(), clang::Decl::getASTContext(), clang::ValueDecl::getType(), and clang::Decl::hasAttr().
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
|
static |
Definition at line 290 of file AnalysisBasedWarnings.cpp.
References clang::Type::castAs(), clang::Type::getAsCXXRecordDecl(), clang::CXXCatchStmt::getCaughtType(), clang::Type::getPointeeType(), clang::ReferenceType::getPointeeType(), clang::CXXThrowExpr::getSubExpr(), clang::Expr::getType(), clang::QualType::getTypePtrOrNull(), clang::Type::getUnqualifiedDesugaredType(), clang::CXXRecordDecl::isDerivedFrom(), clang::Type::isPointerType(), and clang::Type::isReferenceType().
|
static |
Definition at line 322 of file AnalysisBasedWarnings.cpp.
Definition at line 803 of file AnalysisBasedWarnings.cpp.
References clang::FixItHint::CreateInsertion(), clang::Sema::Diag(), clang::QualType::getCanonicalType(), clang::NamedDecl::getDeclName(), clang::Sema::getFixItZeroInitializerForType(), clang::VarDecl::getInit(), clang::Decl::getLocation(), clang::Decl::getLocEnd(), clang::Sema::getLocForEndOfToken(), clang::ValueDecl::getType(), clang::Decl::hasAttr(), clang::Type::isBlockPointerType(), and clang::SourceLocation::isMacroID().
Referenced by DiagnoseUninitializedUse().
SourceManager& SM |
Definition at line 1647 of file AnalysisBasedWarnings.cpp.