Skip to content

Commit 398ad87

Browse files
committed
[clang][c++20] Fix code coverage mapping crash with generalized NTTPs
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 db7d0ed commit 398ad87

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
@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
21772177
}
21782178

21792179
void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
2180-
Visit(OVE->getSourceExpr());
2180+
if (const Expr *SE = OVE->getSourceExpr())
2181+
Visit(SE);
21812182
}
21822183
};
21832184

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)