[cfe-dev] Making lambda function name consistent with GCC?

Nathan Sidwell via cfe-dev cfe-dev at lists.llvm.org
Mon May 3 04:10:17 PDT 2021


On 4/30/21 1:52 PM, Fāng-ruì Sòng via cfe-dev wrote:
> Redirect to cfe-dev.
> 
> On Fri, Apr 30, 2021 at 9:42 AM Xun Li via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
>>
>> Hi,
>>
>> I noticed that when compiling lambda functions, the generated function
>> names use different conventions than GCC.
>> Example: https://godbolt.org/z/5qvqKqEe6
>> The lambda in Clang is named "_Z3barIZ3foovE3$_0EvT_", while the one
>> in GCC is named "_Z3barIZ3foovEUlvE_EvT_". Their demangled names are
>> also different ("void bar<foo()::$_0>(foo()::$_0)" vs "void
>> bar<foo()::{lambda()#1}>(foo()::{lambda()#1})").
>> Lambdas are not covered by the ABI so this is OK.

Actually, they are.  See 5.1.8 of the ABI doc 
(https://github.com/itanium-cxx-abi/cxx-abi)

The reason is that these symbols do escape into object files with 
external linkage (not something originally anticipated).

>> However there are use-cases where I find it very inconvenient when
>> they generate different names. For example, if we are to compare the
>> performance difference of the same software compiled under Clang and
>> GCC, the perf stack traces will look very different because of the
>> naming differences, making it hard to compare.
>> Is there any particular reason that Clang uses a different naming
>> convention for lambdas, and would there be push-backs if we were to
>> make it consistent with GCC?

It would be good to have clang match the ABI.  I am not sure how much 
pain it would be for users to switch though -- perhaps having two 
manglings and therefore two distinct instances in the same executable. 
Other than code bloat most would not notice, unless someone put a static 
var into their lambda operator.

>> Thanks.
>>
>> --
>> Xun
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> 


-- 
Nathan Sidwell


More information about the cfe-dev mailing list