Thread overview
[Issue 8854] New: incomprehensible bug on windows with import side effect
Oct 20, 2012
Maxim Fomin
Oct 20, 2012
Maxim Fomin
Dec 27, 2012
Maxim Fomin
October 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8854

           Summary: incomprehensible bug on windows with import side
                    effect
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: thelastmammoth@gmail.com


--- Comment #0 from thelastmammoth@gmail.com 2012-10-19 11:24:45 PDT ---
Created an attachment (id=1150)
zip containing all 4 files to reproduce bug

I've attached a set of 4 files I've simplified as much as I could. This gives rise to a very weird bug (only on windows 32 bits). Here's the contents of the readme:

steps to reproduce bug:
----
cd to directory containing this readme
rdmd --force -I.\tests main
----
note:
dmd -I.\tests main main_aux1 tests/main_testfun and then running main still has
the bug

note:
any of the following changes will remove the bug (ie the assert will pass):

rename tests/main_testfun to tests/main_aux2 (or probably other stuff) and
reflecting this in main_testfun.d and the import statement in main.d)
rename directory tests to test123 (or something else) and reflecting this in
the -I flag
remove the (useless) import main_aux1; in main_testfun.d
remove the (useless) import std.stdio in main_aux1.d
replace assert([0].map!(a=>b.length)[0]==1); by assert(b.length==1); in
main_testfun.d




├── main.d
├── main_aux1.d
├── readme.txt
└── tests
    └── main_testfun.d

--------------------
contents of each file:

cat main.d

                              --------------------
import main_testfun;
void main(){
    testfun;
}
--------------------

cat main_aux1.d

                              --------------------
module main_aux1;
import std.stdio;//works wo this
--------------------

cat tests/main_testfun.d

                              --------------------
module main_testfun;
import main_aux1;
import std.algorithm:map;

void testfun(){
    auto b=[1];
    assert([0].map!(a=>b.length)[0]==1);
}
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8854


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-10-20 01:11:57 PDT ---
This happens in linux too with both options -m32 and -m64 (dmd 2.060). Also if
dummy import of std.stdio is changed to other module (eg. bigint) the bug still
happens.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8854



--- Comment #2 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-10-20 04:12:53 PDT ---
Forgot to mention - I cannot reproduce bug related to naming files and directories.

Comparing disassembles of testfunc shows that they are same, except __lamda2.

Buggy version (presence of dummy import) boils down to following asm:

0x0000000000419b84 <+0>:    push   %rbp
0x0000000000419b85 <+1>:    mov    %rsp,%rbp
0x0000000000419b88 <+4>:    sub    $0x10,%rsp
0x0000000000419b8c <+8>:    mov    (%rdi),%rax
0x0000000000419b8f <+11>:    leaveq
0x0000000000419b90 <+12>:    retq

However, in correct version of program without dummy import asm is:

0x0000000000419c68 <+0>:    push   %rbp
0x0000000000419c69 <+1>:    mov    %rsp,%rbp
0x0000000000419c6c <+4>:    sub    $0x10,%rsp
0x0000000000419c70 <+8>:    mov    -0x30(%rdi),%rax
0x0000000000419c74 <+12>:    leaveq
0x0000000000419c75 <+13>:    retq

It seems that importing some code changes size of type.

In everything else assemblies look similar, except in changes of relatives
addresses (binaries are of different sizes.) May be worth mentioning that
running two version shows that differences started at calling opIndex of
MapStruct
(https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L438).
In buggy version index=42_998_32, in correct version index=42_982_32. Both
function return same value.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8854


Maxim Fomin <maxim@maxim-fomin.ru> changed:

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


--- Comment #3 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-12-27 07:56:12 PST ---
Fixed in issue 8774

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