summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-10-09 16:55:15 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-10-09 17:25:28 +0200
commit7c4d3ea6ba4d42b4dda5148a00c8c411b5d7703d (patch)
tree15cfb902f17f482cd7246d242ee8d7aeb40a4966 /compilerplugins
parent4d3c6a04995a19209c3a66b92fddbb50c92418b7 (diff)
don't check next statement after if body if there's also an else part
Change-Id: I04265acd821187f529562691f35ede93b84368fa
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/bodynotinblock.cxx9
-rw-r--r--compilerplugins/clang/bodynotinblock.hxx2
2 files changed, 8 insertions, 3 deletions
diff --git a/compilerplugins/clang/bodynotinblock.cxx b/compilerplugins/clang/bodynotinblock.cxx
index 9c047c501fca..f13eb9392357 100644
--- a/compilerplugins/clang/bodynotinblock.cxx
+++ b/compilerplugins/clang/bodynotinblock.cxx
@@ -54,7 +54,7 @@ void BodyNotInBlock::traverseStatement( const Stmt* stmt, StmtParents& parents )
parents.push_back( *it );
if( const IfStmt* ifstmt = dyn_cast< IfStmt >( *it ))
{
- checkBody( ifstmt->getThen(), parents, 0 );
+ checkBody( ifstmt->getThen(), parents, 0, ifstmt->getElse() != NULL );
checkBody( ifstmt->getElse(), parents, 0 );
}
else if( const WhileStmt* whilestmt = dyn_cast< WhileStmt >( *it ))
@@ -70,7 +70,7 @@ void BodyNotInBlock::traverseStatement( const Stmt* stmt, StmtParents& parents )
parents.pop_back();
}
-void BodyNotInBlock::checkBody( const Stmt* body, const StmtParents& parents, int stmtType )
+void BodyNotInBlock::checkBody( const Stmt* body, const StmtParents& parents, int stmtType, bool dontGoUp )
{
if( body == NULL || parents.size() < 2 )
return;
@@ -127,6 +127,11 @@ void BodyNotInBlock::checkBody( const Stmt* body, const StmtParents& parents, in
// make it visible the two statements are not in the same body.
if( dyn_cast< CompoundStmt >( parents[ parent_pos ] ))
return;
+ // If the body to be checked is a body of an if statement that has also
+ // an else part, don't go up, the else is after the body and should make
+ // it clear the body does not continue there.
+ if( dontGoUp )
+ return;
}
}
diff --git a/compilerplugins/clang/bodynotinblock.hxx b/compilerplugins/clang/bodynotinblock.hxx
index 9846d7a0e567..a2c47e6683cd 100644
--- a/compilerplugins/clang/bodynotinblock.hxx
+++ b/compilerplugins/clang/bodynotinblock.hxx
@@ -27,7 +27,7 @@ class BodyNotInBlock
private:
typedef std::vector< const Stmt* > StmtParents;
void traverseStatement( const Stmt* stmt, StmtParents& parents );
- void checkBody( const Stmt* body, const StmtParents& parents, int stmtType );
+ void checkBody( const Stmt* body, const StmtParents& parents, int stmtType, bool dontGoUp = false );
};
} // namespace