[clang] 5ff6c65 - [Coverage] Handle array decomposition correctly (#88881)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 15 15:40:06 PDT 2024
Author: Andrey Ali Khan Bolshakov
Date: 2024-05-15T15:40:03-07:00
New Revision: 5ff6c6542ac451daaed6c417e481e313165d3454
URL: https://github.com/llvm/llvm-project/commit/5ff6c6542ac451daaed6c417e481e313165d3454
DIFF: https://github.com/llvm/llvm-project/commit/5ff6c6542ac451daaed6c417e481e313165d3454.diff
LOG: [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.
Added:
clang/test/CoverageMapping/decomposition.cpp
Modified:
clang/lib/CodeGen/CoverageMappingGen.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index e46560029ab08..cc8ab7a5b4369 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2177,6 +2177,10 @@ struct CounterCoverageMappingBuilder
// propagate counts into them.
}
+ void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
+ Visit(AILE->getCommonExpr()->getSourceExpr());
+ }
+
void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
// Just visit syntatic expression as this is what users actually write.
VisitStmt(POE->getSyntacticForm());
diff --git a/clang/test/CoverageMapping/decomposition.cpp b/clang/test/CoverageMapping/decomposition.cpp
new file mode 100644
index 0000000000000..601ea630faeec
--- /dev/null
+++ b/clang/test/CoverageMapping/decomposition.cpp
@@ -0,0 +1,15 @@
+// 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
+
+// CHECK-LABEL: _Z19array_decompositioni:
+// CHECK-NEXT: File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT: File 0, [[@LINE+8]]:20 -> [[@LINE+8]]:25 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+7]]:20 -> [[@LINE+7]]:25 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE+6]]:27 -> [[@LINE+6]]:28 = #1
+// CHECK-NEXT: File 0, [[@LINE+5]]:28 -> [[@LINE+5]]:29 = #1
+// CHECK-NEXT: File 0, [[@LINE+4]]:32 -> [[@LINE+4]]:33 = (#0 - #1)
+int array_decomposition(int i) {
+ int a[] = {1, 2, 3};
+ int b[] = {4, 5, 6};
+ auto [x, y, z] = i > 0 ? a : b;
+ return x + y + z;
+}
More information about the cfe-commits
mailing list