summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2014-08-19 17:32:30 +0000
committerAlex Lorenz <arphaman@gmail.com>2014-08-19 17:32:30 +0000
commit34ac9b5e25d3a00197ad30238d4e213f7811ebfe (patch)
tree5c632b3b63a03fa4148853693eaa68bbedc608b8
parentdd6394d83344a3f61ddcf9fa0804308146d6b888 (diff)
downloadbcm5719-llvm-34ac9b5e25d3a00197ad30238d4e213f7811ebfe.tar.gz
bcm5719-llvm-34ac9b5e25d3a00197ad30238d4e213f7811ebfe.zip
Add tests for coverage mapping generation.
This patch adds the tests for the coverage mapping generation. Most of the tests check the mapping regions produced by the generator, and one checks the llvm IR. Differential Revision: http://reviews.llvm.org/D4847 llvm-svn: 215995
-rw-r--r--clang/test/CoverageMapping/Inputs/code.h11
-rw-r--r--clang/test/CoverageMapping/Inputs/header1.h31
-rw-r--r--clang/test/CoverageMapping/break.c31
-rw-r--r--clang/test/CoverageMapping/builtinmacro.c14
-rw-r--r--clang/test/CoverageMapping/casts.c11
-rw-r--r--clang/test/CoverageMapping/classtemplate.cpp34
-rw-r--r--clang/test/CoverageMapping/continue.c24
-rw-r--r--clang/test/CoverageMapping/header.cpp27
-rw-r--r--clang/test/CoverageMapping/if.c24
-rw-r--r--clang/test/CoverageMapping/includehell.cpp12
-rw-r--r--clang/test/CoverageMapping/ir.c12
-rw-r--r--clang/test/CoverageMapping/label.cpp63
-rw-r--r--clang/test/CoverageMapping/logical.cpp13
-rw-r--r--clang/test/CoverageMapping/loopmacro.c40
-rw-r--r--clang/test/CoverageMapping/loops.cpp37
-rw-r--r--clang/test/CoverageMapping/macroception.c37
-rw-r--r--clang/test/CoverageMapping/macroparams.c11
-rw-r--r--clang/test/CoverageMapping/macroparams2.c20
-rw-r--r--clang/test/CoverageMapping/macros.c26
-rw-r--r--clang/test/CoverageMapping/nestedclass.cpp28
-rw-r--r--clang/test/CoverageMapping/preprocessor.c37
-rw-r--r--clang/test/CoverageMapping/return.c35
-rw-r--r--clang/test/CoverageMapping/switch.c48
-rw-r--r--clang/test/CoverageMapping/templates.cpp21
-rw-r--r--clang/test/CoverageMapping/test.c31
-rw-r--r--clang/test/CoverageMapping/trycatch.cpp34
26 files changed, 712 insertions, 0 deletions
diff --git a/clang/test/CoverageMapping/Inputs/code.h b/clang/test/CoverageMapping/Inputs/code.h
new file mode 100644
index 00000000000..cd3cfb5d3fe
--- /dev/null
+++ b/clang/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;
+}
diff --git a/clang/test/CoverageMapping/Inputs/header1.h b/clang/test/CoverageMapping/Inputs/header1.h
new file mode 100644
index 00000000000..d01e813b40b
--- /dev/null
+++ b/clang/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
diff --git a/clang/test/CoverageMapping/break.c b/clang/test/CoverageMapping/break.c
new file mode 100644
index 00000000000..f5a0af5097b
--- /dev/null
+++ b/clang/test/CoverageMapping/break.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name break.c %s | FileCheck %s
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+28]]:2 = #0 (HasCodeBefore = 0)
+ int cnt = 0; // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:18 = #0 (HasCodeBefore = 0)
+ while(cnt < 100) { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+3]]:4 = #1 (HasCodeBefore = 0)
+ break;
+ ++cnt; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = 0 (HasCodeBefore = 0)
+ } // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:18 = #0 (HasCodeBefore = 0)
+ while(cnt < 100) { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+6]]:4 = #2 (HasCodeBefore = 0)
+ {
+ break;
+ ++cnt; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE+2]]:10 = 0 (HasCodeBefore = 0)
+ }
+ ++cnt;
+ } // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:18 = ((#0 + #3) - #4) (HasCodeBefore = 0)
+ while(cnt < 100) { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+6]]:4 = #3 (HasCodeBefore = 0)
+ if(cnt == 0) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+3]]:6 = #4 (HasCodeBefore = 0)
+ break;
+ ++cnt; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = 0 (HasCodeBefore = 0)
+ }
+ ++cnt; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = (#3 - #4) (HasCodeBefore = 0)
+ } // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:18 = (#0 + #6) (HasCodeBefore = 0)
+ while(cnt < 100) { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+7]]:4 = #5 (HasCodeBefore = 0)
+ if(cnt == 0) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+5]]:10 = #6 (HasCodeBefore = 0)
+ ++cnt;
+ } else { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+2]]:6 = (#5 - #6) (HasCodeBefore = 0)
+ break;
+ }
+ ++cnt;
+ }
+}
diff --git a/clang/test/CoverageMapping/builtinmacro.c b/clang/test/CoverageMapping/builtinmacro.c
new file mode 100644
index 00000000000..a023abc62a4
--- /dev/null
+++ b/clang/test/CoverageMapping/builtinmacro.c
@@ -0,0 +1,14 @@
+// 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.
+
+// CHECK: filename
+const char *filename (const char *name) { // CHECK-NEXT: File 0, [[@LINE]]:41 -> [[@LINE+3]]:2 = #0 (HasCodeBefore = 0)
+ static const char this_file[] = __FILE__;
+ return this_file;
+}
+
+int main() { // CHECK-NEXT: main
+ filename(__FILE__ "test.c");
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/casts.c b/clang/test/CoverageMapping/casts.c
new file mode 100644
index 00000000000..94c13dc13cb
--- /dev/null
+++ b/clang/test/CoverageMapping/casts.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name casts.c %s | FileCheck %s
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:41 -> [[@LINE+1]]:54 = #1 (HasCodeBefore = 0)
+ int window_size = (sizeof(int) <= 2 ? (unsigned)512 : 1024); // CHECK-NEXT: File 0, [[@LINE]]:57 -> [[@LINE]]:61 = (#0 - #1) (HasCodeBefore = 0)
+ return 0;
+}
+
+
+
+
diff --git a/clang/test/CoverageMapping/classtemplate.cpp b/clang/test/CoverageMapping/classtemplate.cpp
new file mode 100644
index 00000000000..95b84c370d9
--- /dev/null
+++ b/clang/test/CoverageMapping/classtemplate.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name classtemplate.cpp %s > %tmapping
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-CONSTRUCTOR
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-GETTER
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-SETTER
+
+template<class TT>
+class Test {
+public:
+ enum BaseType {
+ A, C, G, T, Invalid
+ };
+ const static int BaseCount = 4;
+ double bases[BaseCount];
+
+ // CHECK-CONSTRUCTOR: Test
+ Test() { } // CHECK-CONSTRUCTOR: File 0, [[@LINE]]:10 -> [[@LINE]]:13 = #0 (HasCodeBefore = 0)
+ // CHECK-GETTER: get
+ double get(TT position) const { // CHECK-GETTER: File 0, [[@LINE]]:33 -> [[@LINE+2]]:4 = 0 (HasCodeBefore = 0)
+ return bases[position];
+ }
+ // CHECK-SETTER: set
+ void set(TT position, double value) { // CHECK-SETTER: File 0, [[@LINE]]:39 -> [[@LINE+2]]:4 = #0 (HasCodeBefore = 0)
+ bases[position] = value;
+ }
+};
+
+int main() {
+ Test<unsigned> t;
+ t.set(Test<unsigned>::A, 5.5);
+ t.set(Test<unsigned>::T, 5.6);
+ t.set(Test<unsigned>::G, 5.7);
+ t.set(Test<unsigned>::C, 5.8);
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/continue.c b/clang/test/CoverageMapping/continue.c
new file mode 100644
index 00000000000..b56b164d4a3
--- /dev/null
+++ b/clang/test/CoverageMapping/continue.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name continue.c %s | FileCheck %s
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+21]]:2 = #0 (HasCodeBefore = 0)
+ int j = 0; // CHECK-NEXT: File 0, [[@LINE+2]]:18 -> [[@LINE+2]]:24 = (#0 + #1) (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:29 = #1 (HasCodeBefore = 0)
+ for(int i = 0; i < 20; ++i) { // CHECK-NEXT: File 0, [[@LINE]]:31 -> [[@LINE+17]]:4 = #1 (HasCodeBefore = 0)
+ if(i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE+13]]:6 = #2 (HasCodeBefore = 0)
+ if(i < 5) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+3]]:8 = #3 (HasCodeBefore = 0)
+ continue;
+ j = 1; // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = 0 (HasCodeBefore = 0)
+ } else { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+7]]:13 = (#2 - #3) (HasCodeBefore = 0)
+ j = 2;
+ }
+ j = 3;
+ if(i < 7) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+3]]:8 = #4 (HasCodeBefore = 0)
+ continue;
+ j = 4; // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = 0 (HasCodeBefore = 0)
+ } else j = 5; // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+1]]:12 = ((#2 - #3) - #4) (HasCodeBefore = 0)
+ j = 6;
+ } else // CHECK-NEXT: File 0, [[@LINE+1]]:7 -> [[@LINE+1]]:12 = (#1 - #2) (HasCodeBefore = 0)
+ j = 7;
+ j = 8; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = ((#1 - #3) - #4) (HasCodeBefore = 0)
+ }
+}
diff --git a/clang/test/CoverageMapping/header.cpp b/clang/test/CoverageMapping/header.cpp
new file mode 100644
index 00000000000..9e4ab54ebde
--- /dev/null
+++ b/clang/test/CoverageMapping/header.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name tu1.cpp %s > %tmapping
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-FUNC
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-STATIC-FUNC
+// cat %tmapping | FileCheck %s --check-prefix=CHECK-STATIC-FUNC2
+
+#include "Inputs/header1.h"
+
+int main() {
+ func(1);
+ static_func(2);
+}
+
+// CHECK-FUNC: func
+// CHECK-FUNC: File 0, 4:25 -> 11:2 = #0 (HasCodeBefore = 0)
+// CHECK-FUNC: File 0, 6:15 -> 8:4 = #1 (HasCodeBefore = 0)
+// CHECK-FUNC: File 0, 8:10 -> 10:4 = (#0 - #1) (HasCodeBefore = 0)
+// CHECK-FUNC: Expansion,File 1, 3:10 -> 3:28 = #0 (HasCodeBefore = 0, Expanded file = 0)
+
+// CHECK-STATIC-FUNC: static_func
+// CHECK-STATIC-FUNC: File 0, 12:32 -> 20:2 = #0 (HasCodeBefore = 0)
+// CHECK-STATIC-FUNC: File 0, 14:15 -> 16:4 = #1 (HasCodeBefore = 0)
+// CHECK-STATIC-FUNC File 0, 16:10 -> 18:4 = (#0 - #1) (HasCodeBefore = 0)
+// CHECK-STATIC-FUNC: Expansion,File 1, 3:10 -> 3:28 = #0 (HasCodeBefore = 0, Expanded file = 0)
+
+// CHECK-STATIC-FUNC2: static_func2
+// CHECK-STATIC-FUNC2: File 0, 21:33 -> 29:2 = 0 (HasCodeBefore = 0)
+// CHECK-STATIC-FUNC2: Expansion,File 1, 3:10 -> 3:28 = 0 (HasCodeBefore = 0, Expanded file = 0)
diff --git a/clang/test/CoverageMapping/if.c b/clang/test/CoverageMapping/if.c
new file mode 100644
index 00000000000..4767b4039b3
--- /dev/null
+++ b/clang/test/CoverageMapping/if.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name if.c %s | FileCheck %s
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+21]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ if(i == 0) i = 1; // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE]]:19 = #1 (HasCodeBefore = 0)
+ if(i == 1)
+ i = 2; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = #2 (HasCodeBefore = 0)
+ if(i == 0) { i = 1; // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #3 (HasCodeBefore = 0)
+ i = 2;
+ }
+ if(i != 0) { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #4 (HasCodeBefore = 0)
+ i = 1;
+ } else { // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+2]]:4 = (#0 - #4) (HasCodeBefore = 0)
+ i = 3;
+ }
+
+ i = i == 0?
+ i + 1 : // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = #5 (HasCodeBefore = 0)
+ i + 2; // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = (#0 - #5) (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:14 -> [[@LINE+1]]:20 = #6 (HasCodeBefore = 0)
+ i = i == 0?i + 12:i + 10; // CHECK-NEXT: File 0, [[@LINE]]:21 -> [[@LINE]]:27 = (#0 - #6) (HasCodeBefore = 0)
+
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/includehell.cpp b/clang/test/CoverageMapping/includehell.cpp
new file mode 100644
index 00000000000..4f4028d4543
--- /dev/null
+++ b/clang/test/CoverageMapping/includehell.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name includehell.cpp %s | FileCheck %s
+
+// CHECK: File 0, 1:1 -> 9:7 = #0 (HasCodeBefore = 0)
+// CHECK-NEXT: File 0, 2:13 -> 4:2 = #1 (HasCodeBefore = 0)
+// CHECK-NEXT: File 0, 4:8 -> 6:2 = (#0 - #1) (HasCodeBefore = 0)
+// CHECK-NEXT: File 0, 7:11 -> 9:2 = #2 (HasCodeBefore = 0)
+// CHECK-NEXT: File 0, 9:8 -> 11:2 = (#0 - #2) (HasCodeBefore = 0)
+int main() { // CHECK-NEXT: File 1, [[@LINE]]:12 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ int x = 0;
+ #include "Inputs/code.h" // CHECK-NEXT: Expansion,File 1, [[@LINE]]:12 -> [[@LINE]]:27 = #0 (HasCodeBefore = 0, Expanded file = 0)
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/ir.c b/clang/test/CoverageMapping/ir.c
new file mode 100644
index 00000000000..eb83959f1d2
--- /dev/null
+++ b/clang/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 }]
diff --git a/clang/test/CoverageMapping/label.cpp b/clang/test/CoverageMapping/label.cpp
new file mode 100644
index 00000000000..d93626041bc
--- /dev/null
+++ b/clang/test/CoverageMapping/label.cpp
@@ -0,0 +1,63 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name label.cpp %s | FileCheck %s
+
+ // CHECK: func
+void func() { // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE+18]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0; // CHECK-NEXT: File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = (#0 + #3) (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:22 -> [[@LINE+1]]:25 = #3 (HasCodeBefore = 0)
+ for(i = 0; i < 10; ++i) { // CHECK-NEXT: File 0, [[@LINE]]:27 -> [[@LINE+10]]:4 = #1 (HasCodeBefore = 0)
+ if(i < 5) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+6]]:6 = #2 (HasCodeBefore = 0)
+ {
+ x: // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE+6]]:14 = #3 (HasCodeBefore = 0)
+ int j = 1;
+ }
+ int m = 2;
+ } else
+ goto x; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#1 - #2) (HasCodeBefore = 0)
+ int k = 3;
+ }
+ static int j = 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:12 = ((#0 + #3) - #1) (HasCodeBefore = 0)
+ ++j;
+ if(j == 1)
+ goto x; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #4 (HasCodeBefore = 0)
+}
+
+ // CHECK-NEXT: test1
+void test1(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+7]]:2 = #0 (HasCodeBefore = 0)
+ if(x == 0)
+ goto a; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1 (HasCodeBefore = 0)
+ goto b; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:9 = (#0 - #1) (HasCodeBefore = 0)
+a: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE]]:2 = #2 (HasCodeBefore = 0)
+b: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+1]]:12 = #3 (HasCodeBefore = 0)
+ x = x + 1;
+}
+
+ // CHECK-NEXT: test2
+void test2(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+8]]:2 = #0 (HasCodeBefore = 0)
+ if(x == 0)
+ goto a; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = #1 (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> [[@LINE+1]]:17 = (#0 - #1) (HasCodeBefore = 0)
+ else if(x == 1) goto b; // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE]]:25 = #2 (HasCodeBefore = 0)
+a: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE]]:2 = #3 (HasCodeBefore = 0)
+b: // CHECK-NEXT: File 0, [[@LINE]]:1 -> [[@LINE+1]]:12 = #4 (HasCodeBefore = 0)
+ x = x + 1;
+}
+
+ // CHECK-NEXT: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+17]]:2 = #0 (HasCodeBefore = 0)
+ int j = 0;
+ for(int i = 0; i < 10; ++i) { // CHECK: File 0, [[@LINE]]:31 -> [[@LINE+11]]:4 = #1 (HasCodeBefore = 0)
+ a: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:13 = #2 (HasCodeBefore = 0)
+ if(i < 3)
+ goto e; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = #3 (HasCodeBefore = 0)
+ goto c; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:11 = (#2 - #3) (HasCodeBefore = 0)
+ b: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 (HasCodeBefore = 0)
+ j = 2;
+ c: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #5 (HasCodeBefore = 0)
+ j = 1;
+ // CHECK-NEXT: File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:4 = #6 (HasCodeBefore = 0)
+ e: f: ; // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:10 = #7 (HasCodeBefore = 0)
+ }
+ func(); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#0 + #7) - #1) (HasCodeBefore = 0)
+ test1(0);
+ test2(2);
+}
diff --git a/clang/test/CoverageMapping/logical.cpp b/clang/test/CoverageMapping/logical.cpp
new file mode 100644
index 00000000000..0971c756b04
--- /dev/null
+++ b/clang/test/CoverageMapping/logical.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name logical.cpp %s | FileCheck %s
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+10]]:2 = #0 (HasCodeBefore = 0)
+ bool bt = true;
+ bool bf = false;
+ bool a = bt && bf; // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE]]:20 = #1 (HasCodeBefore = 0)
+ a = bt &&
+ bf; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:9 = #2 (HasCodeBefore = 0)
+ a = bf || bt; // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE]]:15 = #3 (HasCodeBefore = 0)
+ a = bf ||
+ bt; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:9 = #4 (HasCodeBefore = 0)
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/loopmacro.c b/clang/test/CoverageMapping/loopmacro.c
new file mode 100644
index 00000000000..cd93878fb7f
--- /dev/null
+++ b/clang/test/CoverageMapping/loopmacro.c
@@ -0,0 +1,40 @@
+// 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)<<H_SHIFT) ^ (c)) & HASH_MASK)
+#define INSERT_STRING(s, match_head) \
+ (UPDATE_HASH(ins_h, window[(s) + MIN_MATCH-1]), \
+ prev[(s) & WMASK] = match_head = head[ins_h], \
+ head[ins_h] = (s))
+
+int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+12]]:2 = #0 (HasCodeBefore = 0)
+ int strstart = 0;
+ int hash_head = 2;
+ int prev_length = 5;
+ int ins_h = 1;
+ int prev[32] = { 0 };
+ int head[32] = { 0 };
+ int window[1024] = { 0 };
+ do { // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE+3]]:30 = (#0 + #1) (HasCodeBefore = 0)
+ strstart++;
+ INSERT_STRING(strstart, hash_head); // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:20 = (#0 + #1) (HasCodeBefore = 0, Expanded file = 1)
+ } while (--prev_length != 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: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)
diff --git a/clang/test/CoverageMapping/loops.cpp b/clang/test/CoverageMapping/loops.cpp
new file mode 100644
index 00000000000..81fad910d9e
--- /dev/null
+++ b/clang/test/CoverageMapping/loops.cpp
@@ -0,0 +1,37 @@
+// 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
+
+ // CHECK: rangedFor
+void rangedFor() { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+6]]:2 = #0 (HasCodeBefore = 0)
+ int arr[] = { 1, 2, 3, 4, 5 };
+ int sum = 0;
+ for(auto i : arr) { // CHECK-NEXT: File 0, [[@LINE]]:21 -> [[@LINE+2]]:4 = #1 (HasCodeBefore = 0)
+ sum += i;
+ }
+}
+
+ // CHECK-NEXT: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+24]]:2 = #0 (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:24 = (#0 + #1) (HasCodeBefore = 0)
+ for(int i = 0; i < 10; ++i) // CHECK-NEXT: File 0, [[@LINE]]:26 -> [[@LINE]]:29 = #1 (HasCodeBefore = 0)
+ ; // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:7 = #1 (HasCodeBefore = 0)
+ for(int i = 0;
+ i < 10; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = (#0 + #2) (HasCodeBefore = 0)
+ ++i) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:10 = #2 (HasCodeBefore = 0)
+ { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:4 = #2 (HasCodeBefore = 0)
+ int x = 0;
+ }
+ int j = 0; // CHECK-NEXT: File 0, [[@LINE+1]]:9 -> [[@LINE+1]]:14 = (#0 + #3) (HasCodeBefore = 0)
+ while(j < 5) ++j; // CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE]]:19 = #3 (HasCodeBefore = 0)
+ do { // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE+2]]:17 = (#0 + #4) (HasCodeBefore = 0)
+ ++j;
+ } while(j < 10);
+ j = 0;
+ while
+ (j < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = (#0 + #5) (HasCodeBefore = 0)
+ ++j; // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE]]:9 = #5 (HasCodeBefore = 0)
+ do
+ ++j; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+1]]:15 = (#0 + #6) (HasCodeBefore = 0)
+ while(j < 10);
+ rangedFor();
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/macroception.c b/clang/test/CoverageMapping/macroception.c
new file mode 100644
index 00000000000..7db02be5a68
--- /dev/null
+++ b/clang/test/CoverageMapping/macroception.c
@@ -0,0 +1,37 @@
+// 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
+
+ // 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)
+int main() M1 // CHECK-NEXT: Expansion,File 2, [[@LINE]]:12 -> [[@LINE]]:14 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ return 0; // CHECK-NEXT: File 2, [[@LINE]]:3 -> [[@LINE+1]]:2 = #0 (HasCodeBefore = 0)
+}
+
+ // CHECK-NEXT: func2
+void func2() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+1]]:12 = #0 (HasCodeBefore = 0)
+ int x = 0;
+M11 // CHECK-NEXT: Expansion,File 0, [[@LINE]]:1 -> [[@LINE]]: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)
+
+ // 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)
+void func3() M1 // CHECK-NEXT: Expansion,File 2, [[@LINE]]:14 -> [[@LINE]]:16 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ int x = 0; // CHECK-NEXT: File 2, [[@LINE]]:3 -> [[@LINE]]:12 = #0 (HasCodeBefore = 0)
+M11 // CHECK-NEXT: Expansion,File 2, [[@LINE]]:1 -> [[@LINE]]: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)
+
+ // 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, [[@LINE+1]]:14 -> [[@LINE+1]]:16 = #0 (HasCodeBefore = 0, Expanded file = 1)
+void func4() M1 M11 // CHECK-NEXT: Expansion,File 2, [[@LINE]]:17 -> [[@LINE]]: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)
diff --git a/clang/test/CoverageMapping/macroparams.c b/clang/test/CoverageMapping/macroparams.c
new file mode 100644
index 00000000000..b28aca3ed7a
--- /dev/null
+++ b/clang/test/CoverageMapping/macroparams.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macroparams.c %s | FileCheck %s
+
+#define MACRO2(X2) (X2 + 2) // CHECK: File 0, [[@LINE]]:20 -> [[@LINE]]:28 = #0 (HasCodeBefore = 0)
+#define MACRO(X) MACRO2(x) // CHECK-NEXT: Expansion,File 1, [[@LINE]]:18 -> [[@LINE]]:24 = #0 (HasCodeBefore = 0, Expanded file = 0)
+ // CHECK-NEXT: File 1, [[@LINE-1]]:25 -> [[@LINE-1]]:26 = #0 (HasCodeBefore = 0)
+
+int main() { // CHECK-NEXT: File 2, [[@LINE]]:12 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ int x = 0;
+ MACRO(x); // CHECK-NEXT: Expansion,File 2, [[@LINE]]:3 -> [[@LINE]]:8 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/macroparams2.c b/clang/test/CoverageMapping/macroparams2.c
new file mode 100644
index 00000000000..0445370b0e1
--- /dev/null
+++ b/clang/test/CoverageMapping/macroparams2.c
@@ -0,0 +1,20 @@
+// 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() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+7]]:2 = #0 (HasCodeBefore = 0)
+ struct S arr[32] = { 0 }; // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:7 -> [[@LINE+2]]:12 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ int n = 0; // CHECK-NEXT: File 0, [[@LINE+1]]:13 -> [[@LINE+1]]:21 = #0 (HasCodeBefore = 0)
+ if (MACRO(arr[n].j, arr[n].i)) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE]]:31 = #0 (HasCodeBefore = 0)
+ n = 1; // CHECK-NEXT: File 0, [[@LINE-1]]:34 -> [[@LINE+1]]:4 = #1 (HasCodeBefore = 0)
+ }
+ return n;
+} // CHECK-NEXT: File 1, [[@LINE-9]]:29 -> [[@LINE-9]]:51 = #0 (HasCodeBefore = 0
+
diff --git a/clang/test/CoverageMapping/macros.c b/clang/test/CoverageMapping/macros.c
new file mode 100644
index 00000000000..d3a0e6aab47
--- /dev/null
+++ b/clang/test/CoverageMapping/macros.c
@@ -0,0 +1,26 @@
+// 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
+
+ // CHECK: func
+void func() { // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ MACRO; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:8 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ i = 2; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]: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)
+
+ // CHECK-NEXT: func2
+void func2() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ MACRO_1; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:10 = #0 (HasCodeBefore = 0, Expanded file = 1)
+ i = 2; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]: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)
+
diff --git a/clang/test/CoverageMapping/nestedclass.cpp b/clang/test/CoverageMapping/nestedclass.cpp
new file mode 100644
index 00000000000..6462eca7cf8
--- /dev/null
+++ b/clang/test/CoverageMapping/nestedclass.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name nestedclass.cpp %s > %tmapping
+// RUN: cat %tmapping | FileCheck %s --check-prefix=CHECK-OUTER
+// RUN: cat %tmapping | FileCheck %s --check-prefix=CHECK-INNER
+// RUN: cat %tmapping | FileCheck %s --check-prefix=CHECK-INNERMOST
+
+struct Test { // CHECK-OUTER: emitTest
+ void emitTest() { // CHECK-OUTER: File 0, [[@LINE]]:19 -> [[@LINE+2]]:4 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ }
+ struct Test2 { // CHECK-INNER: emitTest2
+ void emitTest2() { // CHECK-INNER: File 0, [[@LINE]]:22 -> [[@LINE+2]]:6 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ }
+ struct Test3 { // CHECK-INNERMOST: emitTest3
+ static void emitTest3() { // CHECK-INNERMOST: File 0, [[@LINE]]:31 -> [[@LINE+2]]:8 = 0 (HasCodeBefore = 0)
+ int i = 0;
+ }
+ };
+ };
+};
+
+int main() {
+ Test t;
+ Test::Test2 t2;
+ t.emitTest();
+ t2.emitTest2();
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/preprocessor.c b/clang/test/CoverageMapping/preprocessor.c
new file mode 100644
index 00000000000..a6edeb7c824
--- /dev/null
+++ b/clang/test/CoverageMapping/preprocessor.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name preprocessor.c %s | FileCheck %s
+
+ // CHECK: func
+void func() { // CHECK: File 0, [[@LINE]]:13 -> [[@LINE+5]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+#ifdef MACRO // CHECK-NEXT: Skipped,File 0, [[@LINE]]:2 -> [[@LINE+2]]:2 = 0 (HasCodeBefore = 0)
+ int x = i;
+#endif
+}
+
+#if 0
+ int g = 0;
+
+ void bar() { }
+#endif
+
+ // CHECK: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+19]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+#if 0 // CHECK-NEXT: Skipped,File 0, [[@LINE]]:2 -> [[@LINE+4]]:2 = 0 (HasCodeBefore = 0)
+ if(i == 0) {
+ i = 1;
+ }
+#endif
+
+#if 1
+ if(i == 0) { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #1 (HasCodeBefore = 0)
+ i = 1;
+ }
+#else // CHECK-NEXT: Skipped,File 0, [[@LINE]]:2 -> [[@LINE+5]]:2 = 0 (HasCodeBefore = 0)
+ if(i == 1) {
+ i = 0;
+ }
+}
+#endif
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/return.c b/clang/test/CoverageMapping/return.c
new file mode 100644
index 00000000000..9c68759b2fc
--- /dev/null
+++ b/clang/test/CoverageMapping/return.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name return.c %s | FileCheck %s
+
+ // CHECK: func
+void func() { // CHECK: File 0, [[@LINE]]:13 -> [[@LINE+3]]:2 = #0 (HasCodeBefore = 0)
+ return;
+ int i = 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:12 = 0 (HasCodeBefore = 0)
+}
+
+ // CHECK-NEXT: func2
+void func2() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+13]]:2 = #0 (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+2]]:18 -> [[@LINE+2]]:24 = ((#0 + #1) - #2) (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:29 = (#1 - #2) (HasCodeBefore = 0)
+ for(int i = 0; i < 10; ++i) { // CHECK-NEXT: File 0, [[@LINE]]:31 -> [[@LINE+9]]:4 = #1 (HasCodeBefore = 0)
+ if(i > 2) { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+2]]:6 = #2 (HasCodeBefore = 0)
+ return;
+ } // CHECK-NEXT: File 0, [[@LINE+1]]:5 -> [[@LINE+3]]:11 = (#1 - #2) (HasCodeBefore = 0)
+ if(i == 3) { // CHECK-NEXT: File 0, [[@LINE]]:16 -> [[@LINE+2]]:6 = #3 (HasCodeBefore = 0)
+ int j = 1;
+ } else { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+2]]:6 = ((#1 - #2) - #3) (HasCodeBefore = 0)
+ int j = 2;
+ }
+ }
+}
+
+ // CHECK-NEXT: func3
+void func3(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+9]]:2 = #0 (HasCodeBefore = 0)
+ if(x > 5) { // CHECK-NEXT: File 0, [[@LINE]]:13 -> [[@LINE+6]]:4 = #1 (HasCodeBefore = 0)
+ while(x >= 9) { // CHECK-NEXT: File 0, [[@LINE]]:11 -> [[@LINE]]:17 = #1 (HasCodeBefore = 0)
+ return; // CHECK-NEXT: File 0, [[@LINE-1]]:19 -> [[@LINE+2]]:6 = #2 (HasCodeBefore = 0)
+ --x; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:10 = 0 (HasCodeBefore = 0)
+ }
+ int i = 0; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:14 = (#1 - #2) (HasCodeBefore = 0)
+ }
+ int j = 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:12 = (#0 - #2) (HasCodeBefore = 0)
+}
diff --git a/clang/test/CoverageMapping/switch.c b/clang/test/CoverageMapping/switch.c
new file mode 100644
index 00000000000..b6672258591
--- /dev/null
+++ b/clang/test/CoverageMapping/switch.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.c %s | FileCheck %s
+ // CHECK: foo
+void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 (HasCodeBefore = 0)
+ switch(i) {
+ case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = #2 (HasCodeBefore = 0)
+ return;
+ case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3 (HasCodeBefore = 0)
+ break;
+ } // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:12 = #1 (HasCodeBefore = 0)
+ int x = 0;
+}
+
+ // CHECK-NEXT: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 = #0 (HasCodeBefore = 0)
+ int i = 0;
+ switch(i) {
+ case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #2 (HasCodeBefore = 0)
+ i = 1;
+ break;
+ case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #3 (HasCodeBefore = 0)
+ i = 2;
+ break;
+ default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 (HasCodeBefore = 0)
+ break;
+ } // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:14 = #1 (HasCodeBefore = 0)
+ switch(i) {
+ case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #6 (HasCodeBefore = 0)
+ i = 1;
+ break;
+ case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #7 (HasCodeBefore = 0)
+ i = 2;
+ default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = (#7 + #8) (HasCodeBefore = 0)
+ break;
+ } // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:14 = #5 (HasCodeBefore = 0)
+
+
+ switch(i) {
+ case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:10 = #10 (HasCodeBefore = 0)
+ case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (#10 + #11) (HasCodeBefore = 0)
+ i = 11;
+ case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:10 = ((#10 + #11) + #12) (HasCodeBefore = 0)
+ case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13) (HasCodeBefore = 0)
+ i = 99;
+ } // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9 (HasCodeBefore = 0)
+
+ foo(1);
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/templates.cpp b/clang/test/CoverageMapping/templates.cpp
new file mode 100644
index 00000000000..fcb92e1e9f5
--- /dev/null
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+
+template<typename T>
+void unused(T x) {
+ return;
+}
+
+template<typename T>
+int func(T x) { // CHECK: func
+ if(x) // CHECK: func
+ return 0;
+ else
+ return 1;
+ int j = 1;
+}
+
+int main() {
+ func<int>(0);
+ func<bool>(true);
+ return 0;
+}
diff --git a/clang/test/CoverageMapping/test.c b/clang/test/CoverageMapping/test.c
new file mode 100644
index 00000000000..594bcf68bc0
--- /dev/null
+++ b/clang/test/CoverageMapping/test.c
@@ -0,0 +1,31 @@
+// 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();
+
+ // CHECK: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+7]]:2 = #0 (HasCodeBefore = 0)
+ // CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:24 = (#0 + #1) (HasCodeBefore = 0)
+ for(int i = 0; i < 10; ++i) { // CHECK-NEXT: File 0, [[@LINE]]:26 -> [[@LINE]]:29 = #1 (HasCodeBefore = 0)
+ bar(); // CHECK-NEXT: File 0, [[@LINE-1]]:31 -> [[@LINE+1]]:4 = #1 (HasCodeBefore = 0)
+ }
+ static_func();
+ return 0;
+}
+
+ // CHECK-NEXT: foo
+void foo() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+4]]:2 = #0 (HasCodeBefore = 0)
+ if(1) { // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE+2]]:4 = #1 (HasCodeBefore = 0)
+ int i = 0;
+ }
+}
+
+ // CHECK-NEXT: bar
+void bar() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+1]]:2 = #0 (HasCodeBefore = 0)
+}
+
+ // CHECK-NEXT: static_func
+void static_func() { } // CHECK: File 0, [[@LINE]]:20 -> [[@LINE]]:23 = #0 (HasCodeBefore = 0)
+
+ // CHECK-NEXT: func
+static void func() { } // CHECK: File 0, [[@LINE]]:20 -> [[@LINE]]:23 = 0 (HasCodeBefore = 0)
diff --git a/clang/test/CoverageMapping/trycatch.cpp b/clang/test/CoverageMapping/trycatch.cpp
new file mode 100644
index 00000000000..a513845c28a
--- /dev/null
+++ b/clang/test/CoverageMapping/trycatch.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -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 {
+};
+
+ // CHECK: func
+void func(int i) { // CHECK-NEXT: File 0, [[@LINE]]:18 -> [[@LINE+5]]:2 = #0 (HasCodeBefore = 0)
+ if(i % 2)
+ throw Error(); // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:16 = #1 (HasCodeBefore = 0)
+ else if(i == 8) // CHECK-NEXT: File 0, [[@LINE]]:8 -> [[@LINE]]:17 = (#0 - #1) (HasCodeBefore = 0)
+ throw ImportantError(); // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:25 = #2 (HasCodeBefore = 0)
+}
+
+ // CHECK-NEXT: main
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+13]]:2 = #0 (HasCodeBefore = 0)
+ int j = 0;
+ try {
+ func(j);
+ } catch(const Error &e) { // CHECK-NEXT: File 0, [[@LINE]]:27 -> [[@LINE+2]]:10 = #2 (HasCodeBefore = 0)
+ j = 1;
+ } catch(const ImportantError &e) { // CHECK-NEXT: File 0, [[@LINE]]:36 -> [[@LINE+3]]:8 = #3 (HasCodeBefore = 0)
+ j = 11;
+ }
+ catch(const Warning &w) { // CHECK-NEXT: File 0, [[@LINE]]:27 -> [[@LINE+2]]:4 = #4 (HasCodeBefore = 0)
+ j = 0;
+ }
+ return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = #1 (HasCodeBefore = 0)
+}
OpenPOWER on IntegriCloud