www.digitalmars.com         C & C++   DMDScript  

D.gnu - Using GCC's builtin alloca without the C standard library

reply Mike Franklin <slavo5150 yahoo.com> writes:
I'd like to be able to use GCC's `__builtin_alloca` without the C 
standard library.

This seems to work:

--- core/stdc/stdlib.d
module core.stdc.stdlib;
extern(C) void* alloca(size_t n) pure;
---

...but, since I'm not actually using the C standard library, I'd 
prefer to avoid creating that module hierarchy.


I tried simply adding...

--- {anyfile}.d
extern extern(C) void* __builtin_alloca(size_t size) pure;
---

... to my existing files, but I get an undefined reference for 
`__bulitin_alloca`.


LDC was pretty straightforward with:
--- {anyfile}.d
pragma(LDC_alloca)
void* alloca(size_t size) pure;
---

Is there a way to do something like that in GDC.  I don't care if 
I have to use `__builtin_alloca` or some other identifier, I just 
don't want to create the C standard library module hierarchy.

Thanks,
Mike
Jul 22 2018
parent reply Johannes Pfau <nospam example.com> writes:
Am Mon, 23 Jul 2018 01:35:02 +0000 schrieb Mike Franklin:

 I'd like to be able to use GCC's `__builtin_alloca` without the C
 standard library.
 
Just import gcc.builtins for all GCC builtins: ---------------------------- import gcc.builtins; void main() { auto foo = __builtin_alloca(10); } ---------------------------- -- Johannes
Jul 23 2018
parent Iain Buclaw <ibuclaw gdcproject.org> writes:
On 23 July 2018 at 09:15, Johannes Pfau via D.gnu <d.gnu puremagic.com> wrote:
 Am Mon, 23 Jul 2018 01:35:02 +0000 schrieb Mike Franklin:

 I'd like to be able to use GCC's `__builtin_alloca` without the C
 standard library.
Just import gcc.builtins for all GCC builtins: ---------------------------- import gcc.builtins; void main() { auto foo = __builtin_alloca(10); } ----------------------------
Assuming that you are already using the gcc.attribute module for accessing various attributes, possibly via a wrapper module. There's probably a project to be made for adding pragmas as an alternative to the various magic modules and attributes we have in the compiler, but first requires a little nip and tuck to make it more friendly for us to add these to gdc. https://issues.dlang.org/show_bug.cgi?id=3004 https://issues.dlang.org/show_bug.cgi?id=19108 https://issues.dlang.org/show_bug.cgi?id=19109 https://issues.dlang.org/show_bug.cgi?id=19110 As well as 'pragma(GNU_builtin)', there are these such options that can't be done using UDAs. https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html Iain.
Jul 23 2018