clang: Remap lambda paths in declaration template arguments
PATCH 1/1 clang: Remap lambda paths in declaration template arguments
clang printed the declaration of a declaration template argument (e.g. a pointer to member) without the caller's printing policy, so -ffile-prefix-map/-fdebug-prefix-map were not applied to lambdas named in it. Their full source path then ended up in DWARF names, e.g. in grpc built with clang:
WARNING: grpc-1.84.1-r0 do_package_qa: QA Issue: File /usr/lib/.debug/libgrpc.so.56.0.0 in package grpc-dbg contains reference to TMPDIR [buildpaths]
from "AddOp<&ClientInitialMetadataInterceptor<(lambda at /abs/...)>::...>".
Pass the policy through.
Signed-off-by Khem Raj <[email protected]>
--- ...printing-policy-for-declaration-temp.patch | 63 +++++++++++++++++++ meta/recipes-devtools/clang/common.inc | 1 + 2 files changed, 64 insertions(+) create mode 100644 meta/recipes-devtools/clang/clang/0036-clang-Honor-the-printing-policy-for-declaration-temp.patch
meta/recipes-devtools/clang/clang/0036-clang-Honor-the-printing-policy-for-declaration-temp.patch new file +63 -0
@@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Tue, 27 Oct 2026 13:05:20 -0700 +Subject: [PATCH] [clang] Honor the printing policy for declaration template + arguments + +TemplateArgument::print printed the declaration of a Declaration +argument with printQualifiedName(Out), which falls back to the +ASTContext's default printing policy and drops the caller's. Among +other things this loses the policy's Callbacks, so -fdebug-prefix-map +and -ffile-prefix-map are not applied to lambdas named in such an +argument, e.g. + + template <typename T> struct S { void m() {} }; + template <auto P> void d() {} + void e() { auto l = [] {}; d<&S<decltype(l)>::m>(); } + +emits "d<&S<(lambda at /abs/path/t.cc:3:21)>::m>" as the DWARF name of +the d instantiation, while the same lambda is remapped everywhere else. +This leaks build paths into otherwise reproducible debug info. + +Pass the policy through to printQualifiedName. + +Upstream-Status: Submitted [https://github.com/llvm/llvm-project/pull/236240] +Signed-off-by: Khem Raj <[email protected]> +--- + clang/lib/AST/TemplateBase.cpp | 2 +- + clang/test/DebugInfo/CXX/prefix-map-lambda.cpp | 12 ++++++++++++ + 2 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp +index a5e0dde..13d7698 100644 +--- a/clang/lib/AST/TemplateBase.cpp ++++ b/clang/lib/AST/TemplateBase.cpp +@@ -543,7 +543,7 @@ void TemplateArgument::print(const PrintingPolicy &Policy, raw_ostream &Out, + } + if (needsAmpersandOnTemplateArg(getParamTypeForDecl(), VD->getType())) + Out << "&"; +- VD->printQualifiedName(Out); ++ VD->printQualifiedName(Out, Policy); + break; + } + +diff --git a/clang/test/DebugInfo/CXX/prefix-map-lambda.cpp b/clang/test/DebugInfo/CXX/prefix-map-lambda.cpp +index f0fb1a3..962bbc0 100644 +--- a/clang/test/DebugInfo/CXX/prefix-map-lambda.cpp ++++ b/clang/test/DebugInfo/CXX/prefix-map-lambda.cpp +@@ -8,3 +8,15 @@ void c() { + // CHECK-SAME: [[@LINE+1]]:{{[0-9]+}})>" + b([]{}); + } ++ ++// The lambda in a declaration template argument (here a pointer to member) ++// must be remapped as well. ++template <typename T> struct S { void m() {} }; ++template <auto P> void d() {} ++void e() { ++ auto l = [] {}; ++ // CHECK: !DISubprogram(name: "d<&S<(lambda at ++ // CHECK-SAME: SOURCE_ROOT ++ // CHECK-SAME: [[@LINE-3]]:{{[0-9]+}})>::m>" ++ d<&S<decltype(l)>::m>(); ++}
meta/recipes-devtools/clang/common.inc +1 -0
@@ -55,6 +55,7 @@ SRC_URI = "\ file://0033-Consolidate-and-fix-sysroot-based-compiler-rt-search.patch \ file://0034-clang-tools-extra-Add-separate-CLANG_TOOLS_EXTRA_INC.patch \ file://0035-PEI-Call-insertZeroCallUsedRegs-after-materializing-.patch \ + file://0036-clang-Honor-the-printing-policy-for-declaration-temp.patch \ " # Fallback to no-PIE if not set GCCPIE ??= ""