Typical example:
module test;
void main()
{
{ int x; pragma(msg, x.mangleof); } // _D4test4mainFZ1xi
{ int x; pragma(msg, x.mangleof); } // _D4test4mainFZ1xi
}
Even if two or more different function local symbols have same name, their mangled name should be unique.
---
Currently the mangling issue causes many pragmatic problems.
https://issues.dlang.org/show_bug.cgi?id=10619
If the same name symbols are captured by TemplateAliasParameter, the corresponding template instances will be entangled.
https://issues.dlang.org/show_bug.cgi?id=14820
If the symbols declared in unrolled loop (compile-time iterated foreach) statement, they're easily entangled.
https://issues.dlang.org/show_bug.cgi?id=9748
The problem is not only for variables, but also function local templates and template functions.
---
Currently function local functions, type definitions, and static variables are not allowed.
module test;
void main()
{
{ void f() {} pragma(msg, f.mangleof); }
{ void f() {} pragma(msg, f.mangleof); } // error
{ struct S {} pragma(msg, S.mangleof); }
{ struct S {} pragma(msg, S.mangleof); } // ICE
{ class C {} pragma(msg, C.mangleof); }
{ class C {} pragma(msg, C.mangleof); } // ICE
{ enum E { a } pragma(msg, E.mangleof); }
{ enum E { a } pragma(msg, E.mangleof); } // error
{ static int v = 0; pragma(msg, v.mangleof); }
{ static int v = 1; pragma(msg, v.mangleof); } // error
}
However, I think the rejections are not so meaningful. I cannot see any reason to limit such the static function local symbols to unique.
(In reply to Kenji Hara from comment #0)
> Currently function local functions, type definitions, and static variables
> are not allowed.
>
[snip]
>
> However, I think the rejections are not so meaningful. I cannot see any
> reason to limit such the static function local symbols to unique.
I'll separate that suggestion into the issue 3031
Comment #3 by k.hara.pg — 2015-07-27T13:14:52Z
*** Issue 10619 has been marked as a duplicate of this issue. ***
Comment #4 by k.hara.pg — 2015-07-27T13:14:54Z
*** Issue 14820 has been marked as a duplicate of this issue. ***
Comment #5 by k.hara.pg — 2015-07-27T13:16:34Z
*** Issue 9748 has been marked as a duplicate of this issue. ***
Comment #6 by dlang-bugzilla — 2016-10-22T16:41:26Z
*** Issue 16608 has been marked as a duplicate of this issue. ***
Comment #8 by moonlightsentinel — 2021-02-26T14:58:15Z
Test case compiles and reports unique manglings.
Tested with DMD64 D Compiler v2.095.1-beta.1-171-gdf3c9e093
Comment #9 by hsteoh — 2021-02-26T19:10:10Z
Test case still produces two identical manglings on DMD git master (7a0382177f35b2766c2d0ba60dae5e541d8033e0):
Output of OP's test case:
-------
_D4test4mainFZ1xi
_D4test4mainFZ1xi
-------
This is wrong because `x` in each case refers to a different local variable in a different scope.
Comment #10 by hsteoh — 2021-02-26T19:14:25Z
Furthermore, all the test cases posted in issue #10619 still fail on DMD git master.
Comment #11 by moonlightsentinel — 2021-02-26T22:25:05Z
(In reply to hsteoh from comment #9)
> Test case still produces two identical manglings on DMD git master
> (7a0382177f35b2766c2d0ba60dae5e541d8033e0):
Sorry, missed the first example.
Comment #12 by dlang-bot — 2021-02-27T00:08:14Z
@MoonlightSentinel updated dlang/dmd pull request #12235 "Fix 14831 - Each function local symbols should have unique mangled name" fixing this issue:
- Fix 14831 - Each function local symbols should have unique mangled name
PR #12119 already fixed collisions for several declarations but missed
local variables.
The check for `isDataSeg` was a remnant of the old error raised for
`static`/`__gshared` variables. Removing it enables the mangling fixup
for local variables.
Note that this doesn't fix https://issues.dlang.org/show_bug.cgi?id=10619
which is unrelated to the mangling.
https://github.com/dlang/dmd/pull/12235
Comment #13 by dlang-bot — 2021-03-01T11:42:49Z
dlang/dmd pull request #12235 "Fix 14831 - Each function local symbols should have unique mangled name" was merged into stable:
- 1d2b5ec75d3bad4f33ccacdf5fe4913d2b512a47 by MoonlightSentinel:
Fix 14831 - Each function local symbols should have unique mangled name
PR #12119 already fixed collisions for several declarations but missed
local variables.
The check for `isDataSeg` was a remnant of the old error raised for
`static`/`__gshared` variables. Removing it enables the mangling fixup
for local variables.
Note that this doesn't fix https://issues.dlang.org/show_bug.cgi?id=10619
which is unrelated to the mangling.
https://github.com/dlang/dmd/pull/12235
Comment #14 by dlang-bot — 2021-03-06T03:40:52Z
dlang/dmd pull request #12253 "merge stable" was merged into master:
- 8b653c5629b930fe8bf956b4be109781f67cb59a by MoonlightSentinel:
Fix 14831 - Each function local symbols should have unique mangled name
PR #12119 already fixed collisions for several declarations but missed
local variables.
The check for `isDataSeg` was a remnant of the old error raised for
`static`/`__gshared` variables. Removing it enables the mangling fixup
for local variables.
Note that this doesn't fix https://issues.dlang.org/show_bug.cgi?id=10619
which is unrelated to the mangling.
https://github.com/dlang/dmd/pull/12253
Comment #15 by pro.mathias.lang — 2021-07-19T00:24:49Z
*** Issue 19674 has been marked as a duplicate of this issue. ***