Thread overview
[Issue 3029] New: Bug in array value mangling rule
May 27, 2009
rsinfu@gmail.com
May 27, 2009
Shin Fujishiro
Jun 06, 2009
Shin Fujishiro
Feb 06, 2010
Walter Bright
Feb 06, 2010
Brad Roberts
Feb 06, 2010
Don
Feb 06, 2010
Kosmonaut
Mar 09, 2010
Walter Bright
Feb 21, 2012
yebblies
May 27, 2009
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
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: -------
June 06, 2009
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: -------
February 06, 2010
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: -------
February 06, 2010
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: -------
February 06, 2010
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: -------
February 06, 2010
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: -------
March 09, 2010
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: -------
February 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3029


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #8 from yebblies <yebblies@gmail.com> 2012-02-22 02:18:23 EST ---
What happened here?  Are we really maintaining backwards compatibility in only the cases that _weren't_ buggy?  What legacy compiled code base is this supposed to be supporting?

I seriously doubt anyone expects to be able to use a new version of dmd without recompiling their code at this point.

See expression.c:2128

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