Build problem with latest git head

Johannes Pfau nospam at example.com
Sat Nov 9 10:17:36 PST 2013


Am Fri, 08 Nov 2013 21:00:18 +0100
schrieb "Timo Sintonen" <t.sintonen at luukku.com>:

> Now returning to my original problem.
> 
> I tested various loops and it seems that write to a variable is 
> not volatile even if the variable is marked shared. If I write to 
> a variable several times in a loop, all but the last write are 
> optimized out. The only write is put after the loop.
> Read works fine now with shared.
> 
> How can I do volatile writes?

AFAICS this is a GDC bug, Iain can you have a look at this?

Here's a simple test case:
---------------------------------------------
struct Register
{
    shared size_t a;
}

Register* reg = cast(Register*)0xFFDDCCAA;

void main()
{
     for(size_t i = 0; i < 10; i++)
         reg.a = i;
}
---------------------------------------------


Same thing in C (working):
---------------------------------------------
#include <stdlib.h>

struct Register
{
    volatile size_t a;
};
typedef struct Register reg_t;

reg_t* reg = (reg_t*)0xFFDDCCAA;

void main()
{
     size_t i;
     for(i = 0; i < 10; i++)
         reg->a = i;
}

---------------------------------------------

Compile with
gdc -O3 test.d -S -fdump-tree-original-raw
gcc -O3 test.c -S -fdump-tree-original-raw

Of course the code won't run but the wrong optimization is obvious in
the generated ASM. I had a quick look at the fdump-tree-original-raw
output but I didn't see a obvious difference between the C/D output.


More information about the D.gnu mailing list