Comment #0 by thelastmammoth — 2012-10-19T11:24:45Z
Created attachment 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);
}
--------------------
Comment #1 by maxim — 2012-10-20T01:11:57Z
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.
Comment #2 by maxim — 2012-10-20T04:12:53Z
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.