https://github.com/bolshakov-a updated https://github.com/llvm/llvm-project/pull/85837
>From 61abd7b6089ecb87eaf6886e251969d4db87e223 Mon Sep 17 00:00:00 2001 From: Bolshakov <bolsh.and...@yandex.ru> Date: Tue, 19 Mar 2024 19:05:36 +0300 Subject: [PATCH 1/2] [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. --- clang/lib/CodeGen/CoverageMappingGen.cpp | 3 ++- clang/test/CoverageMapping/templates.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index cc8ab7a5b4369..48896fa03d9ff 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2187,7 +2187,8 @@ struct CounterCoverageMappingBuilder } void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) { - Visit(OVE->getSourceExpr()); + if (const Expr *SE = OVE->getSourceExpr()) + Visit(SE); } }; diff --git a/clang/test/CoverageMapping/templates.cpp b/clang/test/CoverageMapping/templates.cpp index 143e566a33cb8..7e7f2208f1145 100644 --- a/clang/test/CoverageMapping/templates.cpp +++ b/clang/test/CoverageMapping/templates.cpp @@ -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) { @@ -30,5 +30,6 @@ namespace structural_value_crash { void test() { tpl_fn<arr>(); + tpl_fn<&arr[1]>(); } } >From 9684fed244607e3c7923c0a3118945c559e2d5d5 Mon Sep 17 00:00:00 2001 From: Bolshakov <bolsh.and...@yandex.ru> Date: Thu, 16 May 2024 12:18:17 +0300 Subject: [PATCH 2/2] Fix up: check `isUnique` instead of source expr presence --- clang/lib/CodeGen/CoverageMappingGen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index 48896fa03d9ff..5f62d2ae46bdb 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2187,8 +2187,8 @@ struct CounterCoverageMappingBuilder } void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) { - if (const Expr *SE = OVE->getSourceExpr()) - Visit(SE); + if (OVE->isUnique()) + Visit(OVE->getSourceExpr()); } }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits