LDC, ARM: unnecessary default initialization

Jack Applegame via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 18 02:42:25 PDT 2017


I explore the possibility of using D for bare metal ARM 
programming.

For some reason, the LDC default initializes the structure, even 
if initialization of all its members is specified as void. I 
believe that this is wrong.

test.d
****************************************
module test;

import core.bitop : volatileStore;

struct Foo {
	uint[64] m = void; // no default initialization
	this(uint a) {
		foreach(ref b; m) volatileStore(&b,a++);
	}
}

void ResetHandler() {
	auto foo = Foo(10);
}
****************************************

$ldc2 -mtriple=thumb-none-linux-eabi -mcpu=cortex-m3 -c --betterC 
--boundscheck=off -relocation-model=static -O3 -vcolumns test.d

test.o assembly
****************************************
00000000 <_D4test12ResetHandlerFZv>:
    0:   b510            push    {r4, lr}
    2:   b0c0            sub     sp, #256        ; 0x100 -+
    4:   466c            mov     r4, sp                   | 
default initialization
    6:   f44f 7180       mov.w   r1, #256        ; 0x100  |
    a:   4620            mov     r0, r4                   | WHY???
    c:   f7ff fffe       bl      0 <__aeabi_memclr4>     -+
   10:   2000            movs    r0, #0
   12:   f100 010a       add.w   r1, r0, #10
   16:   f844 1020       str.w   r1, [r4, r0, lsl #2]
   1a:   3001            adds    r0, #1
   1c:   2949            cmp     r1, #73 ; 0x49
   1e:   d1f8            bne.n   12 <_D4test12ResetHandlerFZv+0x12>
   20:   b040            add     sp, #256        ; 0x100
   22:   bd10            pop     {r4, pc}
*****************************************




More information about the Digitalmars-d mailing list