D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8854 - incomprehensible bug on windows with import side effect
Summary: incomprehensible bug on windows with import side effect
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-19 11:24 UTC by thelastmammoth
Modified: 2012-12-27 07:56 UTC (History)
2 users (show)

See Also:


Attachments
zip containing all 4 files to reproduce bug (1.35 KB, application/zip)
2012-10-19 11:24 UTC, thelastmammoth
Details

Note You need to log in before you can comment on or make changes to this issue.
Description thelastmammoth 2012-10-19 11:24:45 UTC
Created attachment 1150 [details]
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 Maxim Fomin 2012-10-20 01:11:57 UTC
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 Maxim Fomin 2012-10-20 04:12:53 UTC
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.
Comment 3 Maxim Fomin 2012-12-27 07:56:12 UTC
Fixed in issue 8774