Bug 464969

Summary: D language demangling
Product: [Developer tools] valgrind Reporter: Witold Baryluk <witold.baryluk>
Component: generalAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: mark, pjfloyd, witold.baryluk
Priority: NOR Keywords: usability
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: d-lang-demangling.patch

Description Witold Baryluk 2023-01-29 03:10:45 UTC
Created attachment 155749 [details]
d-lang-demangling.patch

See patch.

Related to bug #445235
Comment 1 Paul Floyd 2023-01-29 07:22:23 UTC
Where is dlang_demangle ? It looks external to me.
Comment 2 Mark Wielaard 2023-01-29 13:19:06 UTC
coregrind/m_demangle/d-demangle.c provides dlang_demangle it comes from libiberty from which we import the demangler from time to time. See auxprogs/update-demangler. Last import was:

commit e0b62fe05559003b731b4d786f3b71e9a66fb94d
Author: Mark Wielaard <mark@klomp.org>
Date:   Thu Feb 17 18:35:38 2022 +0100

    Update libiberty demangler
    
    Update the libiberty demangler using the auxprogs/update-demangler
    script to gcc git commit d3b2ead595467166c849950ecd3710501a5094d9.
    
    This update includes:
    
    - libiberty rust-demangle, ignore .suffix
    - libiberty: Fix infinite recursion in rust demangler
    - Update copyright years
    - libiberty: support digits in cpp mangled clone names
    - d-demangle: properly skip anonymous symbols
    - d-demangle: remove parenthesis where it is not needed
Comment 3 Paul Floyd 2023-01-29 14:40:31 UTC
OK that reminds me of https://bugs.kde.org/show_bug.cgi?id=445235

IIRC we don't want the build/tests to rely on having all compilers avalable so to test the trick is to use a C program using D mangled symbols.
Comment 4 Paul Floyd 2023-01-29 15:25:35 UTC
And the other bugzi was already mentioned.
Comment 5 Paul Floyd 2023-01-29 15:43:35 UTC
Very quick test, I used one of the functions here:

https://dlang.org/blog/2017/12/20/ds-newfangled-name-mangling/

To write

#include <iostream>

extern "C" void _D4test4findFiPxaZPxa()
{
   int a;
   if (a)
      std::cout << "a\n";
   else
      std::cout << "!a\n";
}

int main()
{
   _D4test4findFiPxaZPxa();
}

Without the patch

==4757== Conditional jump or move depends on uninitialised value(s)
==4757==    at 0x2025FC: _D4test4findFiPxaZPxa (d.cpp:6)

With the patch

==4760== Conditional jump or move depends on uninitialised value(s)
==4760==    at 0x2025FC: test.find(int, const(char)*) (d.cpp:6)
Comment 6 Witold Baryluk 2023-01-29 20:06:08 UTC
Yes. "_D4test4findFiPxaZPxa" , is mangling for "test.find(int, const(char)*)", or for "const(char)* find(int, const(char)*)" if one also includes the return type.

Thanks for adding a test.
Comment 7 Paul Floyd 2023-01-29 21:08:56 UTC
commit 82282a6676a5c1b3784fd22fc097a0076dfcb7ca (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Sun Jan 29 22:05:27 2023 +0100

    Bug 464969 -  D language demangling
    
        Patch from witold.baryluk@gmail.com
    
    (also added a testcase)