Skip to content

Commit 6be1a15

Browse files
authored
[clang][c++20] Fix code coverage mapping crash with generalized NTTPs (#85837)
Introduced in #78041, originally reported as #79957 and fixed partially in #80050. `OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no corresponding source expression. A test case with subobject-referring NTTP added.
1 parent 2669ee1 commit 6be1a15

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,8 @@ struct CounterCoverageMappingBuilder
22712271
}
22722272

22732273
void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
2274-
Visit(OVE->getSourceExpr());
2274+
if (OVE->isUnique())
2275+
Visit(OVE->getSourceExpr());
22752276
}
22762277
};
22772278

clang/test/CoverageMapping/templates.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
1+
// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
22

33
template<typename T>
44
void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
3030

3131
void test() {
3232
tpl_fn<arr>();
33+
tpl_fn<&arr[1]>();
3334
}
3435
}

0 commit comments

Comments
 (0)