Added Redirects to longdouble error functions [BZ #29033]
Checks
Context |
Check |
Description |
dj/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
dj/TryBot-32bit |
success
|
Build for i686
|
Commit Message
This patch redirects the error functions to the appropriate
longdouble variants which enables the compiler to optimize
for the abi ieeelongdouble.
Signed-off-by: Sachin Monga <smonga@linux.ibm.com>
---
misc/bits/error-ldbl.h | 53 ++++++++++++++++++++++++++++++++++++++++--
misc/sys/cdefs.h | 6 +++++
2 files changed, 57 insertions(+), 2 deletions(-)
Comments
On 2/9/23 11:45 AM, Sachin Monga via Libc-alpha wrote:
> This patch redirects the error functions to the appropriate
> longdouble variants which enables the compiler to optimize
> for the abi ieeelongdouble.
This is a tricky patch. Are there tests to verify this functions as
desired when redirecting long double? If practical, please add some.
>
> Signed-off-by: Sachin Monga <smonga@linux.ibm.com>
> ---
> misc/bits/error-ldbl.h | 53 ++++++++++++++++++++++++++++++++++++++++--
> misc/sys/cdefs.h | 6 +++++
> 2 files changed, 57 insertions(+), 2 deletions(-)
>
> diff --git a/misc/bits/error-ldbl.h b/misc/bits/error-ldbl.h
> index 599a7d6e06..73ecbe7a10 100644
> --- a/misc/bits/error-ldbl.h
> +++ b/misc/bits/error-ldbl.h
> @@ -20,5 +20,54 @@
> # error "Never include <bits/error-ldbl.h> directly; use <error.h> instead."
> #endif
>
> -__LDBL_REDIR_DECL (error)
> -__LDBL_REDIR_DECL (error_at_line)
Does this still return the expected function with usage like?
#include <error.h>
typedef void (error_func_t)(int,int,const char*,...);
error_func_t
get_error_func() {
return &error;
}
> +
> +__LDBL_REDIRECT (__error_alias, (int __status, int __errnum,
> + const char *__format, ...),
> + error)
> + __attribute__ ((__format__ (__printf__, 3, 4)));
> +__LDBL_REDIRECT (__error_noreturn, (int __status, int __errnum,
> + const char *__format, ...),
> + error)
> + __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)));
> +
> +
> +/* If we know the function will never return make sure the compiler
> + realizes that, too. */
> +__extern_always_inline void
> +error (int __status, int __errnum, const char *__format, ...)
> +{
> + if (__builtin_constant_p (__status) && __status != 0)
> + __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
> + else
> + __error_alias (__status, __errnum, __format, __va_arg_pack ());
> +}
> +
> +
> +__LDBL_REDIRECT (__error_at_line_alias, (int __status, int __errnum,
> + const char *__fname,
> + unsigned int __line,
> + const char *__format, ...),
> + error_at_line)
> + __attribute__ ((__format__ (__printf__, 5, 6)));
> +__LDBL_REDIRECT (__error_at_line_noreturn, (int __status, int __errnum,
> + const char *__fname,
> + unsigned int __line,
> + const char *__format,
> + ...),
> + error_at_line)
> + __attribute__ ((__noreturn__, __format__ (__printf__, 5, 6)));
> +
> +
> +/* If we know the function will never return make sure the compiler
> + realizes that, too. */
> +__extern_always_inline void
> +error_at_line (int __status, int __errnum, const char *__fname,
> + unsigned int __line, const char *__format, ...)
> +{
> + if (__builtin_constant_p (__status) && __status != 0)
> + __error_at_line_noreturn (__status, __errnum, __fname, __line, __format,
> + __va_arg_pack ());
> + else
> + __error_at_line_alias (__status, __errnum, __fname, __line,
> + __format, __va_arg_pack ());
> +}
> diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
> index 66d6702123..34fdd3c24a 100644
> --- a/misc/sys/cdefs.h
> +++ b/misc/sys/cdefs.h
> @@ -245,6 +245,7 @@
> #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
>
> # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
> +
Trivial nit, this change seems unrelated.
> # ifdef __cplusplus
> # define __REDIRECT_NTH(name, proto, alias) \
> name proto __THROW __asm__ (__ASMNAME (#alias))
> @@ -567,6 +568,8 @@
> # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
> # define __LDBL_REDIR_DECL(name) \
> extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
> +# define __LDBL_REDIRECT(name, proto, alias) \
> + extern void name proto __asm (__ASMNAME ("__" #alias "ieee128"))
Is it possible to use the existing __REDIRECT_LDBL macro instead of
adding a new one? They seem identical save for an extra expansion with
__REDIRECT_LDBL.
>
> /* Alias name defined automatically, with leading underscores. */
> # define __LDBL_REDIR2_DECL(name) \
> @@ -605,6 +608,8 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
> extern __typeof (name) name __asm (__ASMNAME (#alias));
> # define __LDBL_REDIR_DECL(name) \
> extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
> +# define __LDBL_REDIRECT(name, proto, alias) \
> + extern void name proto __asm (__ASMNAME ("__nldbl_" #alias));
> # define __REDIRECT_LDBL(name, proto, alias) \
> __LDBL_REDIR1 (name, proto, __nldbl_##alias)
> # define __REDIRECT_NTH_LDBL(name, proto, alias) \
> @@ -619,6 +624,7 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
> # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
> # define __LDBL_REDIR2_DECL(name)
> # define __LDBL_REDIR_DECL(name)
> +# define __LDBL_REDIRECT(name, proto, alias)
> # ifdef __REDIRECT
> # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
> # define __REDIRECT_NTH_LDBL(name, proto, alias) \
@@ -20,5 +20,54 @@
# error "Never include <bits/error-ldbl.h> directly; use <error.h> instead."
#endif
-__LDBL_REDIR_DECL (error)
-__LDBL_REDIR_DECL (error_at_line)
+
+__LDBL_REDIRECT (__error_alias, (int __status, int __errnum,
+ const char *__format, ...),
+ error)
+ __attribute__ ((__format__ (__printf__, 3, 4)));
+__LDBL_REDIRECT (__error_noreturn, (int __status, int __errnum,
+ const char *__format, ...),
+ error)
+ __attribute__ ((__noreturn__, __format__ (__printf__, 3, 4)));
+
+
+/* If we know the function will never return make sure the compiler
+ realizes that, too. */
+__extern_always_inline void
+error (int __status, int __errnum, const char *__format, ...)
+{
+ if (__builtin_constant_p (__status) && __status != 0)
+ __error_noreturn (__status, __errnum, __format, __va_arg_pack ());
+ else
+ __error_alias (__status, __errnum, __format, __va_arg_pack ());
+}
+
+
+__LDBL_REDIRECT (__error_at_line_alias, (int __status, int __errnum,
+ const char *__fname,
+ unsigned int __line,
+ const char *__format, ...),
+ error_at_line)
+ __attribute__ ((__format__ (__printf__, 5, 6)));
+__LDBL_REDIRECT (__error_at_line_noreturn, (int __status, int __errnum,
+ const char *__fname,
+ unsigned int __line,
+ const char *__format,
+ ...),
+ error_at_line)
+ __attribute__ ((__noreturn__, __format__ (__printf__, 5, 6)));
+
+
+/* If we know the function will never return make sure the compiler
+ realizes that, too. */
+__extern_always_inline void
+error_at_line (int __status, int __errnum, const char *__fname,
+ unsigned int __line, const char *__format, ...)
+{
+ if (__builtin_constant_p (__status) && __status != 0)
+ __error_at_line_noreturn (__status, __errnum, __fname, __line, __format,
+ __va_arg_pack ());
+ else
+ __error_at_line_alias (__status, __errnum, __fname, __line,
+ __format, __va_arg_pack ());
+}
@@ -245,6 +245,7 @@
#if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
+
# ifdef __cplusplus
# define __REDIRECT_NTH(name, proto, alias) \
name proto __THROW __asm__ (__ASMNAME (#alias))
@@ -567,6 +568,8 @@
# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
# define __LDBL_REDIR_DECL(name) \
extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
+# define __LDBL_REDIRECT(name, proto, alias) \
+ extern void name proto __asm (__ASMNAME ("__" #alias "ieee128"))
/* Alias name defined automatically, with leading underscores. */
# define __LDBL_REDIR2_DECL(name) \
@@ -605,6 +608,8 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
extern __typeof (name) name __asm (__ASMNAME (#alias));
# define __LDBL_REDIR_DECL(name) \
extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
+# define __LDBL_REDIRECT(name, proto, alias) \
+ extern void name proto __asm (__ASMNAME ("__nldbl_" #alias));
# define __REDIRECT_LDBL(name, proto, alias) \
__LDBL_REDIR1 (name, proto, __nldbl_##alias)
# define __REDIRECT_NTH_LDBL(name, proto, alias) \
@@ -619,6 +624,7 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf
# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
# define __LDBL_REDIR2_DECL(name)
# define __LDBL_REDIR_DECL(name)
+# define __LDBL_REDIRECT(name, proto, alias)
# ifdef __REDIRECT
# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
# define __REDIRECT_NTH_LDBL(name, proto, alias) \