<div dir="auto">Do we need the same change for if-statements too?</div><div class="gmail_extra"><br><div class="gmail_quote">On 12 Oct 2016 6:26 pm, "Vedant Kumar via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">vsk created this revision.<br>
vsk added reviewers: arphaman, ikudrin.<br>
vsk added a subscriber: cfe-commits.<br>
<br>
Generate coverage mappings for <init> in switch (<init>; <cond>).<br>
<br>
I'm unsure about whether or not the CodeGenPGO change in this patch deserves more testing.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D25539" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D25539</a><br>
<br>
Files:<br>
lib/CodeGen/CodeGenPGO.cpp<br>
lib/CodeGen/<wbr>CoverageMappingGen.cpp<br>
test/CoverageMapping/switch.c<br>
test/CoverageMapping/switch.<wbr>cpp<br>
<br>
<br>
Index: test/CoverageMapping/switch.<wbr>cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- test/CoverageMapping/switch.<wbr>cpp<br>
+++ test/CoverageMapping/switch.<wbr>cpp<br>
@@ -1,4 +1,5 @@<br>
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.c %s | FileCheck %s<br>
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name switch.cpp %s | FileCheck %s<br>
+<br>
// CHECK: foo<br>
void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0<br>
switch(i) {<br>
@@ -10,7 +11,7 @@<br>
int x = 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1<br>
}<br>
<br>
-void nop() {}<br>
+int nop() { return 0; }<br>
<br>
// CHECK: bar<br>
void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 = #0<br>
@@ -35,8 +36,16 @@<br>
nop(); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #6<br>
}<br>
<br>
+ // CHECK: baz<br>
+void baz() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 = #0<br>
+ switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = #2<br>
+ : nop(); // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = (#0 - #2)<br>
+ i) {}<br>
+ nop(); // CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1<br>
+}<br>
+<br>
// CHECK-NEXT: main<br>
-int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 = #0<br>
+int main() { // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 = #0<br>
int i = 0;<br>
switch(i) {<br>
case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 = #2<br>
@@ -48,7 +57,7 @@<br>
default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4<br>
break;<br>
}<br>
- switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+22]]:2 = #1<br>
+ switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1<br>
case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6<br>
i = 1;<br>
break;<br>
@@ -58,16 +67,17 @@<br>
break;<br>
}<br>
<br>
- switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+12]]:2 = #5<br>
+ switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5<br>
case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 = #10<br>
case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 = (#10 + #11)<br>
i = 11;<br>
case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#10 + #11) + #12)<br>
case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13)<br>
i = 99;<br>
}<br>
<br>
- foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = #9<br>
+ foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9<br>
bar(1);<br>
+ baz();<br>
return 0;<br>
}<br>
Index: lib/CodeGen/<wbr>CoverageMappingGen.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/CodeGen/<wbr>CoverageMappingGen.cpp<br>
+++ lib/CodeGen/<wbr>CoverageMappingGen.cpp<br>
@@ -813,6 +813,9 @@<br>
<br>
void VisitSwitchStmt(const SwitchStmt *S) {<br>
extendRegion(S);<br>
+ if (S->getInit())<br>
+ Visit(S->getInit());<br>
+<br>
Visit(S->getCond());<br>
<br>
BreakContinueStack.push_back(<wbr>BreakContinue());<br>
Index: lib/CodeGen/CodeGenPGO.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/CodeGen/CodeGenPGO.cpp<br>
+++ lib/CodeGen/CodeGenPGO.cpp<br>
@@ -458,6 +458,8 @@<br>
<br>
void VisitSwitchStmt(const SwitchStmt *S) {<br>
RecordStmtCount(S);<br>
+ if (S->getInit())<br>
+ Visit(S->getInit());<br>
Visit(S->getCond());<br>
CurrentCount = 0;<br>
BreakContinueStack.push_back(<wbr>BreakContinue());<br>
<br>
<br>
<br>______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div></div>