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
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 committed Mar 20, 2024
1 parent db7d0ed commit 398ad87
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 @@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
}

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

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 398ad87

Please sign in to comment.