[PATCH] D25572: [Coverage] Support for C++17 if initializers

2016-10-14 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284293: [Coverage] Support for C++17 if initializers 
(authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25572?vs=74559=74753#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25572

Files:
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/if.c
  cfe/trunk/test/CoverageMapping/if.cpp
  cfe/trunk/test/Profile/cxx-stmt-initializers.cpp

Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -875,6 +875,9 @@
 
   void VisitIfStmt(const IfStmt *S) {
 extendRegion(S);
+if (S->getInit())
+  Visit(S->getInit());
+
 // Extend into the condition before we propagate through it below - this is
 // needed to handle macros that generate the "if" but not the condition.
 extendRegion(S->getCond());
Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -490,6 +490,8 @@
   void VisitIfStmt(const IfStmt *S) {
 RecordStmtCount(S);
 uint64_t ParentCount = CurrentCount;
+if (S->getInit())
+  Visit(S->getInit());
 Visit(S->getCond());
 
 // Counter tracks the "then" part of an if statement. The count for
Index: cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
===
--- cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
+++ cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
@@ -4,6 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // PGOGEN: @[[SIC:__profc__Z11switch_initv]] = private global [3 x i64] zeroinitializer
+// PGOGEN: @[[IIC:__profc__Z7if_initv]] = private global [3 x i64] zeroinitializer
 
 // Note: We expect counters for the function entry block, the condition in the
 // switch initializer, and the switch successor block.
@@ -15,3 +16,14 @@
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 2
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 1
 }
+
+// Note: We expect counters for the function entry block, the condition in the
+// if initializer, and the if successor block.
+//
+// CHECK-LABEL: define {{.*}}void @_Z7if_initv()
+// PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 0
+void if_init() {
+  if (int i = true ? 0 : 1; i) {}
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 2
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 1
+}
Index: cfe/trunk/test/CoverageMapping/if.cpp
===
--- cfe/trunk/test/CoverageMapping/if.cpp
+++ cfe/trunk/test/CoverageMapping/if.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name if.cpp %s | FileCheck %s
+
+int nop() { return 0; }
+
+// CHECK-LABEL: _Z3foov:
+void foo() {// CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+5]]:2 = #0
+  if (int j = true ? nop()  // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = #2
+   : nop(); // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = (#0 - #2)
+  j)// CHECK-NEXT: [[@LINE]]:7 -> [[@LINE]]:8 = #0
+++j;// CHECK-NEXT: [[@LINE]]:5 -> [[@LINE]]:8 = #1
+}
+
+// CHECK-LABEL: main:
+int main() {// CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 = #0
+  int i = 0;
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 0) i = 1; // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE]]:19 = #1
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 1)
+i = 2;  // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = #2
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i == 0) { i = 1;   // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #3
+i = 2;
+  }
+// CHECK-NEXT: File 0, [[@LINE+1]]:6 -> [[@LINE+1]]:12 = #0
+  if(i != 0) {  // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+2]]:4 = #4
+i = 1;
+  } else {  // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE+2]]:4 = (#0 - #4)
+i = 3;
+  }
+
+  i = i == 0?
+i + 1 : // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = #5
+i + 2;  // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:14 = (#0 - #5)
+// CHECK-NEXT: File 0, [[@LINE+1]]:14 -> [[@LINE+1]]:20 = #6
+  i = i == 0?i + 12:i + 10; // CHECK-NEXT: File 0, [[@LINE]]:21 -> [[@LINE]]:27 = (#0 - #6)
+
+  return 0;
+}

[PATCH] D25572: [Coverage] Support for C++17 if initializers

2016-10-14 Thread Igor Kudrin via cfe-commits
ikudrin accepted this revision.
ikudrin added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D25572



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25572: [Coverage] Support for C++17 if initializers

2016-10-13 Thread Vedant Kumar via cfe-commits
vsk created this revision.
vsk added reviewers: arphaman, ikudrin.
vsk added a subscriber: cfe-commits.

Generate coverage mappings for  in if (; ).

Here's some sample output (let's hope phab gets the spaces right :) --

  12|   |// CHECK-LABEL: define {{.*}}void @_Z11switch_initv()
  13|   |// PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 0
  14|  1|void switch_init() {
  15|  1|  switch (int i = true ? 0 : 1; i) {}
  ^1  ^0
  16|  1|  // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 2
  17|  1|  // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 1
  18|  1|}
  19|   |
  20|   |// Note: We expect counters for the function entry block, the 
condition in the
  21|   |// if initializer, and the if successor block.
  22|   |//
  23|   |// CHECK-LABEL: define {{.*}}void @_Z7if_initv()
  24|   |// PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 0
  25|  1|void if_init() {
  26|  1|  if (int i = true ? 0 : 1; i) {}
  ^1  ^0 ^1 ^0
  27|  1|  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 2
  28|  1|  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 1
  29|  1|}

I did some local testing of this patch (as well as 
https://reviews.llvm.org/D25539) using a maze of macros to generate parts of 
the IfStmt / SwitchStmt. The goal of that exercise was to break popRegions(). 
Ultimately I decided against checking those tests in because they seem a bit 
paranoid. We're not actually pushing new regions for the initializer 
statements..


https://reviews.llvm.org/D25572

Files:
  lib/CodeGen/CodeGenPGO.cpp
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/if.c
  test/CoverageMapping/if.cpp
  test/Profile/cxx-stmt-initializers.cpp


Index: test/Profile/cxx-stmt-initializers.cpp
===
--- test/Profile/cxx-stmt-initializers.cpp
+++ test/Profile/cxx-stmt-initializers.cpp
@@ -4,6 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN 
%s
 
 // PGOGEN: @[[SIC:__profc__Z11switch_initv]] = private global [3 x i64] 
zeroinitializer
+// PGOGEN: @[[IIC:__profc__Z7if_initv]] = private global [3 x i64] 
zeroinitializer
 
 // Note: We expect counters for the function entry block, the condition in the
 // switch initializer, and the switch successor block.
@@ -15,3 +16,14 @@
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 2
   // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 1
 }
+
+// Note: We expect counters for the function entry block, the condition in the
+// if initializer, and the if successor block.
+//
+// CHECK-LABEL: define {{.*}}void @_Z7if_initv()
+// PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 0
+void if_init() {
+  if (int i = true ? 0 : 1; i) {}
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 2
+  // PGOGEN: store {{.*}} @[[IIC]], i64 0, i64 1
+}
Index: test/CoverageMapping/if.cpp
===
--- test/CoverageMapping/if.cpp
+++ test/CoverageMapping/if.cpp
@@ -1,5 +1,16 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -main-file-name if.c %s | FileCheck %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple 
-main-file-name if.cpp %s | FileCheck %s
 
+int nop() { return 0; }
+
+// CHECK-LABEL: _Z3foov:
+void foo() {// CHECK-NEXT: [[@LINE]]:12 -> [[@LINE+5]]:2 = 
#0
+  if (int j = true ? nop()  // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = 
#2
+   : nop(); // CHECK-NEXT: [[@LINE]]:22 -> [[@LINE]]:27 = 
(#0 - #2)
+  j)// CHECK-NEXT: [[@LINE]]:7 -> [[@LINE]]:8 = #0
+++j;// CHECK-NEXT: [[@LINE]]:5 -> [[@LINE]]:8 = #1
+}
+
+// CHECK-LABEL: main:
 int main() {// CHECK: File 0, [[@LINE]]:12 -> {{[0-9]+}}:2 
= #0
   int i = 0;
 // CHECK-NEXT: File 0, [[@LINE+1]]:6 -> 
[[@LINE+1]]:12 = #0
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -875,6 +875,9 @@
 
   void VisitIfStmt(const IfStmt *S) {
 extendRegion(S);
+if (S->getInit())
+  Visit(S->getInit());
+
 // Extend into the condition before we propagate through it below - this is
 // needed to handle macros that generate the "if" but not the condition.
 extendRegion(S->getCond());
Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -490,6 +490,8 @@
   void VisitIfStmt(const IfStmt *S) {
 RecordStmtCount(S);
 uint64_t ParentCount = CurrentCount;
+if (S->getInit())
+  Visit(S->getInit());
 Visit(S->getCond());
 
 //