summaryrefslogtreecommitdiff
path: root/unittests/Analysis
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2017-04-05 15:06:17 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2017-04-05 15:06:17 +0000
commit727ea63e6e82677f6e10e05e08bc7d6bdbae3111 (patch)
tree4ee5885552a89173f552ac05ebfbb233fcd09687 /unittests/Analysis
parenta61d7c54b0ed55119636b7d922ab5d9c5747fe04 (diff)
downloadclang-727ea63e6e82677f6e10e05e08bc7d6bdbae3111.tar.gz
Revert "[analyzer] Add a modular constraint system to the CloneDetector"
This reverts commit r299544. Crashes on tests on some buildbots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299550 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Analysis')
-rw-r--r--unittests/Analysis/CMakeLists.txt5
-rw-r--r--unittests/Analysis/CloneDetectionTest.cpp110
2 files changed, 2 insertions, 113 deletions
diff --git a/unittests/Analysis/CMakeLists.txt b/unittests/Analysis/CMakeLists.txt
index 62db8f652e..926f586be3 100644
--- a/unittests/Analysis/CMakeLists.txt
+++ b/unittests/Analysis/CMakeLists.txt
@@ -2,12 +2,11 @@ set(LLVM_LINK_COMPONENTS
Support
)
-add_clang_unittest(ClangAnalysisTests
+add_clang_unittest(CFGTests
CFGTest.cpp
- CloneDetectionTest.cpp
)
-target_link_libraries(ClangAnalysisTests
+target_link_libraries(CFGTests
clangAnalysis
clangAST
clangASTMatchers
diff --git a/unittests/Analysis/CloneDetectionTest.cpp b/unittests/Analysis/CloneDetectionTest.cpp
deleted file mode 100644
index d9bab9ea96..0000000000
--- a/unittests/Analysis/CloneDetectionTest.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-//===- unittests/Analysis/CloneDetectionTest.cpp - Clone detection tests --===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/RecursiveASTVisitor.h"
-#include "clang/Analysis/CloneDetection.h"
-#include "clang/Tooling/Tooling.h"
-#include "gtest/gtest.h"
-
-namespace clang {
-namespace analysis {
-namespace {
-
-class CloneDetectionVisitor
- : public RecursiveASTVisitor<CloneDetectionVisitor> {
-
- CloneDetector &Detector;
-
-public:
- explicit CloneDetectionVisitor(CloneDetector &D) : Detector(D) {}
-
- bool VisitFunctionDecl(FunctionDecl *D) {
- Detector.analyzeCodeBody(D);
- return true;
- }
-};
-
-/// Example constraint for testing purposes.
-/// Filters out all statements that are in a function which name starts with
-/// "bar".
-class NoBarFunctionConstraint {
-public:
- void constrain(std::vector<CloneDetector::CloneGroup> &CloneGroups) {
- CloneConstraint::splitCloneGroups(
- CloneGroups, [](const StmtSequence &A, const StmtSequence &B) {
- // Check if one of the sequences is in a function which name starts
- // with "bar".
- for (const StmtSequence &Arg : {A, B}) {
- if (const auto *D =
- dyn_cast<const FunctionDecl>(Arg.getContainingDecl())) {
- if (D->getNameAsString().find("bar") == 0)
- return false;
- }
- }
- return true;
- });
- }
-};
-
-TEST(CloneDetector, NoPostOrderTraversal) {
- auto ASTUnit =
- clang::tooling::buildASTFromCode("void foo1(int &a1) { a1++; }\n"
- "void foo2(int &a2) { a2++; }\n"
- "void bar1(int &a3) { a3++; }\n"
- "void bar2(int &a4) { a4++; }\n");
- auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
-
- CloneDetector Detector;
- // Push all the function bodies into the detector.
- CloneDetectionVisitor Visitor(Detector);
- Visitor.TraverseTranslationUnitDecl(TU);
-
- // Find clones with the usual settings, but but we want to filter out
- // all statements from functions which names start with "bar".
- std::vector<CloneDetector::CloneGroup> CloneGroups;
- Detector.findClones(CloneGroups, NoBarFunctionConstraint(),
- RecursiveCloneTypeIIConstraint(),
- MinComplexityConstraint(2), MinGroupSizeConstraint(2),
- OnlyLargestCloneConstraint());
-
- ASSERT_EQ(CloneGroups.size(), 1u);
- ASSERT_EQ(CloneGroups.front().size(), 2u);
-
- for (auto &Clone : CloneGroups.front()) {
- const auto ND = dyn_cast<const FunctionDecl>(Clone.getContainingDecl());
- ASSERT_TRUE(ND != nullptr);
- // Check that no function name starting with "bar" is in the results...
- ASSERT_TRUE(ND->getNameAsString().find("bar") != 0);
- }
-
- // Retry above's example without the filter...
- CloneGroups.clear();
-
- Detector.findClones(CloneGroups, RecursiveCloneTypeIIConstraint(),
- MinComplexityConstraint(2), MinGroupSizeConstraint(2),
- OnlyLargestCloneConstraint());
- ASSERT_EQ(CloneGroups.size(), 1u);
- ASSERT_EQ(CloneGroups.front().size(), 4u);
-
- // Count how many functions with the bar prefix we have in the results.
- int FoundFunctionsWithBarPrefix = 0;
- for (auto &Clone : CloneGroups.front()) {
- const auto ND = dyn_cast<const FunctionDecl>(Clone.getContainingDecl());
- ASSERT_TRUE(ND != nullptr);
- // This time check that we picked up the bar functions from above
- if (ND->getNameAsString().find("bar") == 0) {
- FoundFunctionsWithBarPrefix++;
- }
- }
- // We should have found the two functions bar1 and bar2.
- ASSERT_EQ(FoundFunctionsWithBarPrefix, 2);
-}
-} // namespace
-} // namespace analysis
-} // namespace clang