r284293 - [Coverage] Support for C++17 if initializers
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 16:38:17 PDT 2016
Author: vedantk
Date: Fri Oct 14 18:38:16 2016
New Revision: 284293
URL: http://llvm.org/viewvc/llvm-project?rev=284293&view=rev
Log:
[Coverage] Support for C++17 if initializers
Differential Revision: https://reviews.llvm.org/D25572
Added:
cfe/trunk/test/CoverageMapping/if.cpp
- copied, changed from r284292, cfe/trunk/test/CoverageMapping/if.c
Removed:
cfe/trunk/test/CoverageMapping/if.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=284293&r1=284292&r2=284293&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Oct 14 18:38:16 2016
@@ -490,6 +490,8 @@ struct ComputeRegionCounts : public Cons
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
Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=284293&r1=284292&r2=284293&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Fri Oct 14 18:38:16 2016
@@ -875,6 +875,9 @@ struct CounterCoverageMappingBuilder
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());
Removed: cfe/trunk/test/CoverageMapping/if.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/if.c?rev=284292&view=auto
==============================================================================
--- cfe/trunk/test/CoverageMapping/if.c (original)
+++ cfe/trunk/test/CoverageMapping/if.c (removed)
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name if.c %s | FileCheck %s
-
-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;
-}
Copied: cfe/trunk/test/CoverageMapping/if.cpp (from r284292, cfe/trunk/test/CoverageMapping/if.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/if.cpp?p2=cfe/trunk/test/CoverageMapping/if.cpp&p1=cfe/trunk/test/CoverageMapping/if.c&r1=284292&r2=284293&rev=284293&view=diff
==============================================================================
--- cfe/trunk/test/CoverageMapping/if.c (original)
+++ cfe/trunk/test/CoverageMapping/if.cpp Fri Oct 14 18:38:16 2016
@@ -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
Modified: cfe/trunk/test/Profile/cxx-stmt-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-stmt-initializers.cpp?rev=284293&r1=284292&r2=284293&view=diff
==============================================================================
--- cfe/trunk/test/Profile/cxx-stmt-initializers.cpp (original)
+++ cfe/trunk/test/Profile/cxx-stmt-initializers.cpp Fri Oct 14 18:38:16 2016
@@ -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 @@ void switch_init() {
// 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
+}
More information about the cfe-commits
mailing list