https://github.com/akash-manna-sky updated https://github.com/llvm/llvm-project/pull/223121
>From af22f33e3c8a65c4f5a47227b4bccd81cd672329 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Sat, 12 Sep 2026 10:00:22 +0530 Subject: [PATCH 1/4] [clang] Fix mangling of constrained auto referring to a parameter when the return type has an ABI tag When the return type carries an ABI tag, mangleFunctionEncoding first mangles the name with a temporary mangler to collect the tags it uses. The function parameter scope was pushed on the outer mangler after the temporary one had already copied its depth state, so a constraint like C<decltype(t)> on an abbreviated function template saw depth zero and hit the "ParmVarDecl is not visible" assertion. Release builds emitted `fp_` instead of `fL0p_`, a name GCC does not produce. Push the scope on the mangler that does the name mangling instead, as makeFunctionReturnTypeTags already does for its temporary mangler. Fixes #204178 --- clang/docs/ReleaseNotes.md | 6 ++++++ clang/lib/AST/ItaniumMangle.cpp | 8 +++++--- clang/test/CodeGenCXX/mangle-concept.cpp | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 3cca316a91d4d..6d4cff82d13d5 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -676,6 +676,12 @@ features cannot lower the translation-unit ABI level; class with an invalid non-static data member, such as one qualified with an address space. (#GH194605) +- Fixed an assertion when mangling an abbreviated function template whose + constrained `auto` parameter refers to an earlier parameter (e.g. + `template<typename T> auto f(T t, C<decltype(t)> auto) -> S`) and whose + return type has an ABI tag, such as a type declared in an `abi_tag` inline + namespace like `std::string` under libstdc++. (#GH204178) + #### Bug Fixes to AST Handling - Fixed a non-deterministic ordering of unused local typedefs that made diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 298f3efbfa221..1e847dc1a55ce 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -871,9 +871,11 @@ void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) { // Output name of the function. FunctionEncodingMangler.disableDerivedAbiTags(); - FunctionTypeDepthState Saved = FunctionTypeDepth.push(); + // Enter the function parameter scope on the mangler that mangles the name. + FunctionTypeDepthState EncodingSaved = + FunctionEncodingMangler.FunctionTypeDepth.push(); FunctionEncodingMangler.mangleNameWithAbiTags(FD); - FunctionTypeDepth.pop(Saved); + FunctionEncodingMangler.FunctionTypeDepth.pop(EncodingSaved); // Remember length of the function name in the buffer. size_t EncodingPositionStart = FunctionEncodingStream.str().size(); @@ -891,7 +893,7 @@ void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) { AdditionalAbiTags.end()); // Output name with implicit tags and function encoding from temporary buffer. - Saved = FunctionTypeDepth.push(); + FunctionTypeDepthState Saved = FunctionTypeDepth.push(); mangleNameWithAbiTags(FD, AdditionalAbiTags); FunctionTypeDepth.pop(Saved); Out << FunctionEncodingStream.str().substr(EncodingPositionStart); diff --git a/clang/test/CodeGenCXX/mangle-concept.cpp b/clang/test/CodeGenCXX/mangle-concept.cpp index 63e819bb4f8f0..ba900e0cc7522 100644 --- a/clang/test/CodeGenCXX/mangle-concept.cpp +++ b/clang/test/CodeGenCXX/mangle-concept.cpp @@ -245,3 +245,15 @@ namespace gh67356 { // CHECK: define {{.*}} @_ZN7gh673561gIiTkNS_1CIFDTcl1ffL0p_fp_EET_EEEiEEvS3_T0_( template void g(int, int); } + +namespace gh204178 { + // Like gh67356::f, but the return type carries an ABI tag. + inline namespace [[gnu::abi_tag("n")]] n { + class s {}; + } + template<typename, typename> concept c = true; + template<typename T> auto f(T t, c<decltype(t)> auto) -> s; + // CHECK: call {{.*}} @_ZN8gh2041781fIiTkNS_1cIDtfL0p_EEEiEENS_1n1sET_T0_( + // CLANG17: call {{.*}} @_ZN8gh2041781fIiiEENS_1n1sET_T0_( + void g() { f(0, 0); } +} >From d717c9b3b1e7b649e6c6b32c79b183afa259feb4 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Wed, 16 Sep 2026 09:18:15 +0530 Subject: [PATCH 2/4] [clang] Drop unhelpful comment in mangleFunctionEncoding --- clang/lib/AST/ItaniumMangle.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 1e847dc1a55ce..0704c73e86c5e 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -871,7 +871,6 @@ void CXXNameMangler::mangleFunctionEncoding(GlobalDecl GD) { // Output name of the function. FunctionEncodingMangler.disableDerivedAbiTags(); - // Enter the function parameter scope on the mangler that mangles the name. FunctionTypeDepthState EncodingSaved = FunctionEncodingMangler.FunctionTypeDepth.push(); FunctionEncodingMangler.mangleNameWithAbiTags(FD); >From 19bc4ae3f2d04939e6f5c35b24972e3a3699ca46 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Wed, 16 Sep 2026 09:22:16 +0530 Subject: [PATCH 3/4] [clang] Reposition release note --- clang/docs/ReleaseNotes.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 6d4cff82d13d5..537162d8df2fc 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -645,6 +645,12 @@ features cannot lower the translation-unit ABI level; to a subobject and is used in a context that requires an implicit conversion. (#GH215900) +- Fixed an assertion when mangling an abbreviated function template whose + constrained `auto` parameter refers to an earlier parameter (e.g. + `template<typename T> auto f(T t, C<decltype(t)> auto) -> S`) and whose + return type has an ABI tag, such as a type declared in an `abi_tag` inline + namespace like `std::string` under libstdc++. (#GH204178) + - Fixed an assertion during template argument deduction where a function parameter pack is referenced by other types in the function type. (#GH28877), (#GH213760) - Fixed a regression where deprecation warnings were omitted for synthesized @@ -676,12 +682,6 @@ features cannot lower the translation-unit ABI level; class with an invalid non-static data member, such as one qualified with an address space. (#GH194605) -- Fixed an assertion when mangling an abbreviated function template whose - constrained `auto` parameter refers to an earlier parameter (e.g. - `template<typename T> auto f(T t, C<decltype(t)> auto) -> S`) and whose - return type has an ABI tag, such as a type declared in an `abi_tag` inline - namespace like `std::string` under libstdc++. (#GH204178) - #### Bug Fixes to AST Handling - Fixed a non-deterministic ordering of unused local typedefs that made >From 6eef19016fba2984a620188981bc7ad609ed95ff Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Wed, 16 Sep 2026 16:40:20 +0530 Subject: [PATCH 4/4] [clang] Shorten release note --- clang/docs/ReleaseNotes.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 537162d8df2fc..1243ad6523a62 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -646,10 +646,7 @@ features cannot lower the translation-unit ABI level; (#GH215900) - Fixed an assertion when mangling an abbreviated function template whose - constrained `auto` parameter refers to an earlier parameter (e.g. - `template<typename T> auto f(T t, C<decltype(t)> auto) -> S`) and whose - return type has an ABI tag, such as a type declared in an `abi_tag` inline - namespace like `std::string` under libstdc++. (#GH204178) + return type has an ABI tag. (#GH204178) - Fixed an assertion during template argument deduction where a function parameter pack is referenced by other types in the function type. (#GH28877), (#GH213760) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
