[PATCH] D25539: [Coverage] Support for C++17 switch initializers
This revision was automatically updated to reflect the committed changes. Closed by commit rL284292: [Coverage] Support for C++17 switch initializers (authored by vedantk). Changed prior to commit: https://reviews.llvm.org/D25539?vs=74552&id=74752#toc Repository: rL LLVM https://reviews.llvm.org/D25539 Files: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp cfe/trunk/test/CoverageMapping/switch.c cfe/trunk/test/CoverageMapping/switch.cpp cfe/trunk/test/Profile/cxx-stmt-initializers.cpp Index: cfe/trunk/test/CoverageMapping/switch.cpp === --- cfe/trunk/test/CoverageMapping/switch.cpp +++ cfe/trunk/test/CoverageMapping/switch.cpp @@ -0,0 +1,83 @@ +// 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 + +// CHECK: foo +void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 + switch(i) { + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #2 +return; + case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3 +break; + } + int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 +} + +int nop() { return 0; } + +// CHECK: bar +void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 = #0 + switch (i) +; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:6 = 0 + + switch (i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+16]]:2 = #1 + } + + switch (i)// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #2 +nop(); // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:10 = 0 + + switch (i)// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+10]]:2 = #3 + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #5 +nop(); + + switch (i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:2 = #4 +nop(); // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:10 = 0 + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #7 +nop(); + } + nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #6 +} + +// CHECK: baz +void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 = #0 + switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = #2 + : nop(); // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = (#0 - #2) + i) {} + nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 +} + +// CHECK-NEXT: main +int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 = #0 + int i = 0; + switch(i) { + case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 = #2 +i = 1; +break; + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = #3 +i = 2; +break; + default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 +break; + } + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1 + case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6 +i = 1; +break; + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #7 +i = 2; + default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = (#7 + #8) +break; + } + + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5 + case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 = #10 + case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 = (#10 + #11) +i = 11; + case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#10 + #11) + #12) + case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13) +i = 99; + } + + foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9 + bar(1); + baz(); + return 0; +} Index: cfe/trunk/test/CoverageMapping/switch.c === --- cfe/trunk/test/CoverageMapping/switch.c +++ cfe/trunk/test/CoverageMapping/switch.c @@ -1,73 +0,0 @@ -// RUN: %clang_cc1 -fprofile-instrument=clang -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 - switch(i) { - case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = #2 -return; - case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #3 -break; - } - int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 -} - -void nop() {} - -// CHECK: bar -void bar(int i) { // CHECK-NE
[PATCH] D25539: [Coverage] Support for C++17 switch initializers
ikudrin accepted this revision. ikudrin added a comment. This revision is now accepted and ready to land. LGTM. https://reviews.llvm.org/D25539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25539: [Coverage] Support for C++17 switch initializers
vsk updated the summary for this revision. vsk updated this revision to Diff 74552. vsk added a comment. Per @arphaman's comments: - Add a CodeGenPGO test which checks whether counters can be created for statements inside of switch initializers. - Group calls to 'Visit' together. https://reviews.llvm.org/D25539 Files: lib/CodeGen/CodeGenPGO.cpp lib/CodeGen/CoverageMappingGen.cpp test/CoverageMapping/switch.c test/CoverageMapping/switch.cpp test/Profile/cxx-stmt-initializers.cpp Index: test/Profile/cxx-stmt-initializers.cpp === --- /dev/null +++ test/Profile/cxx-stmt-initializers.cpp @@ -0,0 +1,17 @@ +// Tests for instrumentation of C++17 statement initializers + +// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-stmt-initializers.cpp -std=c++1z -o - -emit-llvm -fprofile-instrument=clang > %tgen +// RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s + +// PGOGEN: @[[SIC:__profc__Z11switch_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. +// +// CHECK-LABEL: define {{.*}}void @_Z11switch_initv() +// PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 0 +void switch_init() { + switch (int i = true ? 0 : 1; i) {} + // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 2 + // PGOGEN: store {{.*}} @[[SIC]], i64 0, i64 1 +} Index: test/CoverageMapping/switch.cpp === --- test/CoverageMapping/switch.cpp +++ test/CoverageMapping/switch.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.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 switch.cpp %s | FileCheck %s + // CHECK: foo void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 switch(i) { @@ -10,7 +11,7 @@ int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 } -void nop() {} +int nop() { return 0; } // CHECK: bar void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 = #0 @@ -35,8 +36,16 @@ nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #6 } +// CHECK: baz +void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 = #0 + switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = #2 + : nop(); // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = (#0 - #2) + i) {} + nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 +} + // CHECK-NEXT: main -int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 = #0 +int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 = #0 int i = 0; switch(i) { case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 = #2 @@ -48,7 +57,7 @@ default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 break; } - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+22]]:2 = #1 + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1 case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6 i = 1; break; @@ -58,16 +67,17 @@ break; } - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+12]]:2 = #5 + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5 case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 = #10 case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 = (#10 + #11) i = 11; case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#10 + #11) + #12) case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13) i = 99; } - foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = #9 + foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9 bar(1); + baz(); return 0; } Index: lib/CodeGen/CoverageMappingGen.cpp === --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -813,6 +813,8 @@ void VisitSwitchStmt(const SwitchStmt *S) { extendRegion(S); +if (S->getInit()) + Visit(S->getInit()); Visit(S->getCond()); BreakContinueStack.push_back(BreakContinue()); Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -458,6 +458,8 @@ void VisitSwitchStmt(const
[PATCH] D25539: [Coverage] Support for C++17 switch initializers
arphaman added a comment. > I'm unsure about whether or not the CodeGenPGO change in this patch deserves > more testing. It wouldn't harm to add a test for CodeGenPGO as well. A good test that you can as a starting point for the new one is `test/Profile/cxx-rangefor.cpp`. A single `PGOGEN` check for a PGO counter generated from a subexpression in a switch initializer should be sufficient. Comment at: lib/CodeGen/CoverageMappingGen.cpp:818 + Visit(S->getInit()); + Visit(S->getCond()); I noticed that you added a newline here, wouldn't it be better to have it after `extendRegion(S)` so that the `Visit` calls are grouped together? https://reviews.llvm.org/D25539 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D25539: [Coverage] Support for C++17 switch initializers
On 13 October 2016 at 03:42, Richard Smith wrote: > Do we need the same change for if-statements too? > Yes, a similar change should be made for them as well. > > On 12 Oct 2016 6:26 pm, "Vedant Kumar via cfe-commits" < > cfe-commits@lists.llvm.org> wrote: > >> vsk created this revision. >> vsk added reviewers: arphaman, ikudrin. >> vsk added a subscriber: cfe-commits. >> >> Generate coverage mappings for in switch (; ). >> >> I'm unsure about whether or not the CodeGenPGO change in this patch >> deserves more testing. >> >> >> https://reviews.llvm.org/D25539 >> >> Files: >> lib/CodeGen/CodeGenPGO.cpp >> lib/CodeGen/CoverageMappingGen.cpp >> test/CoverageMapping/switch.c >> test/CoverageMapping/switch.cpp >> >> >> Index: test/CoverageMapping/switch.cpp >> === >> --- test/CoverageMapping/switch.cpp >> +++ test/CoverageMapping/switch.cpp >> @@ -1,4 +1,5 @@ >> -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping >> -dump-coverage-mapping -emit-llvm-only -main-file-name switch.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 switch.cpp %s | FileCheck %s >> + >> // CHECK: foo >> void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 >> = #0 >>switch(i) { >> @@ -10,7 +11,7 @@ >>int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 >> = #1 >> } >> >> -void nop() {} >> +int nop() { return 0; } >> >> // CHECK: bar >> void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> >> [[@LINE+20]]:2 = #0 >> @@ -35,8 +36,16 @@ >>nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 >> = #6 >> } >> >> +// CHECK: baz >> +void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 >> = #0 >> + switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> >> [[@LINE]]:31 = #2 >> + : nop(); // CHECK-NEXT: [[@LINE]]:26 -> >> [[@LINE]]:31 = (#0 - #2) >> + i) {} >> + nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 >> +} >> + >> // CHECK-NEXT: main >> -int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> >> [[@LINE+34]]:2 = #0 >> +int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> >> [[@LINE+35]]:2 = #0 >>int i = 0; >>switch(i) { >>case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 >> = #2 >> @@ -48,7 +57,7 @@ >>default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 >> = #4 >> break; >>} >> - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+22]]:2 >> = #1 >> + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 >> = #1 >>case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 >> = #6 >> i = 1; >> break; >> @@ -58,16 +67,17 @@ >> break; >>} >> >> - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+12]]:2 >> = #5 >> + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 >> = #5 >>case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 >> = #10 >>case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 >> = (#10 + #11) >> i = 11; >>case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 >> = ((#10 + #11) + #12) >>case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 >> = (((#10 + #11) + #12) + #13) >> i = 99; >>} >> >> - foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 >> = #9 >> + foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 >> = #9 >>bar(1); >> + baz(); >>return 0; >> } >> Index: lib/CodeGen/CoverageMappingGen.cpp >> === >> --- lib/CodeGen/CoverageMappingGen.cpp >> +++ lib/CodeGen/CoverageMappingGen.cpp >> @@ -813,6 +813,9 @@ >> >>void VisitSwitchStmt(const SwitchStmt *S) { >> extendRegion(S); >> +if (S->getInit()) >> + Visit(S->getInit()); >> + >> Visit(S->getCond()); >> >> BreakContinueStack.push_back(BreakContinue()); >> Index: lib/CodeGen/CodeGenPGO.cpp >> === >> --- lib/CodeGen/CodeGenPGO.cpp >> +++ lib/CodeGen/CodeGenPGO.cpp >> @@ -458,6 +458,8 @@ >> >>void VisitSwitchStmt(const SwitchStmt *S) { >> RecordStmtCount(S); >> +if (S->getInit()) >> + Visit(S->getInit()); >> Visit(S->getCond()); >> CurrentCount = 0; >> BreakContinueStack.push_back(BreakContinue()); >> >> >> >> ___ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> >> ___
Re: [PATCH] D25539: [Coverage] Support for C++17 switch initializers
Do we need the same change for if-statements too? On 12 Oct 2016 6:26 pm, "Vedant Kumar via cfe-commits" < cfe-commits@lists.llvm.org> wrote: > vsk created this revision. > vsk added reviewers: arphaman, ikudrin. > vsk added a subscriber: cfe-commits. > > Generate coverage mappings for in switch (; ). > > I'm unsure about whether or not the CodeGenPGO change in this patch > deserves more testing. > > > https://reviews.llvm.org/D25539 > > Files: > lib/CodeGen/CodeGenPGO.cpp > lib/CodeGen/CoverageMappingGen.cpp > test/CoverageMapping/switch.c > test/CoverageMapping/switch.cpp > > > Index: test/CoverageMapping/switch.cpp > === > --- test/CoverageMapping/switch.cpp > +++ test/CoverageMapping/switch.cpp > @@ -1,4 +1,5 @@ > -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping > -dump-coverage-mapping -emit-llvm-only -main-file-name switch.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 switch.cpp %s | FileCheck %s > + > // CHECK: foo > void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 > = #0 >switch(i) { > @@ -10,7 +11,7 @@ >int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = > #1 > } > > -void nop() {} > +int nop() { return 0; } > > // CHECK: bar > void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 > = #0 > @@ -35,8 +36,16 @@ >nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = > #6 > } > > +// CHECK: baz > +void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 > = #0 > + switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> > [[@LINE]]:31 = #2 > + : nop(); // CHECK-NEXT: [[@LINE]]:26 -> > [[@LINE]]:31 = (#0 - #2) > + i) {} > + nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 > +} > + > // CHECK-NEXT: main > -int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 > = #0 > +int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 > = #0 >int i = 0; >switch(i) { >case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 > = #2 > @@ -48,7 +57,7 @@ >default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 > = #4 > break; >} > - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+22]]:2 > = #1 > + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 > = #1 >case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 > = #6 > i = 1; > break; > @@ -58,16 +67,17 @@ > break; >} > > - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+12]]:2 > = #5 > + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 > = #5 >case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 > = #10 >case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 > = (#10 + #11) > i = 11; >case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 > = ((#10 + #11) + #12) >case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 > = (((#10 + #11) + #12) + #13) > i = 99; >} > > - foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 > = #9 > + foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 > = #9 >bar(1); > + baz(); >return 0; > } > Index: lib/CodeGen/CoverageMappingGen.cpp > === > --- lib/CodeGen/CoverageMappingGen.cpp > +++ lib/CodeGen/CoverageMappingGen.cpp > @@ -813,6 +813,9 @@ > >void VisitSwitchStmt(const SwitchStmt *S) { > extendRegion(S); > +if (S->getInit()) > + Visit(S->getInit()); > + > Visit(S->getCond()); > > BreakContinueStack.push_back(BreakContinue()); > Index: lib/CodeGen/CodeGenPGO.cpp > === > --- lib/CodeGen/CodeGenPGO.cpp > +++ lib/CodeGen/CodeGenPGO.cpp > @@ -458,6 +458,8 @@ > >void VisitSwitchStmt(const SwitchStmt *S) { > RecordStmtCount(S); > +if (S->getInit()) > + Visit(S->getInit()); > Visit(S->getCond()); > CurrentCount = 0; > BreakContinueStack.push_back(BreakContinue()); > > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25539: [Coverage] Support for C++17 switch initializers
vsk created this revision. vsk added reviewers: arphaman, ikudrin. vsk added a subscriber: cfe-commits. Generate coverage mappings for in switch (; ). I'm unsure about whether or not the CodeGenPGO change in this patch deserves more testing. https://reviews.llvm.org/D25539 Files: lib/CodeGen/CodeGenPGO.cpp lib/CodeGen/CoverageMappingGen.cpp test/CoverageMapping/switch.c test/CoverageMapping/switch.cpp Index: test/CoverageMapping/switch.cpp === --- test/CoverageMapping/switch.cpp +++ test/CoverageMapping/switch.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.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 switch.cpp %s | FileCheck %s + // CHECK: foo void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 switch(i) { @@ -10,7 +11,7 @@ int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 } -void nop() {} +int nop() { return 0; } // CHECK: bar void bar(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+20]]:2 = #0 @@ -35,8 +36,16 @@ nop();// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #6 } +// CHECK: baz +void baz() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+5]]:2 = #0 + switch (int i = true ? nop() // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = #2 + : nop(); // CHECK-NEXT: [[@LINE]]:26 -> [[@LINE]]:31 = (#0 - #2) + i) {} + nop();// CHECK-NEXT: [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 +} + // CHECK-NEXT: main -int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+34]]:2 = #0 +int main() {// CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE+35]]:2 = #0 int i = 0; switch(i) { case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+7]]:10 = #2 @@ -48,7 +57,7 @@ default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:10 = #4 break; } - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+22]]:2 = #1 + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+23]]:2 = #1 case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+6]]:10 = #6 i = 1; break; @@ -58,16 +67,17 @@ break; } - switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+12]]:2 = #5 + switch(i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+13]]:2 = #5 case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:11 = #10 case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+4]]:11 = (#10 + #11) i = 11; case 3: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = ((#10 + #11) + #12) case 4: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:11 = (((#10 + #11) + #12) + #13) i = 99; } - foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:11 = #9 + foo(1); // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:11 = #9 bar(1); + baz(); return 0; } Index: lib/CodeGen/CoverageMappingGen.cpp === --- lib/CodeGen/CoverageMappingGen.cpp +++ lib/CodeGen/CoverageMappingGen.cpp @@ -813,6 +813,9 @@ void VisitSwitchStmt(const SwitchStmt *S) { extendRegion(S); +if (S->getInit()) + Visit(S->getInit()); + Visit(S->getCond()); BreakContinueStack.push_back(BreakContinue()); Index: lib/CodeGen/CodeGenPGO.cpp === --- lib/CodeGen/CodeGenPGO.cpp +++ lib/CodeGen/CodeGenPGO.cpp @@ -458,6 +458,8 @@ void VisitSwitchStmt(const SwitchStmt *S) { RecordStmtCount(S); +if (S->getInit()) + Visit(S->getInit()); Visit(S->getCond()); CurrentCount = 0; BreakContinueStack.push_back(BreakContinue()); Index: test/CoverageMapping/switch.cpp === --- test/CoverageMapping/switch.cpp +++ test/CoverageMapping/switch.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name switch.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 switch.cpp %s | FileCheck %s + // CHECK: foo void foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+8]]:2 = #0 switch(i) { @@ -10,7 +11,7 @@ int x = 0;// CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:2 = #1 } -void nop() {} +int nop() { return 0; } // CHECK: bar void bar(int i) { // CH