xref: /llvm-project/clang/test/Tooling/clang-diff-basic.cpp (revision 2b955ffaed14af72b381fc7ee389c3deaaf9c6d8)
1a29d6aecSJohannes Altmanninger // RUN: clang-diff -dump-matches %S/Inputs/clang-diff-basic-src.cpp %s -- | FileCheck %s
2a75b2cacSAlex Lorenz 
3a75b2cacSAlex Lorenz // CHECK: Match TranslationUnitDecl{{.*}} to TranslationUnitDecl
4a75b2cacSAlex Lorenz // CHECK: Match NamespaceDecl: src{{.*}} to NamespaceDecl: dst
5a75b2cacSAlex Lorenz namespace dst {
6a75b2cacSAlex Lorenz // CHECK-NOT: Match NamespaceDecl: src{{.*}} to NamespaceDecl: inner
7a75b2cacSAlex Lorenz namespace inner {
foo()8a75b2cacSAlex Lorenz void foo() {
9a75b2cacSAlex Lorenz   // CHECK: Match IntegerLiteral: 321{{.*}} to IntegerLiteral: 322
10a75b2cacSAlex Lorenz   int x = 322;
11a75b2cacSAlex Lorenz }
12a75b2cacSAlex Lorenz }
13a75b2cacSAlex Lorenz 
14*2b955ffaSJohannes Altmanninger // CHECK: Match DeclRefExpr: :foo{{.*}} to DeclRefExpr: :inner::foo
main()15a75b2cacSAlex Lorenz void main() { inner::foo(); }
16a75b2cacSAlex Lorenz 
17a75b2cacSAlex Lorenz // CHECK: Match StringLiteral: foo{{.*}} to StringLiteral: foo
18a75b2cacSAlex Lorenz const char *b = "f" "o" "o";
19a75b2cacSAlex Lorenz 
20a75b2cacSAlex Lorenz // unsigned is canonicalized to unsigned int
21*2b955ffaSJohannes Altmanninger // CHECK: Match TypedefDecl: :nat;unsigned int;{{.*}} to TypedefDecl: :nat;unsigned int;
22a75b2cacSAlex Lorenz typedef unsigned nat;
23a75b2cacSAlex Lorenz 
24*2b955ffaSJohannes Altmanninger // CHECK: Match VarDecl: :p(int){{.*}} to VarDecl: :prod(double)
25*2b955ffaSJohannes Altmanninger // CHECK: Update VarDecl: :p(int){{.*}} to :prod(double)
26e0fe5cd4SJohannes Altmanninger // CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: *
27a75b2cacSAlex Lorenz double prod = 1 * 2 * 10;
28a75b2cacSAlex Lorenz // CHECK: Update DeclRefExpr
29a75b2cacSAlex Lorenz int squared = prod * prod;
30a75b2cacSAlex Lorenz 
31a75b2cacSAlex Lorenz class X {
foo(int i)32a75b2cacSAlex Lorenz   const char *foo(int i) {
33a75b2cacSAlex Lorenz     if (i == 0)
34a75b2cacSAlex Lorenz       return "Bar";
35a75b2cacSAlex Lorenz     // CHECK: Insert IfStmt{{.*}} into IfStmt
36a75b2cacSAlex Lorenz     // CHECK: Insert BinaryOperator: =={{.*}} into IfStmt
37a75b2cacSAlex Lorenz     else if (i == -1)
38a75b2cacSAlex Lorenz       return "foo";
39a75b2cacSAlex Lorenz     return 0;
40a75b2cacSAlex Lorenz   }
X()41e0fe5cd4SJohannes Altmanninger   X(){}
42a75b2cacSAlex Lorenz };
43a75b2cacSAlex Lorenz }
44e0fe5cd4SJohannes Altmanninger 
4551321aefSJohannes Altmanninger // CHECK: Move CompoundStmt{{.*}} into CompoundStmt
m()46e0fe5cd4SJohannes Altmanninger void m() { { int x = 0 + 0 + 0; } }
47e0fe5cd4SJohannes Altmanninger // CHECK: Update and Move IntegerLiteral: 7{{.*}} into BinaryOperator: +({{.*}}) at 1
48e0fe5cd4SJohannes Altmanninger int um = 1 + 7;
49e0fe5cd4SJohannes Altmanninger 
5051321aefSJohannes Altmanninger namespace {
5151321aefSJohannes Altmanninger // match with parents of different type
520dd86dc5SJohannes Altmanninger // CHECK: Match FunctionDecl: f1{{.*}} to FunctionDecl: (anonymous namespace)::f1
f1()5351321aefSJohannes Altmanninger void f1() {{ (void) __func__;;; }}
5451321aefSJohannes Altmanninger }
5551321aefSJohannes Altmanninger 
56e0fe5cd4SJohannes Altmanninger // CHECK: Delete AccessSpecDecl: public
57e0fe5cd4SJohannes Altmanninger // CHECK: Delete CXXMethodDecl
58