[D-runtime] Bug 3150: requires changes to rt/lifetime.d
Steve Schveighoffer
schveiguy at yahoo.com
Fri Jul 23 08:54:34 PDT 2010
I have a problem here. If I change a function that returns a ulong to having it
return an Array struct, the compiler expects the caller to push a reference to
the return value on the stack, where it doesn't do that when returning a ulong.
Easily demonstrated with this code:
testlongtoarray2.d:
struct Array
{
size_t length;
ubyte* ptr;
}
extern(C) Array callme()
{
Array d;
d.length = 5;
d.ptr = null;
return d;
}
testlongtoarray.d:
extern(C) ulong callme();
void main()
{
ulong x = callme();
}
[steves at steveslaptop testd]$ dmd -gc testlongtoarray*.d[steves at steveslaptop
testd]$ gdb testlongtoarray2
GNU gdb (GDB) Fedora (6.8.50.20090302-40.fc11)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i586-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) run
Starting program: /home/steves/testd/testlongtoarray2
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x08049073 in callme (__HID1=0x180fc4) at testlongtoarray2.d:9 <------ note the
hidden argument which is garbage!
9 Array d;
Missing separate debuginfos, use: debuginfo-install glibc-2.10.2-1.i686
(gdb)
What's happening is that main is simply calling the function without pushing
anything on the stack, but the implementation expects that the reference to the
return value is on the stack.
Does this make any sense to anyone? What should I do here? I can't really
change what the compiler expects the return value to be.
-Steve
----- Original Message ----
> From: Don Clugston <dclugston at googlemail.com>
> To: D-runtime at puremagic.com
> Sent: Fri, July 23, 2010 5:31:04 AM
> Subject: [D-runtime] Bug 3150: requires changes to rt/lifetime.d
>
> Fixing this bug will be important for 64 bits:
> 3150 cast from dynamic array to ulong is allowed
>
> As discussed in the comments to that bug, a change is required at two
> places in druntime, because druntime currently relies on the compiler
> bug. I don't think it's particularly difficult, but I don't want to do
> it myself. Can one of you guys take care of it?
> _______________________________________________
> D-runtime mailing list
> D-runtime at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/d-runtime
>
More information about the D-runtime
mailing list