xref: /llvm-project/clang/test/Tooling/clang-diff-bottomup.cpp (revision 0dd86dc5f1552e67559af03a1676bc30eca4317a)
1d1969307SJohannes Altmanninger // RUN: %clang_cc1 -E %s > %t.src.cpp
2d1969307SJohannes Altmanninger // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
3d1969307SJohannes Altmanninger // RUN: clang-diff -dump-matches -s=0 %t.src.cpp %t.dst.cpp -- | FileCheck %s
4d1969307SJohannes Altmanninger //
5d1969307SJohannes Altmanninger // Test the bottom-up matching, with maxsize set to 0, so that the optimal matching will never be applied.
6d1969307SJohannes Altmanninger 
7d1969307SJohannes Altmanninger #ifndef DEST
8d1969307SJohannes Altmanninger 
f1()9d1969307SJohannes Altmanninger void f1() { ; {{;}} }
f2()10d1969307SJohannes Altmanninger void f2() { ;; {{;}} }
11d1969307SJohannes Altmanninger 
12d1969307SJohannes Altmanninger #else
13d1969307SJohannes Altmanninger 
14d1969307SJohannes Altmanninger // Jaccard similarity threshold is 0.5.
15d1969307SJohannes Altmanninger 
f1()16d1969307SJohannes Altmanninger void f1() {
17d1969307SJohannes Altmanninger // CompoundStmt: 3 matched descendants, subtree sizes 4 and 5
18d1969307SJohannes Altmanninger // Jaccard similarity = 3 / (4 + 5 - 3) = 3 / 6 >= 0.5
19*0dd86dc5SJohannes Altmanninger // CHECK: Match FunctionDecl: f1(void ())(1) to FunctionDecl: f1(void ())(1)
20d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(2) to CompoundStmt(2)
21d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(4) to CompoundStmt(3)
22d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(5) to CompoundStmt(4)
23d1969307SJohannes Altmanninger // CHECK: Match NullStmt(6) to NullStmt(5)
24d1969307SJohannes Altmanninger   {{;}} ;;
25d1969307SJohannes Altmanninger }
26d1969307SJohannes Altmanninger 
f2()27d1969307SJohannes Altmanninger void f2() {
28d1969307SJohannes Altmanninger // CompoundStmt: 3 matched descendants, subtree sizes 4 and 5
29d1969307SJohannes Altmanninger // Jaccard similarity = 3 / (5 + 6 - 3) = 3 / 8 < 0.5
30d1969307SJohannes Altmanninger // CHECK-NOT: Match FunctionDecl(9)
31d1969307SJohannes Altmanninger // CHECK-NOT: Match CompoundStmt(10)
32d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(11) to CompoundStmt(10)
33d1969307SJohannes Altmanninger // CHECK: Match CompoundStmt(12) to CompoundStmt(11)
34d1969307SJohannes Altmanninger // CHECK: Match NullStmt(13) to NullStmt(12)
35d1969307SJohannes Altmanninger // CHECK-NOT: Match NullStmt(13)
36d1969307SJohannes Altmanninger   {{;}} ;;;
37d1969307SJohannes Altmanninger }
38d1969307SJohannes Altmanninger 
39d1969307SJohannes Altmanninger #endif
40