r215995 - Add tests for coverage mapping generation.

Alex Lorenz arphaman at gmail.com
Tue Aug 19 10:32:31 PDT 2014


Author: arphaman
Date: Tue Aug 19 12:32:30 2014
New Revision: 215995

URL: http://llvm.org/viewvc/llvm-project?rev=215995&view=rev
Log:
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

Added:
    cfe/trunk/test/CoverageMapping/Inputs/code.h
    cfe/trunk/test/CoverageMapping/Inputs/header1.h
    cfe/trunk/test/CoverageMapping/break.c
    cfe/trunk/test/CoverageMapping/builtinmacro.c
    cfe/trunk/test/CoverageMapping/casts.c
    cfe/trunk/test/CoverageMapping/classtemplate.cpp
    cfe/trunk/test/CoverageMapping/continue.c
    cfe/trunk/test/CoverageMapping/header.cpp
    cfe/trunk/test/CoverageMapping/if.c
    cfe/trunk/test/CoverageMapping/includehell.cpp
    cfe/trunk/test/CoverageMapping/ir.c
    cfe/trunk/test/CoverageMapping/label.cpp
    cfe/trunk/test/CoverageMapping/logical.cpp
    cfe/trunk/test/CoverageMapping/loopmacro.c
    cfe/trunk/test/CoverageMapping/loops.cpp
    cfe/trunk/test/CoverageMapping/macroception.c
    cfe/trunk/test/CoverageMapping/macroparams.c
    cfe/trunk/test/CoverageMapping/macroparams2.c
    cfe/trunk/test/CoverageMapping/macros.c
    cfe/trunk/test/CoverageMapping/nestedclass.cpp
    cfe/trunk/test/CoverageMapping/preprocessor.c
    cfe/trunk/test/CoverageMapping/return.c
    cfe/trunk/test/CoverageMapping/switch.c
    cfe/trunk/test/CoverageMapping/templates.cpp
    cfe/trunk/test/CoverageMapping/test.c
    cfe/trunk/test/CoverageMapping/trycatch.cpp

Added: cfe/trunk/test/CoverageMapping/Inputs/code.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/code.h?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/Inputs/code.h (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/code.h Tue Aug 19 12:32:30 2014
@@ -0,0 +1,11 @@
+x = x;
+if (x == 0) {
+  x = 1;
+} else {
+  x = 2;
+}
+if (true) {
+  x = x;
+} else {
+  x = x;
+}

Added: cfe/trunk/test/CoverageMapping/Inputs/header1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/header1.h?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/Inputs/header1.h (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/header1.h Tue Aug 19 12:32:30 2014
@@ -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

Added: cfe/trunk/test/CoverageMapping/break.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/break.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/break.c (added)
+++ cfe/trunk/test/CoverageMapping/break.c Tue Aug 19 12:32:30 2014
@@ -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;
+  }
+}

Added: cfe/trunk/test/CoverageMapping/builtinmacro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/builtinmacro.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/builtinmacro.c (added)
+++ cfe/trunk/test/CoverageMapping/builtinmacro.c Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/casts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/casts.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/casts.c (added)
+++ cfe/trunk/test/CoverageMapping/casts.c Tue Aug 19 12:32:30 2014
@@ -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;
+}
+
+
+
+

Added: cfe/trunk/test/CoverageMapping/classtemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/classtemplate.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/classtemplate.cpp (added)
+++ cfe/trunk/test/CoverageMapping/classtemplate.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/continue.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/continue.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/continue.c (added)
+++ cfe/trunk/test/CoverageMapping/continue.c Tue Aug 19 12:32:30 2014
@@ -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)
+  }
+}

Added: cfe/trunk/test/CoverageMapping/header.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/header.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/header.cpp (added)
+++ cfe/trunk/test/CoverageMapping/header.cpp Tue Aug 19 12:32:30 2014
@@ -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)

Added: cfe/trunk/test/CoverageMapping/if.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/if.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/if.c (added)
+++ cfe/trunk/test/CoverageMapping/if.c Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/includehell.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/includehell.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/includehell.cpp (added)
+++ cfe/trunk/test/CoverageMapping/includehell.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/ir.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/ir.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/ir.c (added)
+++ cfe/trunk/test/CoverageMapping/ir.c Tue Aug 19 12:32:30 2014
@@ -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 }]

Added: cfe/trunk/test/CoverageMapping/label.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/label.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/label.cpp (added)
+++ cfe/trunk/test/CoverageMapping/label.cpp Tue Aug 19 12:32:30 2014
@@ -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);
+}

Added: cfe/trunk/test/CoverageMapping/logical.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/logical.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/logical.cpp (added)
+++ cfe/trunk/test/CoverageMapping/logical.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/loopmacro.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/loopmacro.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/loopmacro.c (added)
+++ cfe/trunk/test/CoverageMapping/loopmacro.c Tue Aug 19 12:32:30 2014
@@ -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)

Added: cfe/trunk/test/CoverageMapping/loops.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/loops.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/loops.cpp (added)
+++ cfe/trunk/test/CoverageMapping/loops.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/macroception.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macroception.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/macroception.c (added)
+++ cfe/trunk/test/CoverageMapping/macroception.c Tue Aug 19 12:32:30 2014
@@ -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)

Added: cfe/trunk/test/CoverageMapping/macroparams.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macroparams.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/macroparams.c (added)
+++ cfe/trunk/test/CoverageMapping/macroparams.c Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/macroparams2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macroparams2.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/macroparams2.c (added)
+++ cfe/trunk/test/CoverageMapping/macroparams2.c Tue Aug 19 12:32:30 2014
@@ -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
+

Added: cfe/trunk/test/CoverageMapping/macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macros.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/macros.c (added)
+++ cfe/trunk/test/CoverageMapping/macros.c Tue Aug 19 12:32:30 2014
@@ -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)
+

Added: cfe/trunk/test/CoverageMapping/nestedclass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/nestedclass.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/nestedclass.cpp (added)
+++ cfe/trunk/test/CoverageMapping/nestedclass.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/preprocessor.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/preprocessor.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/preprocessor.c (added)
+++ cfe/trunk/test/CoverageMapping/preprocessor.c Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/return.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/return.c (added)
+++ cfe/trunk/test/CoverageMapping/return.c Tue Aug 19 12:32:30 2014
@@ -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)
+}

Added: cfe/trunk/test/CoverageMapping/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/switch.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/switch.c (added)
+++ cfe/trunk/test/CoverageMapping/switch.c Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/templates.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/templates.cpp (added)
+++ cfe/trunk/test/CoverageMapping/templates.cpp Tue Aug 19 12:32:30 2014
@@ -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;
+}

Added: cfe/trunk/test/CoverageMapping/test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/test.c?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/test.c (added)
+++ cfe/trunk/test/CoverageMapping/test.c Tue Aug 19 12:32:30 2014
@@ -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)

Added: cfe/trunk/test/CoverageMapping/trycatch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/trycatch.cpp?rev=215995&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/trycatch.cpp (added)
+++ cfe/trunk/test/CoverageMapping/trycatch.cpp Tue Aug 19 12:32:30 2014
@@ -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)
+}





More information about the cfe-commits mailing list