Index: cfe/trunk/test/CoverageMapping/Inputs/code.h =================================================================== --- cfe/trunk/test/CoverageMapping/Inputs/code.h +++ cfe/trunk/test/CoverageMapping/Inputs/code.h @@ -0,0 +1,11 @@ +x = x; +if (x == 0) { + x = 1; +} else { + x = 2; +} +if (true) { + x = x; +} else { + x = x; +} Index: cfe/trunk/test/CoverageMapping/Inputs/header1.h =================================================================== --- cfe/trunk/test/CoverageMapping/Inputs/header1.h +++ cfe/trunk/test/CoverageMapping/Inputs/header1.h @@ -0,0 +1,31 @@ +#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; +} + +#endif // HEADER1_H Index: cfe/trunk/test/CoverageMapping/break.c =================================================================== --- cfe/trunk/test/CoverageMapping/break.c +++ cfe/trunk/test/CoverageMapping/break.c @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name break.c %s | 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, 3:12 -> 31:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:9 -> 5:18 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:20 -> 8:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:5 -> 7:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:9 -> 9:18 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:20 -> 15:4 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:7 -> 14:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:9 -> 16:18 = ((#0 + #3) - #4) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:20 -> 22:4 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:18 -> 20:6 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:7 -> 19:12 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:5 -> 21:10 = (#3 - #4) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:9 -> 23:18 = (#0 + #6) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:20 -> 30:4 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:18 -> 29:10 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:12 -> 28:6 = (#5 - #6) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/builtinmacro.c =================================================================== --- cfe/trunk/test/CoverageMapping/builtinmacro.c +++ cfe/trunk/test/CoverageMapping/builtinmacro.c @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name builtinmacro.c %s | 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: filename +// CHECK-NEXT: File 0, 5:41 -> 8:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: main + +int main() { + filename(__FILE__ "test.c"); + return 0; +} Index: cfe/trunk/test/CoverageMapping/casts.c =================================================================== --- cfe/trunk/test/CoverageMapping/casts.c +++ cfe/trunk/test/CoverageMapping/casts.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name casts.c %s | FileCheck %s + +int main() { + int window_size = (sizeof(int) <= 2 ? (unsigned)512 : 1024); + return 0; +} + +// CHECK: File 0, 3:12 -> 6:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 4:41 -> 4:54 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 4:57 -> 4:61 = (#0 - #1) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/class.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/class.cpp +++ cfe/trunk/test/CoverageMapping/class.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name class.cpp %s | 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, 24:25 -> 26:2 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 28:12 -> 32:2 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 10:11 -> 12:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 13:20 -> 13:33 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 8:3 -> 9:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 14:30 -> 14:33 = 0 (HasCodeBefore = 0) +// CHECK: File 0, 15:20 -> 17:4 = 0 (HasCodeBefore = 0) +// CHECK: File 0, 18:28 -> 20:4 = 0 (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/classtemplate.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/classtemplate.cpp +++ cfe/trunk/test/CoverageMapping/classtemplate.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %s | 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: set +// CHECK-NEXT: File 0, 16:39 -> 18:4 = #0 (HasCodeBefore = 0) + +// CHECK-NEXT: Test +// CHECK-NEXT: File 0, 12:10 -> 12:13 = #0 (HasCodeBefore = 0) + +// CHECK-NEXT: get +// CHECK-NEXT: File 0, 13:33 -> 15:4 = 0 (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: cfe/trunk/test/CoverageMapping/continue.c =================================================================== --- cfe/trunk/test/CoverageMapping/continue.c +++ cfe/trunk/test/CoverageMapping/continue.c @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name continue.c %s | 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, 3:12 -> 23:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:18 -> 5:24 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:26 -> 5:29 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:31 -> 22:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:16 -> 19:6 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:17 -> 10:8 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:9 -> 9:14 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:14 -> 17:13 = (#2 - #3) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:17 -> 17:8 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:9 -> 16:14 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:14 -> 18:12 = ((#2 - #3) - #4) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:7 -> 20:12 = (#1 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:5 -> 21:10 = ((#1 - #3) - #4) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/derivedclass.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/derivedclass.cpp +++ cfe/trunk/test/CoverageMapping/derivedclass.cpp @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name derivedclass.cpp %s | 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, 14:20 -> 14:33 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 25:3 -> 25:6 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 29:28 -> 31:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 26:22 -> 28:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 11:19 -> 13:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 15:28 -> 17:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 9:3 -> 10:4 = #0 (HasCodeBefore = 0) +// CHECK: File 0, 32:20 -> 34:4 = 0 (HasCodeBefore = 0) + +int main() { + Base *B = new Derived(42); + B->setX(B->getX()); + delete B; + return 0; +} Index: cfe/trunk/test/CoverageMapping/header.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/header.cpp +++ cfe/trunk/test/CoverageMapping/header.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name tu1.cpp %s | FileCheck %s + +#include "Inputs/header1.h" + +int main() { + func(1); + static_func(2); +} + +// CHECK: static_func +// CHECK-NEXT: File 0, 12:32 -> 20:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:15 -> 16:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:10 -> 18:4 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 3:10 -> 3:28 = #0 (HasCodeBefore = 0, Expanded file = 0) + +// CHECK-NEXT: func +// CHECK-NEXT: File 0, 4:25 -> 11:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:15 -> 8:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:10 -> 10:4 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 3:10 -> 3:28 = #0 (HasCodeBefore = 0, Expanded file = 0) + +// CHECK-NEXT: static_func2 +// CHECK-NEXT: File 0, 21:33 -> 29:2 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 3:10 -> 3:28 = 0 (HasCodeBefore = 0, Expanded file = 0) Index: cfe/trunk/test/CoverageMapping/if.c =================================================================== --- cfe/trunk/test/CoverageMapping/if.c +++ cfe/trunk/test/CoverageMapping/if.c @@ -0,0 +1,65 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name if.c %s | 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, 3:12 -> 38:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:14 -> 5:19 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:5 -> 7:10 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:14 -> 8:19 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 10:5 -> 10:10 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:14 -> 13:4 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:14 -> 16:4 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:14 -> 19:4 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:10 -> 21:4 = (#0 - #7) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 23:9 -> 23:14 = #8 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:9 -> 24:14 = (#0 - #8) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:14 -> 25:20 = #9 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:21 -> 25:27 = (#0 - #9) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:14 -> 26:20 = #10 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:21 -> 26:27 = (#0 - #10) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:18 -> 28:24 = (#0 + #11) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:26 -> 28:29 = #11 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:31 -> 36:4 = #11 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:15 -> 31:6 = #12 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:7 -> 32:12 = (#11 - #12) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 33:15 -> 33:20 = #13 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 33:27 -> 33:32 = (#11 - #13) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:15 -> 34:20 = #14 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 34:27 -> 34:32 = (#11 - #14) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:15 -> 35:16 = #15 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:22 -> 35:27 = (#11 - #15) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/includehell.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/includehell.cpp +++ cfe/trunk/test/CoverageMapping/includehell.cpp @@ -0,0 +1,67 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name includehell.cpp %s | 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 "Inputs/code.h" +#include "Inputs/code.h" + x = 0; + CODE + x = 0; + CODE CODE + if (false) { + x = 0; CODE + } + return 0; +} + +// CHECK: File 0, 1:1 -> 9:7 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 2:13 -> 4:2 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 4:8 -> 6:2 = (#0 - #3) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:11 -> 9:2 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:8 -> 11:2 = (#0 - #4) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 16:12 -> 28:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 18:12 -> 18:27 = #0 (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: Expansion,File 1, 19:10 -> 19:25 = #0 (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 1, 21:3 -> 21:7 = #0 (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: Expansion,File 1, 23:3 -> 23:7 = #0 (HasCodeBefore = 0, Expanded file = 5) +// CHECK-NEXT: Expansion,File 1, 23:8 -> 23:12 = #0 (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 1, 24:14 -> 26:4 = #11 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 25:12 -> 25:16 = #11 (HasCodeBefore = 0, Expanded file = 6) +// CHECK-NEXT: File 2, 1:1 -> 9:7 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 2:13 -> 4:2 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 4:8 -> 6:2 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 7:11 -> 9:2 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 9:8 -> 11:2 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 4:3 -> 12:9 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 5:15 -> 7:4 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 7:10 -> 9:4 = (#0 - #5) (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 10:13 -> 12:4 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 12:10 -> 14:4 = (#0 - #6) (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 4:3 -> 12:9 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 5:15 -> 7:4 = #9 (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 7:10 -> 9:4 = (#0 - #9) (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 10:13 -> 12:4 = #10 (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 12:10 -> 14:4 = (#0 - #10) (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 4:3 -> 12:9 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 5:15 -> 7:4 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 7:10 -> 9:4 = (#0 - #7) (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 10:13 -> 12:4 = #8 (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 12:10 -> 14:4 = (#0 - #8) (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 4:3 -> 12:9 = #11 (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 5:15 -> 7:4 = #12 (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 7:10 -> 9:4 = (#11 - #12) (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 10:13 -> 12:4 = #13 (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 12:10 -> 14:4 = (#11 - #13) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/ir.c =================================================================== --- cfe/trunk/test/CoverageMapping/ir.c +++ cfe/trunk/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: cfe/trunk/test/CoverageMapping/label.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/label.cpp +++ cfe/trunk/test/CoverageMapping/label.cpp @@ -0,0 +1,96 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name label.cpp %s | 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-NEXT: File 0, 3:13 -> 20:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:14 -> 5:20 = (#0 + #3) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:22 -> 5:25 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:27 -> 15:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:15 -> 12:6 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:9 -> 14:14 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:7 -> 13:13 = (#1 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:3 -> 18:12 = ((#0 + #3) - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:5 -> 19:11 = #4 (HasCodeBefore = 0) + +void test1(int x) { + if(x == 0) + goto a; + goto b; +a: +b: + x = x + 1; +} + +// CHECK-NEXT: test1 +// CHECK-NEXT: File 0, 33:19 -> 40:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:5 -> 35:11 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 36:3 -> 36:9 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 37:1 -> 37:2 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 38:1 -> 39:12 = #3 (HasCodeBefore = 0) + +void test2(int x) { + if(x == 0) + goto a; + else if(x == 1) goto b; +a: +b: + x = x + 1; +} + +// CHECK-NEXT: test2 +// CHECK-NEXT: File 0, 49:19 -> 56:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 51:5 -> 51:11 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 52:8 -> 52:17 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 52:19 -> 52:25 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 53:1 -> 53:2 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 54:1 -> 55:12 = #4 (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-NEXT: main +// CHECK-NEXT: File 0, 66:12 -> 82:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 68:18 -> 68:24 = (#0 + #7) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 68:26 -> 68:29 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 68:31 -> 78:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 69:3 -> 70:13 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 71:7 -> 71:13 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 72:5 -> 72:11 = (#2 - #3) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 73:3 -> 74:10 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 75:3 -> 76:10 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 77:3 -> 77:4 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 77:6 -> 77:10 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 79:3 -> 81:11 = ((#0 + #7) - #1) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/logical.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/logical.cpp +++ cfe/trunk/test/CoverageMapping/logical.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name logical.cpp %s | 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, 3:12 -> 25:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:18 -> 6:20 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 8:7 -> 8:9 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:13 -> 9:15 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:7 -> 11:9 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:13 -> 12:15 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:7 -> 14:9 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:13 -> 15:15 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 17:7 -> 17:9 = #8 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:18 -> 18:24 = (#0 + #9) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:26 -> 18:29 = #9 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 18:31 -> 23:4 = #9 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:17 -> 19:22 = #11 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:24 -> 19:32 = #10 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:18 -> 20:24 = #12 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:17 -> 21:23 = #14 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:25 -> 21:34 = #13 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:19 -> 22:25 = #15 (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/loopmacro.c =================================================================== --- cfe/trunk/test/CoverageMapping/loopmacro.c +++ cfe/trunk/test/CoverageMapping/loopmacro.c @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loopmacro.c %s | 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)< 26:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:6 -> 25:30 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 24:7 -> 24:20 = (#0 + #1) (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 24:21 -> 24:29 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:21 -> 24:29 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:21 -> 24:29 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:31 -> 24:40 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:4 -> 12:23 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 10:5 -> 10:16 = (#0 + #1) (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: File 1, 10:17 -> 10:22 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:17 -> 10:22 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:24 -> 10:32 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:33 -> 10:36 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:46 -> 10:49 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 2, 5:18 -> 5:53 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 8:26 -> 8:66 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 3, 8:38 -> 8:45 = (#0 + #1) (HasCodeBefore = 0, Expanded file = 2) Index: cfe/trunk/test/CoverageMapping/loops.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/loops.cpp +++ cfe/trunk/test/CoverageMapping/loops.cpp @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -std=c++11 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name loops.cpp %s | 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-NEXT: File 0, 3:18 -> 11:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 6:21 -> 10:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:7 -> 9:12 = #2 (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-NEXT: main +// CHECK-NEXT: File 0, 18:12 -> 43:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:18 -> 19:24 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:26 -> 19:29 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 20:6 -> 20:7 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:18 -> 21:23 = (#0 + #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:25 -> 21:28 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:6 -> 22:7 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 24:7 -> 24:13 = (#0 + #3) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:7 -> 25:10 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 26:3 -> 28:4 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:9 -> 30:14 = (#0 + #4) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:16 -> 30:19 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 31:6 -> 33:17 = (#0 + #5) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 36:5 -> 36:10 = (#0 + #6) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 37:6 -> 37:9 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:5 -> 40:15 = (#0 + #7) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/macroception.c =================================================================== --- cfe/trunk/test/CoverageMapping/macroception.c +++ cfe/trunk/test/CoverageMapping/macroception.c @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroception.c %s | FileCheck %s + +#define M2 { +#define M1 M2 +#define M22 } +#define M11 M22 + +int main() M1 + return 0; +} + +// CHECK: main +// CHECK-NEXT: File 0, 3:12 -> 3:13 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0 (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 8:12 -> 8:14 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 9:3 -> 10:2 = #0 (HasCodeBefore = 0) + +void func2() { + int x = 0; +M11 + +// CHECK-NEXT: func2 +// CHECK-NEXT: File 0, 18:14 -> 19:12 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 20:1 -> 20:4 = #0 (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 1, 5:13 -> 5:14 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 2, 6:13 -> 6:16 = #0 (HasCodeBefore = 0, Expanded file = 1) + +void func3() M1 + int x = 0; +M11 + +// CHECK-NEXT: func3 +// CHECK-NEXT: File 0, 3:12 -> 3:13 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0 (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 28:14 -> 28:16 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 2, 29:3 -> 29:12 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 2, 30:1 -> 30:4 = #0 (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 3, 5:13 -> 5:14 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 4, 6:13 -> 6:16 = #0 (HasCodeBefore = 0, Expanded file = 3) + +void func4() M1 M11 + +// CHECK-NEXT: func4 +// CHECK-NEXT: File 0, 3:12 -> 3:13 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0 (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 2, 41:14 -> 41:16 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: Expansion,File 2, 41:17 -> 41:20 = #0 (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 3, 5:13 -> 5:14 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 4, 6:13 -> 6:16 = #0 (HasCodeBefore = 0, Expanded file = 3) Index: cfe/trunk/test/CoverageMapping/macroparams.c =================================================================== --- cfe/trunk/test/CoverageMapping/macroparams.c +++ cfe/trunk/test/CoverageMapping/macroparams.c @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroparams.c %s | 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, 8:22 -> 16:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 9:16 -> 9:25 = #0 (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 0, 9:29 -> 12:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 12:10 -> 15:4 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 13:5 -> 13:13 = (#0 - #1) (HasCodeBefore = 0, Expanded file = 3) +// CHECK-NEXT: File 0, 13:14 -> 13:16 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:17 -> 13:26 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 14:5 -> 14:13 = (#0 - #1) (HasCodeBefore = 0, Expanded file = 4) +// CHECK-NEXT: File 0, 14:14 -> 14:16 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:17 -> 14:24 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 21:12 -> 32:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 24:3 -> 24:12 = #0 (HasCodeBefore = 0, Expanded file = 0) +// CHECK-NEXT: Expansion,File 1, 26:3 -> 26:12 = #0 (HasCodeBefore = 0, Expanded file = 5) +// CHECK-NEXT: File 1, 26:13 -> 26:14 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 26:13 -> 26:14 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 26:13 -> 26:14 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 26:13 -> 26:14 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 27:6 -> 30:12 = (#0 + #3) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 29:5 -> 29:10 = (#0 + #3) (HasCodeBefore = 0, Expanded file = 10) +// CHECK-NEXT: File 2, 3:19 -> 3:23 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 3, 5:21 -> 5:42 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 4, 5:21 -> 5:42 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 8:22 -> 16:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 9:16 -> 9:25 = #0 (HasCodeBefore = 0, Expanded file = 6) +// CHECK-NEXT: File 5, 9:29 -> 12:4 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 12:10 -> 15:4 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 13:5 -> 13:13 = (#0 - #2) (HasCodeBefore = 0, Expanded file = 7) +// CHECK-NEXT: File 5, 13:14 -> 13:16 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 13:17 -> 13:26 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 5, 14:5 -> 14:13 = (#0 - #2) (HasCodeBefore = 0, Expanded file = 8) +// CHECK-NEXT: File 5, 14:14 -> 14:16 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 5, 14:17 -> 14:24 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 6, 3:19 -> 3:23 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 7, 5:21 -> 5:42 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 8, 5:21 -> 5:42 = (#0 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 9, 18:20 -> 18:28 = (#0 + #3) (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 10, 19:18 -> 19:24 = (#0 + #3) (HasCodeBefore = 0, Expanded file = 9) +// CHECK-NEXT: File 10, 19:25 -> 19:26 = (#0 + #3) (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/macroparams2.c =================================================================== --- cfe/trunk/test/CoverageMapping/macroparams2.c +++ cfe/trunk/test/CoverageMapping/macroparams2.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroparams2.c %s | 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, 12:12 -> 19:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 15:7 -> 15:12 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 15:13 -> 15:21 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:23 -> 15:31 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:34 -> 17:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 10:29 -> 10:51 = #0 (HasCodeBefore = 0 Index: cfe/trunk/test/CoverageMapping/macros.c =================================================================== --- cfe/trunk/test/CoverageMapping/macros.c +++ cfe/trunk/test/CoverageMapping/macros.c @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macros.c %s | 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-NEXT: File 0, 8:13 -> 12:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 10:3 -> 10:8 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 11:3 -> 11:8 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 4:15 -> 4:21 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 4:23 -> 4:28 = 0 (HasCodeBefore = 0) + +void func2() { + int i = 0; + MACRO_1; + i = 2; +} + +// CHECK-NEXT: func2 +// CHECK-NEXT: File 0, 21:14 -> 25:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 0, 23:3 -> 23:10 = #0 (HasCodeBefore = 0, Expanded file = 1) +// CHECK-NEXT: File 0, 24:3 -> 24:8 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 1, 6:17 -> 6:23 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Expansion,File 1, 6:25 -> 6:32 = 0 (HasCodeBefore = 0, Expanded file = 2) +// CHECK-NEXT: File 2, 5:17 -> 5:22 = 0 (HasCodeBefore = 0) + +int main() { + func(); + func2(); + return 0; +} + +void bar() { +} Index: cfe/trunk/test/CoverageMapping/nestedclass.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/nestedclass.cpp +++ cfe/trunk/test/CoverageMapping/nestedclass.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name nestedclass.cpp %s | 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: emitTest2 +// CHECK-NEXT: File 0, 8:22 -> 10:6 = #0 (HasCodeBefore = 0) + +// CHECK-NEXT: emitTest +// CHECK-NEXT: File 0, 4:19 -> 6:4 = #0 (HasCodeBefore = 0) + +// CHECK-NEXT: emitTest3 +// CHECK-NEXT: File 0, 12:31 -> 14:8 = 0 (HasCodeBefore = 0) + +int main() { + Test t; + Test::Test2 t2; + t.emitTest(); + t2.emitTest2(); + return 0; +} Index: cfe/trunk/test/CoverageMapping/preprocessor.c =================================================================== --- cfe/trunk/test/CoverageMapping/preprocessor.c +++ cfe/trunk/test/CoverageMapping/preprocessor.c @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name preprocessor.c %s | FileCheck %s + +void func() { + int i = 0; +#ifdef MACRO + int x = i; +#endif +} + +// CHECK: func +// CHECK: File 0, 3:13 -> 8:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 5:2 -> 7: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-NEXT: File 0, 20:12 -> 39:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 22:2 -> 26:2 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 29:14 -> 31:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: Skipped,File 0, 32:2 -> 37:2 = 0 (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/return.c =================================================================== --- cfe/trunk/test/CoverageMapping/return.c +++ cfe/trunk/test/CoverageMapping/return.c @@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name return.c %s | FileCheck %s + +void func() { + return; + int i = 0; +} + +// CHECK: func +// CHECK: File 0, 3:13 -> 6:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:3 -> 5: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-NEXT: func2 +// CHECK-NEXT: File 0, 12:14 -> 25:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:18 -> 13:24 = ((#0 + #1) - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:26 -> 13:29 = (#1 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:31 -> 24:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:15 -> 16:6 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:12 -> 21:11 = (#1 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 19:16 -> 21:6 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:12 -> 23:6 = ((#1 - #2) - #3) (HasCodeBefore = 0) + +void func3(int x) { + if(x > 5) { + while(x >= 9) { + return; + --x; + } + int i = 0; + } + int j = 0; +} + +// CHECK-NEXT: func3 +// CHECK-NEXT: File 0, 37:19 -> 46:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 38:13 -> 44:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:11 -> 39:17 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:19 -> 42:6 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 41:7 -> 41:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:5 -> 43:14 = (#1 - #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 45:3 -> 45:12 = (#0 - #2) (HasCodeBefore = 0) + +int main() { + func(); + func2(); + for(int i = 0; i < 10; ++i) + func3(i); + return 0; +} Index: cfe/trunk/test/CoverageMapping/switch.c =================================================================== --- cfe/trunk/test/CoverageMapping/switch.c +++ cfe/trunk/test/CoverageMapping/switch.c @@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.c %s | FileCheck %s + +void foo(int i) { + switch(i) { + case 1: + return; + case 2: + break; + } + int x = 0; +} + +// CHECK: foo +// CHECK-NEXT: File 0, 3:17 -> 11:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 5:3 -> 6:11 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:3 -> 8:10 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 9:3 -> 10:12 = #1 (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-NEXT: main +// CHECK-NEXT: File 0, 19:12 -> 60:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 22:3 -> 24:10 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 25:3 -> 27:10 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 28:3 -> 29:10 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:3 -> 31:14 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:3 -> 34:10 = #6 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:3 -> 36:10 = #7 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 37:3 -> 38:10 = (#7 + #8) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:3 -> 42:14 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 43:3 -> 43:10 = #10 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 44:3 -> 45:11 = (#10 + #11) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 46:3 -> 46:10 = ((#10 + #11) + #12) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 47:3 -> 48:11 = (((#10 + #11) + #12) + #13) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 49:3 -> 50:14 = #9 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 51:3 -> 52:13 = #15 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 53:5 -> 53:10 = 0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 54:3 -> 55:10 = #16 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 56:3 -> 59:11 = #14 (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/templates.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/templates.cpp +++ cfe/trunk/test/CoverageMapping/templates.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name templates.cpp %s | 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-NEXT: File 0, 9:15 -> 15:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:5 -> 11:13 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:5 -> 13:13 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:3 -> 14:12 = 0 (HasCodeBefore = 0) + +// CHECK-NEXT: func +// CHECK-NEXT: File 0, 9:15 -> 15:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 11:5 -> 11:13 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 13:5 -> 13:13 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:3 -> 14:12 = 0 (HasCodeBefore = 0) + +int main() { + func(0); + func(true); + return 0; +} Index: cfe/trunk/test/CoverageMapping/test.c =================================================================== --- cfe/trunk/test/CoverageMapping/test.c +++ cfe/trunk/test/CoverageMapping/test.c @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name test.c %s | FileCheck %s + +void bar(); +static void static_func(); + +int main() { + for(int i = 0; i < 10; ++i) { + bar(); + } + static_func(); + return 0; +} + +// CHECK: main +// CHECK-NEXT: File 0, 6:12 -> 12:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:18 -> 7:24 = (#0 + #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:26 -> 7:29 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 7:31 -> 9:4 = #1 (HasCodeBefore = 0) + +void foo() { + if(1) { + int i = 0; + } +} + +// CHECK-NEXT: foo +// CHECK-NEXT: File 0, 20:12 -> 24:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 21:9 -> 23:4 = #1 (HasCodeBefore = 0) + +void bar() { +} + +// CHECK-NEXT: bar +// CHECK-NEXT: File 0, 30:12 -> 31:2 = #0 (HasCodeBefore = 0) + +void static_func() { } + +// CHECK-NEXT: static_func +// CHECK: File 0, 36:20 -> 36:23 = #0 (HasCodeBefore = 0) + +static void func() { } + +// CHECK-NEXT: func +// CHECK: File 0, 41:20 -> 41:23 = 0 (HasCodeBefore = 0) Index: cfe/trunk/test/CoverageMapping/trycatch.cpp =================================================================== --- cfe/trunk/test/CoverageMapping/trycatch.cpp +++ cfe/trunk/test/CoverageMapping/trycatch.cpp @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name trycatch.cpp %s | 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-NEXT: File 0, 12:18 -> 17:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 14:5 -> 14:16 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 15:8 -> 15:17 = (#0 - #1) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 16:5 -> 16:25 = #2 (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-NEXT: main +// CHECK-NEXT: File 0, 25:12 -> 40:2 = #0 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:18 -> 27:23 = (#0 + #2) (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:25 -> 27:28 = #2 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 27:30 -> 38:4 = #1 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 30:29 -> 32:12 = #3 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 32:38 -> 35:10 = #4 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 35:29 -> 37:6 = #5 (HasCodeBefore = 0) +// CHECK-NEXT: File 0, 39:3 -> 39:11 = ((#0 + #2) - #1) (HasCodeBefore = 0)