[PATCH] D34361: [analyzer] MinComplexityConstraint now early exits and only does one macro stack lookup
Raphael Isemann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 3 06:49:04 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312440: [analyzer] MinComplexityConstraint now early exits and only does one macro… (authored by teemperor).
Changed prior to commit:
https://reviews.llvm.org/D34361?vs=113692&id=113693#toc
Repository:
rL LLVM
https://reviews.llvm.org/D34361
Files:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
Index: cfe/trunk/include/clang/Analysis/CloneDetection.h
===================================================================
--- cfe/trunk/include/clang/Analysis/CloneDetection.h
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h
@@ -288,14 +288,19 @@
MinComplexityConstraint(unsigned MinComplexity)
: MinComplexity(MinComplexity) {}
- size_t calculateStmtComplexity(const StmtSequence &Seq,
+ /// Calculates the complexity of the given StmtSequence.
+ /// \param Limit The limit of complexity we probe for. After reaching
+ /// this limit during calculation, this method is exiting
+ /// early to improve performance and returns this limit.
+ size_t calculateStmtComplexity(const StmtSequence &Seq, std::size_t Limit,
const std::string &ParentMacroStack = "");
void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
CloneConstraint::filterGroups(
CloneGroups, [this](const CloneDetector::CloneGroup &A) {
if (!A.empty())
- return calculateStmtComplexity(A.front()) < MinComplexity;
+ return calculateStmtComplexity(A.front(), MinComplexity) <
+ MinComplexity;
else
return false;
});
Index: cfe/trunk/lib/Analysis/CloneDetection.cpp
===================================================================
--- cfe/trunk/lib/Analysis/CloneDetection.cpp
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp
@@ -422,19 +422,18 @@
}
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;
size_t Complexity = 1;
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,22 +443,25 @@
// 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;
}
// Iterate over the Stmts in the StmtSequence and add their complexity values
// to the current complexity value.
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34361.113693.patch
Type: text/x-patch
Size: 3562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170903/f5ec8d61/attachment-0001.bin>
More information about the cfe-commits
mailing list