Automatic void initialization

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Jun 2 09:25:14 PDT 2009


On Tue, Jun 2, 2009 at 10:41 AM, Frits van Bommel
<fvbommel at remwovexcapss.nl> wrote:
> Jarrett Billingsley wrote:
>>
>> On Tue, Jun 2, 2009 at 8:10 AM, bearophile <bearophileHUGS at lycos.com>
>> wrote:
>>>
>>> Walter Bright:
>>>>
>>>> Dead assignment elimination is compiler technology from the 70's !<
>>>
>>> I'd like to see this technology used for arrays too. So in the following
>>> two adjacent lines of code "a" doesn't get initialized to zero before being
>>> initialized again to 5:
>>>
>>> void main() {
>>>   auto a = new int[10];
>>>   a[] = 5;
>>>   printf("%d\n", a[3]);
>>> }
>>
>> As far as I know, LDC already does this.
>
> It doesn't. The runtime call that allocates the array initializes it (to 0
> in this case), and then the array assignment overwrites that initialization.
>
> In this case the array doesn't escape the function, so it does get
> stack-allocated by a custom optimization pass (and the initialization is
> turned into an LLVM memset intrinsic), but LLVM still can't "look into" the
> call that does the array assignment to know it will always overwrite the
> entire array so the memset isn't necessary.

I thought I remember seeing a runtime function to allocate an array
without initializing it.. maybe it's just not used yet?



More information about the Digitalmars-d mailing list