www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10086] New: strange segmentation fault

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

           Summary: strange segmentation fault
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: luka8088 owave.net



Attached code compiles bug segfaults on both:
Windows_NT luka8088-PC 6.1 7601+Service_Pack_1


I have no idea way :$

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




Created an attachment (id=1214)
code

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




Make sure it is compiled as -unittest, correct output should be: S1([[1]])

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


David <admin dav1d.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |admin dav1d.de



The order of how you compile the files matters:


─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd program.d lngex/m1.d
alter/callback.d
-unittest                                                                       
─[dav1d archbox][/tmp/b/dlang-bug]╼ ./program                              
    
S1([[1]])
─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d
lngex/m1.d alter/callback.d                                                     
─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d
lngex/m1.d alter/callback.d  && ./program                                       
S1([[1]])
─[dav1d archbox][/tmp/b/dlang-bug]╼ rm program                             
    
─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram program.d
lngex/m1.d alter/callback.d  && ./program                                       
S1([[1]])
─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram lngex/m1.d
alter/callback.d program.d  && ./program                                        
S1([[1]])
─[dav1d archbox][/tmp/b/dlang-bug]╼ dmd -unittest -ofprogram
alter/callback.d
lngex/m1.d program.d  && ./program                                              
./program(_D4core7runtime18runModuleUnitTestsUZb19unittestSegvHandlerUiPS4core3sys5posix6signal9siginfo_tPvZv+0x3e)[0x457cde]
[1]    2047 segmentation fault (core dumped)  ./program

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


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru



---
Reduced 

------ m1.d -----
module m1;

import std.stdio;
import callback;

struct S1 {
  int[][] a1 = [[1]];
}

 safe auto f1 (S1 r, bool o, dchar a, dchar b) {
  return r;
}

 safe auto f2 (T1, T2) (S1 r, T1 g, T2 h) {
  alias cpt = bind!(f1, r);
  return f3!(cpt!(bool, dchar, dchar))(g, h);
}

 safe auto f3 (alias l = (a, b, c) => 0, T1, T2) (T1 d, T2 e) {
  return l(true, 'a', 'b');
}

void main() {
  S1 s1;
  auto z = bind!(f2, s1)("", "");
  writeln(z);
}
----callback.d ----

module callback;

template bind (alias f, bindValues...) {
  auto bind (types...) (types values) {
    return f(bindValues, values);
  }
}
------------------

If compilation starts with 'callback' the program crashes, can confirm in 2.063
git head.

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


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice, wrong-code
           Severity|normal                      |major



---
Further reduced:

-----callback.d-----
module callback;

auto bind(alias f, bindValues...)()
{
   auto bind(types...) (types values)
   {
      return f(bindValues, values);
   }
   return bind();
}
----m1.d--------
import callback;

extern(C) int printf(const char*, ...);

struct S1 {
   int a1 = 1;
}

 safe auto f1 (S1 r) {
  return r;
}

 safe auto f2()(S1 r) {
  return bind!(f1, r);
}

void main() {
  S1 s1;
  auto z = bind!(f2, s1)();
  printf("%d\n", z.a1);
}
-------------------------
Compile with callback as first argument, program prints garbage.

The problem appears in:
Dump of assembler code for function
_D2m14mainFZv43__T4bindS62m12f2S23_D2m14mainFZv2s1S2m12S1Z4bindMFNfZS2m12S19__T4bindZ4bindMFNfZS2m12S1:
   0x000000000041a1bc <+0>:    push   %rbp
   0x000000000041a1bd <+1>:    mov    %rsp,%rbp
   0x000000000041a1c0 <+4>:    sub    $0x10,%rsp
=> 0x000000000041a1c4 <+8>:    mov    (%rdi),%edi
   0x000000000041a1c6 <+10>:    callq  0x41a1d4
<_D2m17__T2f2Z2f2FNfS2m12S1ZS2m12S1>
   0x000000000041a1cb <+15>:    mov    %rbp,%rsp
   0x000000000041a1ce <+18>:    pop    %rbp
   0x000000000041a1cf <+19>:    retq   
End of assembler dump.

If m1.d is compiled first, instruction is mov -0x8 (%rdi),%edi which is correct
(function got RBP as argument, so it should read 8 bytes below).

Moreover, there is ice here: if you transform f2() from function template to
template (again, you need to compile callback first), you get:

m1.d(13): Error: function m1.f2 compiler error, parameter 'r', bugzilla 2962?
dmd: glue.c:817: virtual void FuncDeclaration::toObjFile(int): Assertion `0'
failed.
Aborted

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


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|strange segmentation fault  |ICE or wrong code on
                   |                            |passing variable as
                   |                            |template value parameter
           Severity|major                       |critical



---
After reading issue 2962 I raise status to critical because this bug seems to
raise old nasty bug marked as fixed and critical.

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



https://github.com/D-Programming-Language/dmd/pull/2485

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/78ca53ef95d71e436c8cdfe70a626e275be6b3c2
fix Issue 10086 - ICE(glue.c) or wrong code on passing variable as template
value parameter

https://github.com/D-Programming-Language/dmd/commit/274718428aee31c5e52d4ce66a932a2e0f4af1e3


Issue 10086 & 10857 - Adjust instantiated template process order, and fix ICE
in glue.c

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2013