Thread overview
[Issue 9539] New: Regression (2.061): Wrong-code on static array pointer
Feb 19, 2013
Andrej Mitrovic
Feb 21, 2013
Kenji Hara
Feb 21, 2013
Kenji Hara
[Issue 9539] Wrong implicit conversion of array to pointer
Feb 22, 2013
Kenji Hara
Mar 01, 2013
Andrej Mitrovic
Apr 11, 2013
Kenji Hara
Apr 11, 2013
Kenji Hara
May 13, 2013
Andrej Mitrovic
February 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539

           Summary: Regression (2.061): Wrong-code on static array pointer
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-19 14:13:47 PST ---
void f(int** ptr)
{
    assert(**ptr == 10);
}

void main()
{
    int* i = new int;
    *i = 10;
    int*[1] x = [i];
    f(&x[0]);
}

2.060:
$ dmd test.d
> 

2.061
$ dmd test.d
> core.exception.AssertError@test(5): Assertion failure

2.062
$ dmd test.d
> core.exception.AssertError@test(5): Assertion failure

Same thing happens when you use 'x.ptr'.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539



--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2013-02-20 23:48:00 PST ---
(In reply to comment #0)
> void f(int** ptr)
> {
>     assert(**ptr == 10);
> }
> 
> void main()
> {
>     int* i = new int;
>     *i = 10;
>     int*[1] x = [i];
>     f(&x[0]);
> }

More simple case:

    int*[1] x;
    int* p = new int;
    x = [p];    // is wrongly rewritten to: x[] = [p].ptr
    printf("p = %p, x[0] = %p\n", p, x[0]);
    assert(p == x[0]);  // fails!?

----

This is horribly serious problem.

The root issue is in TypeDArray::implicitConvTo. FROM THE BEGINNING of D2, an implicit conversion from dynamic array to its element pointer type as a deprecated feature.

    int[] arr;  int* p;
    p = arr;  // is expected to rewrite to p = arr.ptr

BUT, it was completely broken FROM THE BEGINNING of D2. Instead of the expected behavior, dynamic array can be convertible to its element type.

    int*[] arr = [null];
    int* p;
    p = arr;    // bad!
    printf("p = %p, arr.ptr = %p\n", p, arr.ptr);

It has been wrongly accepted in long time if '-d' switch is specified. Then, from 2.061, the situation has become worse by "informational deprecated error in default". Above code would be _silently_ accepted in default, and compiler outputs wrong-code.

----

But, we cannot *fix* TypeDArray::implicitConvTo to implement the deprecated feature, because it breaks phobos building.

In std.process line 367:
    scope(exit) if (exists(filename)) remove(filename);   // <----

Today, it calls std.file.remove in here.

std.stdio.file line 413:
    void remove(in char[] name)

But std.process also imports core.stdc.stdio through std.stdio. In there another 'remove' is defined.

core.stdc.stdio line 453:
    int remove(in char* filename);   // <----

After *fixing* the deprecated feature, the 'remove' call in std.process will match both 'remove's that defined in different modules, and it will raise an error according to overload set resolution rule.

std\process.d(367): Error: std.file.remove at std\file.d(413) conflicts with
core.stdc.stdio.remove at
C:\Users\khara\dmd2\src\druntime\import\core\stdc\stdio.d(453)

----

So as a conclusion, we should just remove the deprecated "array to pointer conversion" feature, rather than fixing broken deprecated feature that already outdated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 21, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2013-02-21 00:10:20 PST ---
https://github.com/D-Programming-Language/dmd/pull/1679

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539



--- Comment #3 from github-bugzilla@puremagic.com 2013-02-21 16:47:54 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/beee8e88c4bdff61087cd34353481e7c364690d3 fix Issue 9539 - Regression (2.061): Wrong-code on static array pointer

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #4 from bearophile_hugs@eml.cc 2013-02-21 18:22:08 PST ---
From the commit:

> the deprecated implicit conversion feature already being a cancer in D2 type system.

Thank you Hara for fixing such things. Implicit type conversions are dangerous.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


Kenji Hara <k.hara.pg@gmail.com> changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-03-01 13:19:34 PST ---
Another person has ran into this recently.

Shouldn't this be a good reason for an emergency release of a patched 2.062? It's really an awful bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |entheh@cantab.net


--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-10 22:01:32 PDT ---
*** Issue 9518 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


Kenji Hara <k.hara.pg@gmail.com> changed:

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


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-11 01:54:36 PDT ---
*** Issue 9916 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 13, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9539


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

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


--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-05-13 06:51:28 PDT ---
*** Issue 10072 has been marked as a duplicate of this issue. ***

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