https://github.com/bolshakov-a created https://github.com/llvm/llvm-project/pull/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. @erichkeane, @cor3ntin, @Endilll >From ec923eedb0b43050e7ce5e6648711a12adb1cebe Mon Sep 17 00:00:00 2001 From: Bolshakov <bolsh.and...@yandex.ru> Date: Tue, 19 Mar 2024 19:05:36 +0300 Subject: [PATCH] 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 71215da362d3d0..3a87f935470673 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2177,7 +2177,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 143e566a33cb85..7e7f2208f1145f 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]>(); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits