LDC, ARM (seems like x86 too) bug?
Johan Engelen
j at j.nl
Tue Sep 19 21:21:41 UTC 2017
On Tuesday, 19 September 2017 at 09:52:12 UTC, Jack Applegame
wrote:
> Code:
>
>> // values from linker script
>> extern(C) extern __gshared {
>> uint src_beg; // source begin uint trg_beg; // target begin
>> uint trg_end; // target end }
>>
>> void copy(uint* ss, uint* ts, const uint* te) {
>> while(ts != te) *ts++ = *ss++;
>> }
>>
>> void foo() {
>> copy(&src_beg, &trg_beg, &trg_end);
>> }
[snip]
> Apparently, LDC believes that addresses of `trg_beg` and
> `trg_end` can not be initially equal and moves check to the
> end. But this is not always the case.
This is a question of spec details. We are assuming C semantics
for extern variables: just like normal variables, they cannot
alias.
See also:
https://stackoverflow.com/questions/5559281/c-externs-that-alias-the-same-address
LLVM optimizes these cases more aggressively than GCC:
https://godbolt.org/g/yJdp9P
-Johan
More information about the digitalmars-d-ldc
mailing list