www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1121] New: Assertion codegen issue with templated function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1121

           Summary: Assertion codegen issue with templated function
           Product: D
           Version: 1.010
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


Weirdest.  Bug.  Ever.

[test.d]------------------------
module test;

import mod;
import std.stdio;

void main()
{
        foo();
        func!(void)();
}
--------------------------------

[mod.d]-------------------------
module mod;

void foo()
{
        assert(false, "GO");
}

public void func(T)()
{
        assert(false, "Blah");
}
--------------------------------

Command line:

C:\dmd\proj\MiniDDebug\minid>dmd test.d mod.d
C:\dmd\bin\..\..\dm\bin\link.exe test+mod,,,user32+kernel32/noi;

C:\dmd\proj\MiniDDebug\minid>test
Error: AssertError Failure GO(5) GO


Notice that the filename reported for the assert error is the same as the error
message instead of "mod.d".  If you look at the disassembly for that "GO!"
assert, it's something like this:

0040204B   push        5
0040204D   push        dword ptr ds:[40F0ECh]
00402053   push        dword ptr ds:[40F0E8h]
00402059   push        dword ptr ds:[40F0ECh]
0040205F   push        dword ptr ds:[40F0E8h]
00402065   call        __d_assert_msg (004022ac)

First it pushes the line number, then what should be the filename pointer and
length, and then the message pointer and length.  The message pointer and
length are correct, but the filename pointer and length are not right (in this
case, it passes the same pointers and length as for the message).  The filename
pointer and length passed also depend on the amount of code and constants in
the executable, resulting in various outputs for this program (such as plain
old access violations, or "AssertError out of memory" errors if the length
passed is gigantic, or "4invalid UTF-8 sequence" errors when it tries to print
out garbage).

However, it's only foo() whose assert is messed up.  func()'s assert works
fine.

Some other interesting aspects.  The following make the problem disappear:

- Removing either assert.
- Removing either assert message (but leaving the condition).
- Declaring foo, func, or both in test.d (both functions have to be declared in
mod.d for the problem to happen).
- Removing foo.

I.. just don't know.


-- 
Apr 10 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1121


bugzilla digitalmars.com changed:

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





Fixed DMD 1.013


-- 
Apr 20 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1121


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All





Added to DStress as
http://dstress.kuehne.cn/complex/assert_21


-- 
Apr 27 2007