Skip to content

Commit 5ff6c65

Browse files
authored
[Coverage] Handle array decomposition correctly (#88881)
`ArrayInitLoopExpr` AST node has two occurences of its as-written initializing expression in its subexpressions through a non-unique `OpaqueValueExpr`. It causes double-visiting of the initializing expression if not handled explicitly, as discussed in #85837.
1 parent 050593f commit 5ff6c65

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,10 @@ struct CounterCoverageMappingBuilder
21772177
// propagate counts into them.
21782178
}
21792179

2180+
void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
2181+
Visit(AILE->getCommonExpr()->getSourceExpr());
2182+
}
2183+
21802184
void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
21812185
// Just visit syntatic expression as this is what users actually write.
21822186
VisitStmt(POE->getSyntacticForm());
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple %itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
2+
3+
// CHECK-LABEL: _Z19array_decompositioni:
4+
// CHECK-NEXT: File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
5+
// CHECK-NEXT: File 0, [[@LINE+8]]:20 -> [[@LINE+8]]:25 = #0
6+
// CHECK-NEXT: Branch,File 0, [[@LINE+7]]:20 -> [[@LINE+7]]:25 = #1, (#0 - #1)
7+
// CHECK-NEXT: Gap,File 0, [[@LINE+6]]:27 -> [[@LINE+6]]:28 = #1
8+
// CHECK-NEXT: File 0, [[@LINE+5]]:28 -> [[@LINE+5]]:29 = #1
9+
// CHECK-NEXT: File 0, [[@LINE+4]]:32 -> [[@LINE+4]]:33 = (#0 - #1)
10+
int array_decomposition(int i) {
11+
int a[] = {1, 2, 3};
12+
int b[] = {4, 5, 6};
13+
auto [x, y, z] = i > 0 ? a : b;
14+
return x + y + z;
15+
}

0 commit comments

Comments
 (0)