Skip to content

Commit

Permalink
[clang][c++20] Fix code coverage mapping crash with generalized NTTPs (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
bolshakov-a authored May 24, 2024
1 parent 2669ee1 commit 6be1a15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CoverageMappingGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2271,7 +2271,8 @@ struct CounterCoverageMappingBuilder
}

void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
Visit(OVE->getSourceExpr());
if (OVE->isUnique())
Visit(OVE->getSourceExpr());
}
};

Expand Down
3 changes: 2 additions & 1 deletion clang/test/CoverageMapping/templates.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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
// 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

template<typename T>
void unused(T x) {
Expand Down Expand Up @@ -30,5 +30,6 @@ namespace structural_value_crash {

void test() {
tpl_fn<arr>();
tpl_fn<&arr[1]>();
}
}

0 comments on commit 6be1a15

Please sign in to comment.