Thread overview
Alloca without core.stdc.stdlib?
Jun 29, 2018
ARaspiK
Jun 29, 2018
ARaspiK
Jun 29, 2018
Iain Buclaw
June 29, 2018
According to core.stdc.stdlib, alloca (on GDC) is a compiler intrinsic.
But I can't separate it from the rest of core.stdc.stdlib, for a small druntime I'm making. Here's what it seems to be:

version(GNU) extern(C) @system nothrow @nogc void* alloca(size_t size) pure;

Writing the declaration to a file, or even removing everything else from core.stdc.stdio, isn't working. I cannot have any C library stuff. How do I isolate it?
June 29, 2018
On Friday, 29 June 2018 at 09:17:58 UTC, ARaspiK wrote:
> According to core.stdc.stdlib, alloca (on GDC) is a compiler intrinsic.
> But I can't separate it from the rest of core.stdc.stdlib, for a small druntime I'm making. Here's what it seems to be:
>
> version(GNU) extern(C) @system nothrow @nogc void* alloca(size_t size) pure;
>
> Writing the declaration to a file, or even removing everything else from core.stdc.stdio, isn't working. I cannot have any C library stuff. How do I isolate it?

After a little more digging around, I found that you can import GCC's builtin functions (including __builtin_alloca) from gcc.builtins. I copied the file exactly, and GCC provided.

It seems that simply importing an empty module named gcc.builtins is enough to get GDC to pull everything. You can also simply import it from the default location.
June 29, 2018
On 29 June 2018 at 11:28, ARaspiK via D.gnu <d.gnu@puremagic.com> wrote:
> On Friday, 29 June 2018 at 09:17:58 UTC, ARaspiK wrote:
>>
>> According to core.stdc.stdlib, alloca (on GDC) is a compiler intrinsic. But I can't separate it from the rest of core.stdc.stdlib, for a small druntime I'm making. Here's what it seems to be:
>>
>> version(GNU) extern(C) @system nothrow @nogc void* alloca(size_t size)
>> pure;
>>
>> Writing the declaration to a file, or even removing everything else from core.stdc.stdio, isn't working. I cannot have any C library stuff. How do I isolate it?
>
>
> After a little more digging around, I found that you can import GCC's builtin functions (including __builtin_alloca) from gcc.builtins. I copied the file exactly, and GCC provided.
>
> It seems that simply importing an empty module named gcc.builtins is enough to get GDC to pull everything. You can also simply import it from the default location.

That's one way to use it.  GDC also has some magic where it checks all extern(C) functions declared in any module starting with core.stdc.

There should be no reason why you can't move alloca to another module, e.g:

module core.stdc.alloca;
extern(C) void* alloca(size_t);

---

import core.stdc.alloca;
auto ptr = alloca(42);  // This is lowered to __builtin_alloca.


Iain.