www.digitalmars.com         C & C++   DMDScript  

D.gnu - Alloca without core.stdc.stdlib?

reply ARaspiK <araspik protonmail.com> writes:
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?
Jun 29 2018
parent reply ARaspiK <araspik protonmail.com> writes:
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.
Jun 29 2018
parent Iain Buclaw <ibuclaw gdcproject.org> writes:
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.
Jun 29 2018