www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiler bug?

reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
I think I found a bug in the compiler.  This bug seems to have affected the 
two versions I tried of dmd (1.024 and 1.033), so it's been in there a 
while.

However, it's a very weird bug.

I have a function that looks like this (for those who are interested, this 
is from tango.io.Path):

Time modified (char[] name)
{
        return timeStamps(name).modified;
}

the timeStamps function returns a collection of 3 Time structs, which 
indicate the modified, created, and accessed time for a file named 'name'.

However, the result is corrupt.  I know this because I'm printing the time 
in the timeStamps function, and it is different than the time returned.

In examining the entire flow of the code, I can find nothing wrong.

This only happens with the -inline switch of dmd.

If I rewrite the function in the following way, the problem goes away(!):

Time modified (char[] name)
{
  auto ts = timeStamps(name);
        return ts.modified;
}

Now, I wanted to create a minimal case (without all of Tango that this 
program uses), but I'm having difficulty.  So I wanted to inspect the 
assembly, but I'm on windows, and there is no obj2asm in the dmd directory. 
So I can't figure out what the compiler is doing differently.  I'm not sure 
where to begin.  Walter, is this enough info for you to look into this?  I 
can send you the object file and source file if you want to see how dmd 
generated the code.

-Steve 
Jul 16 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Steven Schveighoffer" <schveiguy yahoo.com> wrote in message 
news:g5l4s4$1285$1 digitalmars.com...
I think I found a bug in the compiler.  This bug seems to have affected the 
two versions I tried of dmd (1.024 and 1.033), so it's been in there a 
while.

 However, it's a very weird bug.

 I have a function that looks like this (for those who are interested, this 
 is from tango.io.Path):

 Time modified (char[] name)
 {
        return timeStamps(name).modified;
 }

 the timeStamps function returns a collection of 3 Time structs, which 
 indicate the modified, created, and accessed time for a file named 'name'.

 However, the result is corrupt.  I know this because I'm printing the time 
 in the timeStamps function, and it is different than the time returned.

 In examining the entire flow of the code, I can find nothing wrong.

 This only happens with the -inline switch of dmd.

 If I rewrite the function in the following way, the problem goes away(!):

 Time modified (char[] name)
 {
  auto ts = timeStamps(name);
        return ts.modified;
 }

 Now, I wanted to create a minimal case (without all of Tango that this 
 program uses), but I'm having difficulty.  So I wanted to inspect the 
 assembly, but I'm on windows, and there is no obj2asm in the dmd 
 directory. So I can't figure out what the compiler is doing differently. 
 I'm not sure where to begin.  Walter, is this enough info for you to look 
 into this?  I can send you the object file and source file if you want to 
 see how dmd generated the code.

You have to buy the EUP to get the windows version of obj2asm, lol. Another way to disassemble is to compile in debug info with -g, and step through in a debugger, like WinDbg (shudder), ddbg (OK), or VS6 (yay). I'm not sure how -g behaves with -inline though. But if it makes you feel any better (?), this is definitely a bug. -inline should *never* change the behavior of code. Bugzilla it if it hasn't been already.
Jul 16 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:g5lha8$20s2$1 digitalmars.com...

 You have to buy the EUP to get the windows version of obj2asm, lol.

Another option might be the OpenWatcom disassembler tool, now that I think about it. http://www.openwatcom.org/index.php/Main_Page I'm almost certain the linker works with OMF, so the disassembler should be able to disassemble the objects that DMD produces.
Jul 16 2008
prev sibling next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Jarrett Billingsley"wrote
 "Steven Schveighoffer" wrote
I think I found a bug in the compiler.  This bug seems to have affected 
the two versions I tried of dmd (1.024 and 1.033), so it's been in there a 
while.

 However, it's a very weird bug.

 I have a function that looks like this (for those who are interested, 
 this is from tango.io.Path):

 Time modified (char[] name)
 {
        return timeStamps(name).modified;
 }

 the timeStamps function returns a collection of 3 Time structs, which 
 indicate the modified, created, and accessed time for a file named 
 'name'.

 However, the result is corrupt.  I know this because I'm printing the 
 time in the timeStamps function, and it is different than the time 
 returned.

 In examining the entire flow of the code, I can find nothing wrong.

 This only happens with the -inline switch of dmd.

 If I rewrite the function in the following way, the problem goes away(!):

 Time modified (char[] name)
 {
  auto ts = timeStamps(name);
        return ts.modified;
 }

 Now, I wanted to create a minimal case (without all of Tango that this 
 program uses), but I'm having difficulty.  So I wanted to inspect the 
 assembly, but I'm on windows, and there is no obj2asm in the dmd 
 directory. So I can't figure out what the compiler is doing differently. 
 I'm not sure where to begin.  Walter, is this enough info for you to look 
 into this?  I can send you the object file and source file if you want to 
 see how dmd generated the code.

You have to buy the EUP to get the windows version of obj2asm, lol.

sweet deal :) So if Walter wants me to debug this, maybe he can send me a copy of obj2asm for free :)
 Another way to disassemble is to compile in debug info with -g, and step 
 through in a debugger, like WinDbg (shudder), ddbg (OK), or VS6 (yay). 
 I'm not sure how -g behaves with -inline though.

Yeah, I had lots of trouble with the debugger. But the printout alone is proof that it is failing.
 But if it makes you feel any better (?), this is definitely a 
 ug.  -inline should *never* change the behavior of code.  Bugzilla it if 
 it hasn't been already.

OK, so should I just attach all tango source used to the bug report? :P I suppose I could try and whittle it down. I'm just really surprised this is the first case. It makes me think that there is something really 'moons-are-aligned-properly' about the way everything is compiled. -Steve
Jul 16 2008
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Steven Schveighoffer wrote:

 I'm just really surprised this is the first case.  It makes me think that 
 there is something really 'moons-are-aligned-properly' about the way 
 everything is compiled.

When NRVO was introduced there were some bugs that appeared that sound similar to yours, but I think all the ones reported were fixed. --bb
Jul 16 2008
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Steven Schveighoffer" wrote
 "Jarrett Billingsley"wrote
 "Steven Schveighoffer" wrote
I think I found a bug in the compiler.  This bug seems to have affected 
the two versions I tried of dmd (1.024 and 1.033), so it's been in there 
a while.

 However, it's a very weird bug.

 I have a function that looks like this (for those who are interested, 
 this is from tango.io.Path):

 Time modified (char[] name)
 {
        return timeStamps(name).modified;
 }

 the timeStamps function returns a collection of 3 Time structs, which 
 indicate the modified, created, and accessed time for a file named 
 'name'.

 However, the result is corrupt.  I know this because I'm printing the 
 time in the timeStamps function, and it is different than the time 
 returned.

 In examining the entire flow of the code, I can find nothing wrong.

 This only happens with the -inline switch of dmd.

 If I rewrite the function in the following way, the problem goes 
 away(!):

 Time modified (char[] name)
 {
  auto ts = timeStamps(name);
        return ts.modified;
 }

 Now, I wanted to create a minimal case (without all of Tango that this 
 program uses), but I'm having difficulty.  So I wanted to inspect the 
 assembly, but I'm on windows, and there is no obj2asm in the dmd 
 directory. So I can't figure out what the compiler is doing differently. 
 I'm not sure where to begin.  Walter, is this enough info for you to 
 look into this?  I can send you the object file and source file if you 
 want to see how dmd generated the code.

You have to buy the EUP to get the windows version of obj2asm, lol.

sweet deal :) So if Walter wants me to debug this, maybe he can send me a copy of obj2asm for free :)
 Another way to disassemble is to compile in debug info with -g, and step 
 through in a debugger, like WinDbg (shudder), ddbg (OK), or VS6 (yay). 
 I'm not sure how -g behaves with -inline though.

Yeah, I had lots of trouble with the debugger. But the printout alone is proof that it is failing.
 But if it makes you feel any better (?), this is definitely a 
 g.  -inline should *never* change the behavior of code.  Bugzilla it if 
 it hasn't been already.

OK, so should I just attach all tango source used to the bug report? :P I suppose I could try and whittle it down. I'm just really surprised this is the first case. It makes me think that there is something really 'moons-are-aligned-properly' about the way everything is compiled. -Steve

Got to a minimal Phobos-based case: http://d.puremagic.com/issues/show_bug.cgi?id=2232 -Steve
Jul 16 2008
prev sibling parent dennis luehring <dl.soluz gmx.net> writes:
ida pro is the best - and the 4.9 version is free for non-commercial use

http://www.hex-rays.com/idapro/idadownfreeware.htm
Jul 16 2008