www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3006] New: template module using array operation cause dmd internal error

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

           Summary: template module using array operation cause dmd
                    internal error
           Product: D
           Version: 2.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: rinick gmail.com


dmd testmodule.d test.d -oftest
Internal error: e2ir.c 632

testmodule.d:
-----------------------------------
module testmodule;
template foo(T)
{
    void foo()
    {
        T[3] a,b,c;
        a[] = b[] + c[];
    }
}
-----------------------------------

test.d:
-----------------------------------
import testmodule;
void main()
{
    foo!ulong();
        // long, double, real, cfloat etc. have this bug
        // int, short, float etc. work fine
}
-----------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 17 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3006


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE(e2ir.c) template module |ICE(e2ir.c, tocsym.c)
                   |using array operation       |template module using array
                   |                            |operation




--- Comment #1 from Don <clugdbug yahoo.com.au>  2009-05-19 01:18:11 PDT ---
Fails also on D1 with a bizarre error message. Where the heck did variable 'p'
come from?

dmd bug2.d bug.d  (order is important).
================
Error: variable p forward referenced
Error: variable p forward referenced
linkage = 0
Assertion failure: '0' on line 262 in file 'tocsym.c'

abnormal program termination
===========

bug.d
------
import bug2;
void main()
{
    foo!(long)();
}
------
bug2.d
------
void foo(T)() {
   long[] a;
   a[] = -a[];
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3006


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch




--- Comment #2 from Don <clugdbug yahoo.com.au>  2009-06-03 16:07:40 PDT ---
Root cause: semantic3 never gets run on the function which 
is created, if it's compiled in a module which doesn't instantiate the
template it's in. To fix this, we can run its semantic3 immediately, since
we're already in semantic3 for this module.
BTW: It also seems to me that the back-end should have
assert(FuncDeclaration->semanticRun==4) before running toObj(), to ensure
semantic3 has been run (it would be a better place to ICE).
BTW: FuncDeclaration::toObj() is declared but never defined or used.

PATCH: Add this code to arrayop.c, BinExp::arrayOp, line 393.

        sc->linkage = LINKc;
        fd->semantic(sc);
+          fd->semantic2(sc);
+          fd->semantic3(sc);
        sc->pop();

// TEST CASE 1. Compilation order is important.
dmd bugx.d bug.d
------
bug.d
------
import bugx;
void main(){
    foo!(long)();
}
------
bugx.d
------
void foo(T)() {
   long[] a;
   a[] = -a[];
}
// TEST CASE 2: replace bugx with:
void foo(T)() {
   T[] a;
   a[] = -a[];
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 03 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3006


HOSOKAWA Kenchi <hskwk inter7.jp> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hskwk inter7.jp




--- Comment #3 from HOSOKAWA Kenchi <hskwk inter7.jp>  2009-08-20 13:06:22 PDT
---
(In reply to comment #2)

Much thanks for your analysis, Don.
I met almost the same error today.

// bugx.d
void foo() {
    real[3] s, a, b;
    s[] = a[] + b[];
}

// bug.d
void bar() {
    foo; // p2 Internal error: e2ir.c 632   DMD 2.031
}

This ICE occurs without template in this case.
Compiling bugx.d cause no error, calling foo from OTHER module cause ICE.

Besides, compiler switchs affect:
( -release && !-unittest ) cause this ICE.

Anyway the root cause is obviously the same.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 20 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3006


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2009-10-13
13:45:08 PDT ---
Fixed dmd 1.049 and 2.034

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