Index: test/CoverageMapping/break.c =================================================================== --- /dev/null +++ test/CoverageMapping/break.c @@ -0,0 +1,52 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +int main() { + int cnt = 0; + while(cnt < 100) { + break; + ++cnt; + } + while(cnt < 100) { + { + break; + ++cnt; + } + ++cnt; + } + while(cnt < 100) { + if(cnt == 0) { + break; + ++cnt; + } + ++cnt; + } + while(cnt < 100) { + if(cnt == 0) { + ++cnt; + } else { + break; + } + ++cnt; + } +} + +// CHECK: File 0, 7:12 -> 35:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:9 -> 9:18 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:20 -> 12:4 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:5 -> 11:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:9 -> 13:18 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:20 -> 19:4 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:7 -> 18:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:9 -> 20:18 = ((#0 + #3) - #4)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:20 -> 26:4 = #3[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:18 -> 24:6 = #4[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:7 -> 23:12 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:5 -> 25:10 = (#3 - #4)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:9 -> 27:18 = (#0 + #6)[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:20 -> 34:4 = #5[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:18 -> 33:10 = #6[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:12 -> 32:6 = (#5 - #6)[1] (HasCodeBefore = 0) Index: test/CoverageMapping/builtinmacro.c =================================================================== --- /dev/null +++ test/CoverageMapping/builtinmacro.c @@ -0,0 +1,20 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +// Test the coverage mapping generation for built-in macroes. + +const char *filename (const char *name) { + static const char this_file[] = __FILE__; + return this_file; +} + +// CHECK: File 0, 9:41 -> 12:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: main + +int main() { + filename(__FILE__ "test.c"); + return 0; +} Index: test/CoverageMapping/casts.c =================================================================== --- /dev/null +++ test/CoverageMapping/casts.c @@ -0,0 +1,14 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump %s | FileCheck %s + +int main() { + int window_size = (sizeof(int) <= 2 ? (unsigned)512 : 1024); + return 0; +} + +// CHECK: File 0, 7:12 -> 10:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:41 -> 8:54 = #1[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:57 -> 8:61 = (#0 - #1)[1] (HasCodeBefore = 0) Index: test/CoverageMapping/class.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/class.cpp @@ -0,0 +1,45 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +class Test { + int x; +public: + Test(int i) + : x(i != 0 ? i : 11) + { + } + ~Test() { + x = 0; + } + int getX() const { return x; } + Test(int i, int j):x(i + j){ } + void setX(int i) { + x = i; + } + inline int getXX() const { + return x*x; + } + void setX2(int i); +}; + +void Test::setX2(int i) { + x = i; +} + +int main() { + Test t(42); + int i = t.getX(); + return 0; +} + +// CHECK: File 0, 12:3 -> 13:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 14:11 -> 16:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 17:20 -> 17:33 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 18:30 -> 18:33 = 0 (HasCodeBefore = 0) +// CHECK: File 0, 19:20 -> 21:4 = 0 (HasCodeBefore = 0) +// CHECK: File 0, 22:28 -> 24:4 = 0 (HasCodeBefore = 0) +// CHECK: File 0, 28:25 -> 30:2 = #0[0] (HasCodeBefore = 0) +// CHECK: File 0, 32:12 -> 36:2 = #0[1] (HasCodeBefore = 0) Index: test/CoverageMapping/classtemplate.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/classtemplate.cpp @@ -0,0 +1,41 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +template +class Test { +public: + enum BaseType { + A, C, G, T, Invalid + }; + const static int BaseCount = 4; + double bases[BaseCount]; + + Test() { } + double get(TT position) const { + return bases[position]; + } + void set(TT position, double value) { + bases[position] = value; + } +}; + +// CHECK: Test +// CHECK: File 0, 16:10 -> 16:13 = #0[1] (HasCodeBefore = 0) + +// CHECK: get +// CHECK: File 0, 17:33 -> 19:4 = 0 (HasCodeBefore = 0) + +// CHECK: set +// CHECK: File 0, 20:39 -> 22:4 = #0[4] (HasCodeBefore = 0) + +int main() { + Test t; + t.set(Test::A, 5.5); + t.set(Test::T, 5.6); + t.set(Test::G, 5.7); + t.set(Test::C, 5.8); + return 0; +} Index: test/CoverageMapping/code.h =================================================================== --- /dev/null +++ test/CoverageMapping/code.h @@ -0,0 +1,11 @@ +x = x; +if (x == 0) { + x = 1; +} else { + x = 2; +} +if (true) { + x = x; +} else { + x = x; +} Index: test/CoverageMapping/continue.c =================================================================== --- /dev/null +++ test/CoverageMapping/continue.c @@ -0,0 +1,41 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +int main() { + int j = 0; + for(int i = 0; i < 20; ++i) { + if(i < 10) { + if(i < 5) { + continue; + j = 1; + } else { + j = 2; + } + j = 3; + if(i < 7) { + continue; + j = 4; + } else j = 5; + j = 6; + } else + j = 7; + j = 8; + } +} + +// CHECK: File 0, 7:12 -> 27:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:18 -> 9:24 = (#0 + #1)[21] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:26 -> 9:29 = #1[20] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:31 -> 26:4 = #1[20] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:16 -> 23:6 = #2[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:17 -> 14:8 = #3[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:9 -> 13:14 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:14 -> 21:13 = (#2 - #3)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:17 -> 21:8 = #4[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:9 -> 20:14 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:14 -> 22:12 = ((#2 - #3) - #4)[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:7 -> 24:12 = (#1 - #2)[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:5 -> 25:10 = ((#1 - #3) - #4)[13] (HasCodeBefore = 0) Index: test/CoverageMapping/derivedclass.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/derivedclass.cpp @@ -0,0 +1,56 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +class Base { +protected: + int x; +public: + Base(int i, int j) + : x(i) + { + } + virtual ~Base() { + x = 0; + } + int getX() const { return x; } + virtual void setX(int i) { + x = i; + } +}; + +class Derived: public Base { + int y; +public: + Derived(int i) + : Base(i, i), y(0) + { } + virtual ~Derived() { + y = 0; + } + virtual void setX(int i) { + x = y = i; + } + int getY() const { + return y; + } +}; + +// CHECK: File 0, 13:3 -> 14:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 15:19 -> 17:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 18:20 -> 18:33 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 19:28 -> 21:4 = #0[0] (HasCodeBefore = 0) +// CHECK: File 0, 29:3 -> 29:6 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 30:22 -> 32:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 33:28 -> 35:4 = #0[1] (HasCodeBefore = 0) +// CHECK: File 0, 36:20 -> 38:4 = 0 (HasCodeBefore = 0) + +int main() { + Base *B = new Derived(42); + B->setX(B->getX()); + delete B; + return 0; +} + Index: test/CoverageMapping/header1.h =================================================================== --- /dev/null +++ test/CoverageMapping/header1.h @@ -0,0 +1,42 @@ +#ifndef HEADER1_H +#define HEADER1_H + +inline void func(int i) { + int x = 0; + if (i == 0) { + x = 1; + } else { + x = 2; + } +} +static void static_func(int j) { + int x = 0; + if (j == x) { + x = !j; + } else { + x = 42; + } + j = x * j; +} +static void static_func2(int j) { + int x = 0; + if (j == x) { + x = !j; + } else { + x = 42; + } + j = x * j; +} +static void static_func3(int j) { + int x = 0; + if (j == x) { + x = !j; + } else { + x = 42; + } + j = x * j; +} + +void foo(); + +#endif // HEADER1_H Index: test/CoverageMapping/if.c =================================================================== --- /dev/null +++ test/CoverageMapping/if.c @@ -0,0 +1,69 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +int main() { + int i = 0; + if(i == 0) i = 1; + if(i == 1) + i = 2; + if(i == 0) i = 1; + if(i == 0) + i = 1; + if(i == 0) { + i = 1; + } + if(i == 0) { i = 1; + i = 2; + } + if(i != 0) { + i = 1; + } else { + i = 3; + } + i = i == 0? + i + 1 : + i + 2; + i = i == 0?i + 12:i + 10; + i = i < 20?i + 13:i + 20; + + for(int j = 0; j < 10; ++j) { + if(j < 3) { + i = 2; + } else + i = 3; + if(j < 4) i = 0; else i = 1; + if(j < 0) i = 0; else i = 1; + if(j < 0) ; else i = 1; + } + return 0; +} + +// CHECK: File 0, 7:12 -> 42:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:14 -> 9:19 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:5 -> 11:10 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:14 -> 12:19 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:5 -> 14:10 = #4[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:14 -> 17:4 = #5[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:14 -> 20:4 = #6[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:14 -> 23:4 = #7[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:10 -> 25:4 = (#0 - #7)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:9 -> 27:14 = #8[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:9 -> 28:14 = (#0 - #8)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:14 -> 29:20 = #9[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:21 -> 29:27 = (#0 - #9)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:14 -> 30:20 = #10[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:21 -> 30:27 = (#0 - #10)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:18 -> 32:24 = (#0 + #11)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:26 -> 32:29 = #11[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:31 -> 40:4 = #11[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 33:15 -> 35:6 = #12[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 36:7 -> 36:12 = (#11 - #12)[7] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 37:15 -> 37:20 = #13[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 37:27 -> 37:32 = (#11 - #13)[6] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 38:15 -> 38:20 = #14[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 38:27 -> 38:32 = (#11 - #14)[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:15 -> 39:16 = #15[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:22 -> 39:27 = (#11 - #15)[10] (HasCodeBefore = 0) Index: test/CoverageMapping/includehell.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/includehell.cpp @@ -0,0 +1,72 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + + +#define CODE \ + x = x;\ + if (x == 0) {\ + x = 1;\ + } else {\ + x = 2;\ + }\ + if (true) {\ + x = x;\ + } else { \ + x = x; \ + } + +int main() { + int x = 0; + #include "code.h" +#include "code.h" + x = 0; + CODE + x = 0; + CODE CODE + if (false) { + x = 0; CODE + } + return 0; +} + +// CHECK: File 0, 1:1 -> 9:7 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 2:13 -> 4:2 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 4:8 -> 6:2 = (#0 - #3)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:11 -> 9:2 = #4[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:8 -> 11:2 = (#0 - #4)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 21:12 -> 33:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 23:12 -> 23:20 = #0[1] (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: Expansion,File 1, 24:10 -> 24:18 = #0[1] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 1, 26:3 -> 26:7 = #0[1] (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: Expansion,File 1, 28:3 -> 28:7 = #0[1] (HasCodeBefore = 0, Expanded file = 5) +// CHECK-NEXT: Expansion,File 1, 28:8 -> 28:12 = #0[1] (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 1, 29:14 -> 31:4 = #11[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 30:12 -> 30:16 = #11[0] (HasCodeBefore = 0, Expanded file = 6) +// CHECK-NEXT: File 2, 1:1 -> 9:7 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 2:13 -> 4:2 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 4:8 -> 6:2 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 7:11 -> 9:2 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 9:8 -> 11:2 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 9:3 -> 17:9 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 10:15 -> 12:4 = #5[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 12:10 -> 14:4 = (#0 - #5)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 15:13 -> 17:4 = #6[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 17:10 -> 19:4 = (#0 - #6)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 9:3 -> 17:9 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 10:15 -> 12:4 = #9[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 12:10 -> 14:4 = (#0 - #9)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 15:13 -> 17:4 = #10[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 17:10 -> 19:4 = (#0 - #10)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 9:3 -> 17:9 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 10:15 -> 12:4 = #7[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 12:10 -> 14:4 = (#0 - #7)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 15:13 -> 17:4 = #8[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 17:10 -> 19:4 = (#0 - #8)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 9:3 -> 17:9 = #11[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 10:15 -> 12:4 = #12[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 12:10 -> 14:4 = (#11 - #12)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 15:13 -> 17:4 = #13[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 17:10 -> 19:4 = (#11 - #13)[0] (HasCodeBefore = 0) Index: test/CoverageMapping/ir.c =================================================================== --- /dev/null +++ test/CoverageMapping/ir.c @@ -0,0 +1,12 @@ +// Check the data structures emitted by coverage mapping +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm -fprofile-instr-generate -fcoverage-mapping | FileCheck %s + + +void foo(void) { } + +int main(void) { + foo(); + return 0; +} + +// CHECK: @__llvm_coverage_mapping = internal constant { i32, i32, i32, i32, [2 x { i8*, i32, i32 }], [{{[0-9]+}} x i8] } { i32 2, i32 {{[0-9]+}}, i32 {{[0-9]+}}, i32 0, [2 x { i8*, i32, i32 }] [{ i8*, i32, i32 } { i8* getelementptr inbounds ([3 x i8]* @__llvm_profile_name_foo, i32 0, i32 0), i32 3, i32 9 }, { i8*, i32, i32 } { i8* getelementptr inbounds ([4 x i8]* @__llvm_profile_name_main, i32 0, i32 0), i32 4, i32 9 }] Index: test/CoverageMapping/label.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/label.cpp @@ -0,0 +1,100 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void func() { + int i = 0; + for(i = 0; i < 10; ++i) { + if(i < 5) { + { + x: + int j = 1; + } + int m = 2; + } else + goto x; + int k = 3; + } + static int j = 0; + ++j; + if(j == 1) + goto x; +} + +// CHECK: func +// CHECK: File 0, 7:13 -> 24:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:14 -> 9:20 = (#0 + #3)[12] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:22 -> 9:25 = #3[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:27 -> 19:4 = #1[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:15 -> 16:6 = #2[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:9 -> 18:14 = #3[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:7 -> 17:13 = (#1 - #2)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:3 -> 22:12 = ((#0 + #3) - #1)[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:5 -> 23:11 = #4[1] (HasCodeBefore = 0) + +void test1(int x) { + if(x == 0) + goto a; + goto b; +a: +b: + x = x + 1; +} + +// CHECK: test1 +// CHECK: File 0, 37:19 -> 44:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:5 -> 39:11 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 40:3 -> 40:9 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 41:1 -> 41:2 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 42:1 -> 43:12 = #3[1] (HasCodeBefore = 0) + +void test2(int x) { + if(x == 0) + goto a; + else if(x == 1) goto b; +a: +b: + x = x + 1; +} + +// CHECK: test2 +// CHECK: File 0, 53:19 -> 60:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 55:5 -> 55:11 = #1[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 56:8 -> 56:17 = (#0 - #1)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 56:19 -> 56:25 = #2[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 57:1 -> 57:2 = #3[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 58:1 -> 59:12 = #4[1] (HasCodeBefore = 0) + +int main() { + int j = 0; + for(int i = 0; i < 10; ++i) { + a: + if(i < 3) + goto e; + goto c; + b: + j = 2; + c: + j = 1; + e: f: ; + } + func(); + test1(0); + test2(2); +} + +// CHECK: main +// CHECK: File 0, 70:12 -> 86:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 72:18 -> 72:24 = (#0 + #7)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 72:26 -> 72:29 = #7[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 72:31 -> 82:4 = #1[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 73:3 -> 74:13 = #2[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 75:7 -> 75:13 = #3[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 76:5 -> 76:11 = (#2 - #3)[7] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 77:3 -> 78:10 = #4[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 79:3 -> 80:10 = #5[7] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 81:3 -> 81:4 = #6[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 81:6 -> 81:10 = #7[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 83:3 -> 85:11 = ((#0 + #7) - #1)[1] (HasCodeBefore = 0) Index: test/CoverageMapping/logical.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/logical.cpp @@ -0,0 +1,48 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +int main() { + bool bt = true; + bool bf = false; + bool a = bt && bf; + a = bt && + bf; + a = bf && bt; + a = bf && + bt; + a = bf || bt; + a = bf || + bt; + a = bt || bf; + a = bt || + bf; + for(int j = 0; j < 10; ++j) { + if(j < 2 && j < 6) a = true; + a = j < 0 && j > 10; + if(j < 0 && j > 10) a = false; + a = j < 10 || j < 20; + } + return 0; +} + +// CHECK: File 0, 7:12 -> 29:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:18 -> 10:20 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:7 -> 12:9 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:13 -> 13:15 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:7 -> 15:9 = #4[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:13 -> 16:15 = #5[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:7 -> 18:9 = #6[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:13 -> 19:15 = #7[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:7 -> 21:9 = #8[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:18 -> 22:24 = (#0 + #9)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:26 -> 22:29 = #9[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:31 -> 27:4 = #9[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:17 -> 23:22 = #11[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:24 -> 23:32 = #10[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:18 -> 24:24 = #12[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:17 -> 25:23 = #14[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:25 -> 25:34 = #13[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:19 -> 26:25 = #15[0] (HasCodeBefore = 0) Index: test/CoverageMapping/loopmacro.c =================================================================== --- /dev/null +++ test/CoverageMapping/loopmacro.c @@ -0,0 +1,48 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +# define HASH_BITS 15 +#define MIN_MATCH 3 +#define H_SHIFT ((HASH_BITS+MIN_MATCH-1)/MIN_MATCH) +#define WMASK 0xFFFF +#define HASH_MASK 0xFFFF +#define UPDATE_HASH(h,c) (h = (((h)< 30:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:6 -> 29:30 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 28:7 -> 28:20 = (#0 + #1)[5] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 28:21 -> 28:29 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:21 -> 28:29 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:21 -> 28:29 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:31 -> 28:40 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:4 -> 16:23 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 14:5 -> 14:16 = (#0 + #1)[5] (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: File 1, 14:17 -> 14:22 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:17 -> 14:22 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:24 -> 14:32 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:33 -> 14:36 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:46 -> 14:49 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 9:18 -> 9:53 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 12:26 -> 12:66 = (#0 + #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 3, 12:38 -> 12:45 = (#0 + #1)[5] (HasCodeBefore = 0, Expanded file = 2) Index: test/CoverageMapping/loops.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/loops.cpp @@ -0,0 +1,65 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void rangedFor() { + int arr[] = { 1, 2, 3, 4, 5 }; + int sum = 0; + for(auto i : arr) { + sum += i; + if(i == 3) + break; + } +} + +// CHECK: rangedFor +// CHECK: File 0, 7:18 -> 15:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:21 -> 14:4 = #1[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:7 -> 13:12 = #2[1] (HasCodeBefore = 0) + +int main() { + for(int i = 0; i < 10; ++i) + ; + for(int i = 0; i < 0; ++i) + ; + for(int i = 0; + i < 10; + ++i) + { + int x = 0; + } + int j = 0; + while(j < 5) ++j; + do { + ++j; + } while(j < 10); + j = 0; + while + (j < 5) + ++j; + do + ++j; + while(j < 10); + rangedFor(); + return 0; +} + +// CHECK: main +// CHECK: File 0, 22:12 -> 47:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:18 -> 23:24 = (#0 + #1)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:26 -> 23:29 = #1[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:6 -> 24:7 = #1[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:18 -> 25:23 = (#0 + #2)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:25 -> 25:28 = #2[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:6 -> 26:7 = #2[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:7 -> 28:13 = (#0 + #3)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:7 -> 29:10 = #3[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:3 -> 32:4 = #3[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:9 -> 34:14 = (#0 + #4)[6] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:16 -> 34:19 = #4[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:6 -> 37:17 = (#0 + #5)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 40:5 -> 40:10 = (#0 + #6)[6] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 41:6 -> 41:9 = #6[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:5 -> 44:15 = (#0 + #7)[5] (HasCodeBefore = 0) Index: test/CoverageMapping/macroception.c =================================================================== --- /dev/null +++ test/CoverageMapping/macroception.c @@ -0,0 +1,49 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +#define M2 { +#define M1 M2 +#define M22 } +#define M11 M22 + +int main() M1 + return 0; +} + +// CHECK: File 0, 7:12 -> 7:13 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 8:12 -> 8:14 = #0[1] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 12:12 -> 12:14 = #0[1] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 13:3 -> 14:2 = #0[1] (HasCodeBefore = 0) + +void func2() { + int x = 0; +M11 + +// CHECK: File 0, 21:14 -> 22:12 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 23:1 -> 23:4 = #0[0] (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 1, 9:13 -> 9:14 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 2, 10:13 -> 10:16 = #0[0] (HasCodeBefore = 0, Expanded file = 1) + +void func3() M1 + int x = 0; +M11 + +// CHECK: File 0, 7:12 -> 7:13 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 8:12 -> 8:14 = #0[0] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 30:14 -> 30:16 = #0[0] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 31:3 -> 31:12 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 2, 32:1 -> 32:4 = #0[0] (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 3, 9:13 -> 9:14 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 4, 10:13 -> 10:16 = #0[0] (HasCodeBefore = 0, Expanded file = 3) + +void func4() M1 M11 + +// CHECK: File 0, 7:12 -> 7:13 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 8:12 -> 8:14 = #0[0] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 42:14 -> 42:16 = #0[0] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: Expansion,File 2, 42:17 -> 42:20 = #0[0] (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 3, 9:13 -> 9:14 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 4, 10:13 -> 10:16 = #0[0] (HasCodeBefore = 0, Expanded file = 3) Index: test/CoverageMapping/macrohell.c =================================================================== --- /dev/null +++ test/CoverageMapping/macrohell.c @@ -0,0 +1,53 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +#define MACRO { int x = 0; +#define MACRO2 MACRO +#define MACRO3 MACRO2 } +#define BEGIN { +#define END } +void foo() MACRO2 } + +// CHECK: foo +// CHECK: File 0, 7:15 -> 7:26 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 8:16 -> 8:21 = #0[1] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 12:12 -> 12:18 = #0[1] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 12:19 -> 12:20 = #0[1] (HasCodeBefore = 0) + +void foo2() MACRO3 + +// CHECK: foo2 +// CHECK: File 0, 7:15 -> 7:26 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 8:16 -> 8:21 = #0[0] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 9:16 -> 9:22 = #0[0] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 9:23 -> 9:24 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 3, 20:13 -> 20:19 = #0[0] (HasCodeBefore = 0, Expanded file = 2) + +void func() BEGIN + int x = 3; +END + +// CHECK: func +// CHECK: File 0, 10:15 -> 10:16 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 29:13 -> 29:18 = #0[1] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: File 1, 30:3 -> 30:12 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 31:1 -> 31:4 = #0[1] (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 2, 11:15 -> 11:16 = #0[1] (HasCodeBefore = 0) + +void func2() BEGIN +END + +// CHECK: func2 +// CHECK: File 0, 10:15 -> 10:16 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 40:14 -> 40:19 = #0[0] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 1, 41:1 -> 41:4 = #0[0] (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 2, 11:15 -> 11:16 = #0[0] (HasCodeBefore = 0) + +int main() { + foo(); + func(); + return 0; +} Index: test/CoverageMapping/macroparams.c =================================================================== --- /dev/null +++ test/CoverageMapping/macroparams.c @@ -0,0 +1,75 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +#define OUTBUFSIZ 1024 + +#define put_byte(c) {outbuf[outcnt++]=c;} + +/* Output a 16 bit value, lsb first */ +#define put_short(w) \ +{ if (outcnt < OUTBUFSIZ-2) { \ + outbuf[outcnt++] = ((w) & 0xff); \ + outbuf[outcnt++] = ((w) >> 8); \ + } else { \ + put_byte(((w) & 0xff)); \ + put_byte(((w) >> 8)); \ + } \ +} + +#define MACRO2(X2) (X2 + 2) +#define MACRO(X) MACRO2(x) + +int main() { + char outbuf[OUTBUFSIZ]; + unsigned outcnt = 0; + put_short(2); + unsigned short i = 42; + put_short(i); + do { + int x = 0; + MACRO(x); + } while(0); + return 0; +} + +// CHECK: File 0, 12:22 -> 20:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 13:16 -> 13:25 = #0[1] (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 0, 13:29 -> 16:4 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:10 -> 19:4 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 17:5 -> 17:13 = (#0 - #1)[0] (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: File 0, 17:14 -> 17:16 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:17 -> 17:26 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 18:5 -> 18:13 = (#0 - #1)[0] (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 0, 18:14 -> 18:16 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:17 -> 18:24 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 25:12 -> 36:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 28:3 -> 28:12 = #0[1] (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 1, 30:3 -> 30:12 = #0[1] (HasCodeBefore = 0, Expanded file = 5) +// CHECK-NEXT: File 1, 30:13 -> 30:14 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 30:13 -> 30:14 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 30:13 -> 30:14 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 30:13 -> 30:14 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 31:6 -> 34:12 = (#0 + #3)[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 33:5 -> 33:10 = (#0 + #3)[1] (HasCodeBefore = 0, Expanded file = 10) +// CHECK-NEXT: File 2, 7:19 -> 7:23 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 9:21 -> 9:42 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 9:21 -> 9:42 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 12:22 -> 20:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 13:16 -> 13:25 = #0[1] (HasCodeBefore = 0, Expanded file = 6) +// CHECK-NEXT: File 5, 13:29 -> 16:4 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 16:10 -> 19:4 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 17:5 -> 17:13 = (#0 - #2)[0] (HasCodeBefore = 0, Expanded file = 7) +// CHECK-NEXT: File 5, 17:14 -> 17:16 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 17:17 -> 17:26 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 18:5 -> 18:13 = (#0 - #2)[0] (HasCodeBefore = 0, Expanded file = 8) +// CHECK-NEXT: File 5, 18:14 -> 18:16 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 18:17 -> 18:24 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 7:19 -> 7:23 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 7, 9:21 -> 9:42 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 8, 9:21 -> 9:42 = (#0 - #2)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 9, 22:20 -> 22:28 = (#0 + #3)[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 10, 23:18 -> 23:24 = (#0 + #3)[1] (HasCodeBefore = 0, Expanded file = 9) +// CHECK-NEXT: File 10, 23:25 -> 23:26 = (#0 + #3)[1] (HasCodeBefore = 0) Index: test/CoverageMapping/macroparams2.c =================================================================== --- /dev/null +++ test/CoverageMapping/macroparams2.c @@ -0,0 +1,30 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +// A test case for when the first macro parameter is used after the second +// macro parameter. + +struct S { + int i, j; +}; + +#define MACRO(REFS, CALLS) (4 * (CALLS) < (REFS)) + +int main() { + struct S arr[32] = { 0 }; + int n = 0; + if (MACRO(arr[n].j, arr[n].i)) { + n = 1; + } + return n; +} + +// CHECK: File 0, 16:12 -> 23:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 19:7 -> 19:12 = #0[1] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 19:13 -> 19:21 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:23 -> 19:31 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:34 -> 21:4 = #1[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 14:29 -> 14:51 = #0[1] (HasCodeBefore = 0) Index: test/CoverageMapping/macros.c =================================================================== --- /dev/null +++ test/CoverageMapping/macros.c @@ -0,0 +1,46 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void bar(); +#define MACRO return; bar() +#define MACRO_2 bar() +#define MACRO_1 return; MACRO_2 + +void func() { + int i = 0; + MACRO; + i = 2; +} + +// CHECK: func +// CHECK: File 0, 12:13 -> 16:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 14:3 -> 14:8 = #0[1] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 15:3 -> 15:8 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 8:15 -> 8:21 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 8:23 -> 8:28 = 0 (HasCodeBefore = 0) + +void func2() { + int i = 0; + MACRO_1; + i = 2; +} + +// CHECK: func2 +// CHECK: File 0, 25:14 -> 29:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 27:3 -> 27:10 = #0[1] (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 28:3 -> 28:8 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:17 -> 10:23 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 10:25 -> 10:32 = 0 (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 2, 9:17 -> 9:22 = 0 (HasCodeBefore = 0) + +int main() { + func(); + func2(); + return 0; +} + +void bar() { +} Index: test/CoverageMapping/nestedclass.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/nestedclass.cpp @@ -0,0 +1,34 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +struct Test { + void emitTest() { + int i = 0; + } + struct Test2 { + void emitTest2() { + int i = 0; + } + struct Test3 { + static void emitTest3() { + int i = 0; + } + }; + }; +}; + +// CHECK: emitTest +// CHECK: File 0, 8:19 -> 10:4 = 0 (HasCodeBefore = 0) + +// CHECK: emitTest2 +// CHECK: File 0, 12:22 -> 14:6 = 0 (HasCodeBefore = 0) + +// CHECK: emitTest3 +// CHECK: File 0, 16:31 -> 18:8 = 0 (HasCodeBefore = 0) + +int main() { + return 0; +} Index: test/CoverageMapping/preprocessor.c =================================================================== --- /dev/null +++ test/CoverageMapping/preprocessor.c @@ -0,0 +1,49 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void func() { + int i = 0; +#ifdef MACRO + int x = i; +#endif +} + +// CHECK: func +// CHECK: File 0, 7:13 -> 12:2 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 9:2 -> 11:2 = 0 (HasCodeBefore = 0) + +#if 0 + int g = 0; + + void bar() { } +#endif + +int main() { + int i = 0; +#if 0 + if(i == 0) { + i = 1; + } +#endif + +#if 1 + if(i == 0) { + i = 1; + } +#else + if(i == 1) { + i = 0; + } +} +#endif + return 0; +} + +// CHECK: main +// CHECK: File 0, 24:12 -> 43:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 26:2 -> 30:2 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 33:14 -> 35:4 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 36:2 -> 41:2 = 0 (HasCodeBefore = 0) Index: test/CoverageMapping/return.c =================================================================== --- /dev/null +++ test/CoverageMapping/return.c @@ -0,0 +1,67 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void func() { + return; + int i = 0; +} + +// CHECK: func +// CHECK: File 0, 7:13 -> 10:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:3 -> 9:12 = 0 (HasCodeBefore = 0) + +void func2() { + for(int i = 0; i < 10; ++i) { + if(i > 2) { + return; + } else { + int j = 0; + } + if(i == 3) { + int j = 1; + } else { + int j = 2; + } + } +} + +// CHECK: func2 +// CHECK: File 0, 16:14 -> 29:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:18 -> 17:24 = ((#0 + #1) - #2)[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:26 -> 17:29 = (#1 - #2)[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:31 -> 28:4 = #1[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:15 -> 20:6 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:12 -> 25:11 = (#1 - #2)[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:16 -> 25:6 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:12 -> 27:6 = ((#1 - #2) - #3)[3] (HasCodeBefore = 0) + +void func3(int x) { + if(x > 5) { + while(x >= 9) { + return; + --x; + } + int i = 0; + } + int j = 0; +} + +// CHECK: func3 +// CHECK: File 0, 41:19 -> 50:2 = #0[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 42:13 -> 48:4 = #1[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:11 -> 43:17 = #1[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:19 -> 46:6 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 45:7 -> 45:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 47:5 -> 47:14 = (#1 - #2)[3] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 49:3 -> 49:12 = (#0 - #2)[9] (HasCodeBefore = 0) + +int main() { + func(); + func2(); + for(int i = 0; i < 10; ++i) + func3(i); + return 0; +} Index: test/CoverageMapping/switch.c =================================================================== --- /dev/null +++ test/CoverageMapping/switch.c @@ -0,0 +1,84 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void foo(int i) { + switch(i) { + case 1: + return; + case 2: + break; + } + int x = 0; +} + +// CHECK: foo +// CHECK: File 0, 7:17 -> 15:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:3 -> 10:11 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:3 -> 12:10 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:3 -> 14:12 = #1[0] (HasCodeBefore = 0) + +int main() { + int i = 0; + switch(i) { + case 0: + i = 1; + break; + case 1: + i = 2; + break; + default: + break; + } + switch(i) { + case 0: + i = 1; + break; + case 1: + i = 2; + default: + break; + } + + + switch(i) { + case 1: + case 2: + i = 11; + case 3: + case 4: + i = 99; + } + switch(i) { + case 1: + return 1; + break; + case 2: + break; + } + + foo(1); + return 0; +} + +// CHECK: main +// CHECK: File 0, 23:12 -> 64:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:3 -> 28:10 = #2[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:3 -> 31:10 = #3[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:3 -> 33:10 = #4[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:3 -> 35:14 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 36:3 -> 38:10 = #6[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:3 -> 40:10 = #7[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 41:3 -> 42:10 = (#7 + #8)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:3 -> 46:14 = #5[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 47:3 -> 47:10 = #10[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 48:3 -> 49:11 = (#10 + #11)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 50:3 -> 50:10 = ((#10 + #11) + #12)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 51:3 -> 52:11 = (((#10 + #11) + #12) + #13)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 53:3 -> 54:14 = #9[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 55:3 -> 56:13 = #15[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 57:5 -> 57:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 58:3 -> 59:10 = #16[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 60:3 -> 63:11 = #14[1] (HasCodeBefore = 0) Index: test/CoverageMapping/templates.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/templates.cpp @@ -0,0 +1,37 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +template +void unused(T x) { + return; +} + +template +int func(T x) { + if(x) + return 0; + else + return 1; + int j = 1; +} + +// CHECK: func +// CHECK: File 0, 13:15 -> 19:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:5 -> 15:13 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:5 -> 17:13 = (#0 - #1)[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:3 -> 18:12 = 0 (HasCodeBefore = 0) + +// CHECK: func +// CHECK: File 0, 13:15 -> 19:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:5 -> 15:13 = #1[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:5 -> 17:13 = (#0 - #1)[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:3 -> 18:12 = 0 (HasCodeBefore = 0) + +int main() { + func(0); + func(true); + return 0; +} Index: test/CoverageMapping/test.c =================================================================== --- /dev/null +++ test/CoverageMapping/test.c @@ -0,0 +1,43 @@ +// RUN: mkdir -p %t +// RUN: %clang %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +void bar(); +static void static_func(); + +int main() { + for(int i = 0; i < 10; ++i) { + bar(); + } + static_func(); + return 0; +} + +// CHECK: File 0, 10:12 -> 16:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:18 -> 11:24 = (#0 + #1)[11] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:26 -> 11:29 = #1[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:31 -> 13:4 = #1[10] (HasCodeBefore = 0) + +void foo() { + if(1) { + int i = 0; + } +} + +// CHECK: File 0, 23:12 -> 27:2 = #0[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:9 -> 26:4 = #1[0] (HasCodeBefore = 0) + +void bar() { +} + +// CHECK: File 0, 32:12 -> 33:2 = #0[10] (HasCodeBefore = 0) + +void static_func() { } + +// CHECK: File 0, 37:20 -> 37:23 = #0[1] (HasCodeBefore = 0) + +static void func() { } + +// CHECK: File 0, 41:20 -> 41:23 = 0 (HasCodeBefore = 0) Index: test/CoverageMapping/trycatch.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/trycatch.cpp @@ -0,0 +1,54 @@ +// RUN: mkdir -p %t +// RUN: %clangxx %s -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +class Error { +}; + +class ImportantError { +}; + +class Warning { +}; + +void func(int i) { + if(i % 2) + throw Error(); + else if(i == 8) + throw ImportantError(); +} + +// CHECK: func +// CHECK: File 0, 16:18 -> 21:2 = #0[9] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:5 -> 18:16 = #1[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:8 -> 19:17 = (#0 - #1)[5] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:5 -> 20:25 = #2[1] (HasCodeBefore = 0) + +int main() { + int j = 0; + for(int i = 0; i < 9; ++i) { + try { + func(i); + } catch(const Error &e) { + j = 1; + } catch(const ImportantError &e) { + j = 11; + } + catch(const Warning &w) { + j = 0; + } + } + return 0; +} + +// CHECK: main +// CHECK: File 0, 29:12 -> 44:2 = #0[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 31:18 -> 31:23 = (#0 + #2)[10] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 31:25 -> 31:28 = #2[9] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 31:30 -> 42:4 = #1[9] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:29 -> 36:12 = #3[4] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 36:38 -> 39:10 = #4[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:29 -> 41:6 = #5[0] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:3 -> 43:11 = ((#0 + #2) - #1)[1] (HasCodeBefore = 0) Index: test/CoverageMapping/tu1.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/tu1.cpp @@ -0,0 +1,22 @@ +// RUN: mkdir -p %t +// RUN: %clang %s %S/tu2.cpp -fprofile-instr-generate -fcoverage-mapping -O2 -o %t/test +// RUN: (cd %t; %t/test) +// RUN: llvm-profdata merge %t/default.profraw -o %t/pgodata +// RUN: llvm-cov report %t/test -instr-profile %t/pgodata -dump | FileCheck %s + +#include "header1.h" + +int main() { + func(1); + static_func(2); + static_func2(3); + foo(); +} + +// CHECK: func +// CHECK: File 0, 4:25 -> 11:2 = #0[2] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:15 -> 8:4 = #1[1] (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:10 -> 10:4 = (#0 - #1)[1] (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 7:10 -> 7:21 = #0[2] (HasCodeBefore = 0, Expanded file = 0) + +// CHECK-NEXT: foo Index: test/CoverageMapping/tu2.cpp =================================================================== --- /dev/null +++ test/CoverageMapping/tu2.cpp @@ -0,0 +1,9 @@ +// This isn't actually a test, this file is part of the test described by tu1.cpp +// RUN: true + +#include "header1.h" + +void foo() { + func(0); + static_func(1); +}