Infinite recursion with memcpy and memset/memclr lowerings

kinke kinke at libero.it
Thu Jul 19 14:51:02 UTC 2018


On Thursday, 19 July 2018 at 12:12:28 UTC, Mike Franklin wrote:
> I ran into an interesting situation with my ARM Cortex-M 
> experiment using LDC.
>
> I have this function:
>
> extern(C) void* __aeabi_memclr(void* dest, size_t num)
> {
>     byte* d = cast(byte*)dest;
>     for(int i = 0; i < num; i++)
>     {
>         d[i] = cast(byte)0;
>     }
>
>     return dest;
> }
>
> LDC seems to recognize the body of the function and rewrites it 
> as `__aeabi_memclr`, causing infinite recursion.  Is there some 
> way I can instruct the compiler to stop doing that?
>
> Mike

Related: 
https://users.rust-lang.org/t/--aeabi-memclr-compiling-to-suicide-loop/4451

I don't know how to prevent LLVM from assuming the compiler-rt 
builtins are available.

If you don't insist on implementing everything yourself, you 
could use LLVM's implementations in compiler-rt, e.g., by a 
simple forward declaration or by using the LLVM memset intrinsic 
(see ldc.intrinsics) and obviously linking against the 
compiler-rt builtins lib (e.g., 
https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/arm/aeabi_memset.S).


More information about the digitalmars-d-ldc mailing list