Skip to content

Commit 61abd7b

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 3041001 commit 61abd7b

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
@@ -2187,7 +2187,8 @@ struct CounterCoverageMappingBuilder
21872187
}
21882188

21892189
void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
2190-
Visit(OVE->getSourceExpr());
2190+
if (const Expr *SE = OVE->getSourceExpr())
2191+
Visit(SE);
21912192
}
21922193
};
21932194

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)