From c515fb5148f1d81d5f7736825e14c7502c15432a Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Mon, 26 Nov 2012 16:42:38 -0800 Subject: Cast to __intptr_t before casting pointer to int64 --- include/libc-internal.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'include') diff --git a/include/libc-internal.h b/include/libc-internal.h index e5fd5337ab..0c0fa024a7 100644 --- a/include/libc-internal.h +++ b/include/libc-internal.h @@ -34,4 +34,20 @@ extern void __libc_thread_freeres (void); /* Define and initialize `__progname' et. al. */ extern void __init_misc (int, char **, char **); +/* 1 if 'type' is a pointer type, 0 otherwise. */ +# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5) + +/* __intptr_t if P is true, or T if P is false. */ +# define __integer_if_pointer_type_sub(T, P) \ + __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \ + : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0)) + +/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */ +# define __integer_if_pointer_type(expr) \ + __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \ + __pointer_type (__typeof__ (expr))) + +/* Cast an integer or a pointer VAL to integer with proper type. */ +# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val)) + #endif /* _LIBC_INTERNAL */ -- cgit 1.4.1