Unconditonally define alloca as __builtin_alloca

Submitted by Michael Forney on Nov. 19, 2019, 4:04 a.m.

Details

Message ID 20191119040459.11143-1-mforney@mforney.org
State New
Series "Unconditonally define alloca as __builtin_alloca"
Headers show

Commit Message

Michael Forney Nov. 19, 2019, 4:04 a.m.
This enables alternative compilers, which may not define __GNUC__,
to implement alloca, which is still fairly widely used.

This is similar to how stdarg.h already works in musl; compilers must
implement __builtin_va_arg, there is no fallback definition.
---
 include/alloca.h | 4 ----
 1 file changed, 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/alloca.h b/include/alloca.h
index d2e6f1c6..8ae8a30d 100644
--- a/include/alloca.h
+++ b/include/alloca.h
@@ -8,11 +8,7 @@  extern "C" {
 #define	__NEED_size_t
 #include <bits/alltypes.h>
 
-void *alloca(size_t);
-
-#ifdef __GNUC__
 #define alloca __builtin_alloca
-#endif
 
 #ifdef __cplusplus
 }

Comments

Szabolcs Nagy Nov. 19, 2019, 9:28 a.m.
* Michael Forney <mforney@mforney.org> [2019-11-18 20:04:59 -0800]:
> This enables alternative compilers, which may not define __GNUC__,
> to implement alloca, which is still fairly widely used.
> 
> This is similar to how stdarg.h already works in musl; compilers must
> implement __builtin_va_arg, there is no fallback definition.
> ---
>  include/alloca.h | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/include/alloca.h b/include/alloca.h
> index d2e6f1c6..8ae8a30d 100644
> --- a/include/alloca.h
> +++ b/include/alloca.h
> @@ -8,11 +8,7 @@ extern "C" {
>  #define	__NEED_size_t
>  #include <bits/alltypes.h>
>  
> -void *alloca(size_t);

i don't think removing the prototype is a good idea.

alloca is a builtin in gcc and won't generate an extern
call even without optimization, so things work now with
#undef alloca

> -
> -#ifdef __GNUC__
>  #define alloca __builtin_alloca
> -#endif
>  
>  #ifdef __cplusplus
>  }
> -- 
> 2.20.1