summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CloneDetection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Analysis/CloneDetection.cpp')
-rw-r--r--clang/lib/Analysis/CloneDetection.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/clang/lib/Analysis/CloneDetection.cpp b/clang/lib/Analysis/CloneDetection.cpp
index 8c833f47f04..acc1525ce4c 100644
--- a/clang/lib/Analysis/CloneDetection.cpp
+++ b/clang/lib/Analysis/CloneDetection.cpp
@@ -422,7 +422,8 @@ void RecursiveCloneTypeIIVerifyConstraint::constrain(
}
size_t MinComplexityConstraint::calculateStmtComplexity(
- const StmtSequence &Seq, const std::string &ParentMacroStack) {
+ const StmtSequence &Seq, std::size_t Limit,
+ const std::string &ParentMacroStack) {
if (Seq.empty())
return 0;
@@ -431,10 +432,8 @@ size_t MinComplexityConstraint::calculateStmtComplexity(
ASTContext &Context = Seq.getASTContext();
// Look up what macros expanded into the current statement.
- std::string StartMacroStack =
+ std::string MacroStack =
data_collection::getMacroStack(Seq.getStartLoc(), Context);
- std::string EndMacroStack =
- data_collection::getMacroStack(Seq.getEndLoc(), Context);
// First, check if ParentMacroStack is not empty which means we are currently
// dealing with a parent statement which was expanded from a macro.
@@ -444,8 +443,7 @@ size_t MinComplexityConstraint::calculateStmtComplexity(
// macro expansion will only increase the total complexity by one.
// Note: This is not the final complexity of this statement as we still
// add the complexity of the child statements to the complexity value.
- if (!ParentMacroStack.empty() && (StartMacroStack == ParentMacroStack &&
- EndMacroStack == ParentMacroStack)) {
+ if (!ParentMacroStack.empty() && MacroStack == ParentMacroStack) {
Complexity = 0;
}
@@ -454,12 +452,16 @@ size_t MinComplexityConstraint::calculateStmtComplexity(
if (Seq.holdsSequence()) {
for (const Stmt *S : Seq) {
Complexity += calculateStmtComplexity(
- StmtSequence(S, Seq.getContainingDecl()), StartMacroStack);
+ StmtSequence(S, Seq.getContainingDecl()), Limit, MacroStack);
+ if (Complexity >= Limit)
+ return Limit;
}
} else {
for (const Stmt *S : Seq.front()->children()) {
Complexity += calculateStmtComplexity(
- StmtSequence(S, Seq.getContainingDecl()), StartMacroStack);
+ StmtSequence(S, Seq.getContainingDecl()), Limit, MacroStack);
+ if (Complexity >= Limit)
+ return Limit;
}
}
return Complexity;
OpenPOWER on IntegriCloud