[Issue 10086] strange segmentation fault

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 15 12:08:21 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10086


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

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


--- Comment #5 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-05-15 12:08:18 PDT ---
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: -------


More information about the Digitalmars-d-bugs mailing list