Issue AnalysisBasedWarnings as part of calling Sema::PopBlockOrFunctionScope(). No real functionality change.

llvm-svn: 126287
This commit is contained in:
Ted Kremenek 2011-02-23 01:51:48 +00:00
parent 55ae319a28
commit 1767a27b3e
6 changed files with 21 additions and 45 deletions

View File

@ -47,16 +47,13 @@ private:
enum VisitFlag { NotVisited = 0, Visited = 1, Pending = 2 };
llvm::DenseMap<const FunctionDecl*, VisitFlag> VisitedFD;
void IssueWarnings(Policy P, const Decl *D, QualType BlockTy);
public:
AnalysisBasedWarnings(Sema &s);
Policy getDefaultPolicy() { return DefaultPolicy; }
void IssueWarnings(Policy P, const Decl *D, const BlockExpr *blkExpr);
void IssueWarnings(Policy P, const BlockExpr *E);
void IssueWarnings(Policy P, const FunctionDecl *D);
void IssueWarnings(Policy P, const ObjCMethodDecl *D);
Policy getDefaultPolicy() { return DefaultPolicy; }
};
}} // end namespace clang::sema

View File

@ -688,7 +688,8 @@ public:
void PushFunctionScope();
void PushBlockScope(Scope *BlockScope, BlockDecl *Block);
void PopFunctionOrBlockScope();
void PopFunctionOrBlockScope(const sema::AnalysisBasedWarnings::Policy *WP =0,
const Decl *D = 0, const BlockExpr *blkExpr = 0);
sema::FunctionScopeInfo *getCurFunction() const {
return FunctionScopes.back();

View File

@ -289,7 +289,7 @@ struct CheckFallThroughDiagnostics {
/// of a noreturn function. We assume that functions and blocks not marked
/// noreturn will return.
static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
QualType BlockTy,
const BlockExpr *blkExpr,
const CheckFallThroughDiagnostics& CD,
AnalysisContext &AC) {
@ -306,6 +306,7 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
HasNoReturn = MD->hasAttr<NoReturnAttr>();
}
else if (isa<BlockDecl>(D)) {
QualType BlockTy = blkExpr->getType();
if (const FunctionType *FT =
BlockTy->getPointeeType()->getAs<FunctionType>()) {
if (FT->getResultType()->isVoidType())
@ -479,9 +480,7 @@ clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s) : S(s) {
void clang::sema::
AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
const Decl *D, QualType BlockTy) {
assert(BlockTy.isNull() || isa<BlockDecl>(D));
const Decl *D, const BlockExpr *blkExpr) {
// We avoid doing analysis-based warnings when there are errors for
// two reasons:
@ -517,7 +516,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
const CheckFallThroughDiagnostics &CD =
(isa<BlockDecl>(D) ? CheckFallThroughDiagnostics::MakeForBlock()
: CheckFallThroughDiagnostics::MakeForFunction(D));
CheckFallThroughForBody(S, D, Body, BlockTy, CD, AC);
CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC);
}
// Warning: check for unreachable code
@ -550,21 +549,3 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
}
}
}
void clang::sema::
AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
const BlockExpr *E) {
return IssueWarnings(P, E->getBlockDecl(), E->getType());
}
void clang::sema::
AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
const ObjCMethodDecl *D) {
return IssueWarnings(P, D, QualType());
}
void clang::sema::
AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
const FunctionDecl *D) {
return IssueWarnings(P, D, QualType());
}

View File

@ -631,9 +631,15 @@ void Sema::PushBlockScope(Scope *BlockScope, BlockDecl *Block) {
BlockScope, Block));
}
void Sema::PopFunctionOrBlockScope() {
FunctionScopeInfo *Scope = FunctionScopes.pop_back_val();
void Sema::PopFunctionOrBlockScope(const AnalysisBasedWarnings::Policy *WP,
const Decl *D, const BlockExpr *blkExpr) {
FunctionScopeInfo *Scope = FunctionScopes.pop_back_val();
assert(!FunctionScopes.empty() && "mismatched push/pop!");
// Issue any analysis-based warnings.
if (WP && D)
AnalysisWarnings.IssueWarnings(*WP, D, blkExpr);
if (FunctionScopes.back() != Scope)
delete Scope;
}

View File

@ -5552,6 +5552,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
FD = dyn_cast_or_null<FunctionDecl>(dcl);
sema::AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy();
sema::AnalysisBasedWarnings::Policy *ActivePolicy = 0;
if (FD) {
FD->setBody(Body);
@ -5620,13 +5621,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
else if (!isa<FunctionTemplateDecl>(dcl)) {
// Since the body is valid, issue any analysis-based warnings that are
// enabled.
QualType ResultType;
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(dcl)) {
AnalysisWarnings.IssueWarnings(WP, FD);
} else {
ObjCMethodDecl *MD = cast<ObjCMethodDecl>(dcl);
AnalysisWarnings.IssueWarnings(WP, MD);
}
ActivePolicy = &WP;
}
assert(ExprTemporaries.empty() && "Leftover temporaries in function");
@ -5635,7 +5630,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
if (!IsInstantiation)
PopDeclContext();
PopFunctionOrBlockScope();
PopFunctionOrBlockScope(ActivePolicy, dcl);
// If any errors have occurred, clear out any temporaries that may have
// been leftover. This ensures that these temporaries won't be picked up for

View File

@ -8890,12 +8890,8 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
BlockExpr *Result = new (Context) BlockExpr(BSI->TheDecl, BlockTy);
// Issue any analysis-based warnings.
const sema::AnalysisBasedWarnings::Policy &WP =
AnalysisWarnings.getDefaultPolicy();
AnalysisWarnings.IssueWarnings(WP, Result);
PopFunctionOrBlockScope();
const AnalysisBasedWarnings::Policy &WP = AnalysisWarnings.getDefaultPolicy();
PopFunctionOrBlockScope(&WP, Result->getBlockDecl(), Result);
return Owned(Result);
}