[Issue 22864] [REG 2.067] Throwing in array literal leads to destructor being called on unconstructed data
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 23 13:04:02 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22864
Iain Buclaw <ibuclaw at gdcproject.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ibuclaw at gdcproject.org
--- Comment #2 from Iain Buclaw <ibuclaw at gdcproject.org> ---
Doesn't affect gdc-11
This is the codegen:
---
struct S[] ret;
struct S slot[1];
void* mem;
ret.length = 1;
slot[0] = getS (); [return slot optimization]
mem = _d_arrayliteralTX (&_D25TypeInfo_AS10issue228641S6__initZ, 1);
__builtin_memcpy (mem, &slot, 1);
ret.ptr = mem;
return ret.ptr;
---
The abort occurs if the array allocation and getS() calls are reversed.
---
struct S[] ret;
struct S slot[1];
void* mem;
ret.length = 1;
mem = _d_arrayliteralTX (&_D25TypeInfo_AS10issue228641S6__initZ, 1);
slot[0] = getS (); [return slot optimization]
__builtin_memcpy (mem, &slot, 1);
ret.ptr = mem;
return ret.ptr;
---
So with ldc (and maybe dmd), it's an issue with what order arguments are
evaluated in. As at a high level, the lowered code would look like:
---
memcpy (_d_arrayliteralTX(), getS(), 1);
---
I guess it would be enforced LTR evaluation of C function calls.
--
More information about the Digitalmars-d-bugs
mailing list