www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3029] New: Bug in array value mangling rule

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029

           Summary: Bug in array value mangling rule
           Product: D
           Version: 2.030
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: spec, wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: rsinfu gmail.com


This valid code:
--------------------
module test;
import std.stdio;
struct S(alias init)
{
    int[] content = init;
}
void main()
{
    S!([12, 3]) s1;
    S!([1, 23]) s2;
    writeln(s1.content);
    writeln(s2.content);
}
--------------------
prints wrong values:
--------------------
12 3
12 3
--------------------
The second line should be "1 23", not "12 3".

That is caused by a bug in the current array value mangling rule:
--------------------
Value:
    A Number Value...
--------------------
Under this rule, both S!([12, 3]) and S!([1, 23]) get mangled to the same name
"S4test15__T1SVG2iA2123Z". (Name collision!!!)

There should be delimiters in Values. For example:
--------------------
Value:
    A Number Values

Values:
    Value
    Value _ Values
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029





--- Comment #1 from Shin Fujishiro <rsinfu gmail.com>  2009-05-27 05:54:04 PDT
---
Struct literals and associative array literals have the same bug too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029





--- Comment #2 from Shin Fujishiro <rsinfu gmail.com>  2009-06-06 09:07:02 PDT
---
Another (possibly better) option is to fix the numeric literal mangling rule as
this:
--------------------
Value:
    i Number        // positive numeric literal
    i N Number      // negative numeric literal
--------------------
The prefix 'i' avoids the mangled-name collision. And this rule is consistent
with other literal mangling rules, which are prefixed by some character (e.g.
'e' for floating point literals).

Patch (expression.c):
--------------------
 void IntegerExp::toMangleBuffer(OutBuffer *buf)
 {
     if ((sinteger_t)value < 0)
-    buf->printf("N%jd", -value);
+    buf->printf("iN%jd", -value);
     else
-    buf->printf("%jd", value);
+    buf->printf("i%jd", value);
 }
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2010-02-05
19:27:30 PST ---
changeset 370

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr puremagic.com


--- Comment #4 from Brad Roberts <braddr puremagic.com> 2010-02-05 19:33:46 PST
---
Why keep the backwards compatibility in D2?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029



--- Comment #5 from Don <clugdbug yahoo.com.au> 2010-02-05 22:09:00 PST ---
(In reply to comment #4)
 Why keep the backwards compatibility in D2?

Yes. With things like the recent change to ModuleInfo, you can't even update the compiler one revision without recompiling. So I don't think we have to worry about D2 backwards compatibility for the next month (which is why it's crucial to get these types of bugs fixed now). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029


Kosmonaut <Kosmonaut tempinbox.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Kosmonaut tempinbox.com


--- Comment #6 from Kosmonaut <Kosmonaut tempinbox.com> 2010-02-05 23:41:50 PST
---
(In reply to comment #3)
 changeset 370

http://www.dsource.org/projects/dmd/changeset/370 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3029


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2010-03-08
22:19:22 PST ---
Fixed dmd 1.057 and 2.041

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2010