diff mbox series

[v3,14/19] add predefined macros for [u]intmax

Message ID 20181214001536.6259-15-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series predefined macros for intmax_t/intptr_t/... | expand

Commit Message

Luc Van Oostenryck Dec. 14, 2018, 12:15 a.m. UTC
Seems to use [u]long for all LP64 archs and [u]llong
and all LP32 ones (but OpenBSD but it seems to not defines
the corresponding macros).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c                            | 6 ++++++
 target.c                         | 2 ++
 target.h                         | 2 ++
 validation/preprocessor/predef.c | 2 ++
 4 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/lib.c b/lib.c
index 50d5b61d3..3a4f9820a 100644
--- a/lib.c
+++ b/lib.c
@@ -474,12 +474,16 @@  static void handle_arch_m64_finalize(void)
 		goto case_x86_64;
 	case ARCH_LP32:
 		/* default values */
+		intmax_ctype = &llong_ctype;
+		uintmax_ctype = &ullong_ctype;
 		return;
 	case ARCH_LP64:
 		bits_in_long = 64;
 		max_int_alignment = 8;
 		size_t_ctype = &ulong_ctype;
 		ssize_t_ctype = &long_ctype;
+		intmax_ctype = &long_ctype;
+		uintmax_ctype = &ulong_ctype;
 		predefine("__LP64__", 1, "1");
 		predefine("_LP64", 1, "1");
 		goto case_64bit_common;
@@ -1239,6 +1243,8 @@  static void predefined_macros(void)
 
 	predefined_sizeof("INT128", "", 128);
 
+	predefined_ctype("INTMAX",    intmax_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH);
+	predefined_ctype("UINTMAX",  uintmax_ctype, PTYPE_MAX|PTYPE_TYPE);
 	predefined_ctype("INTPTR",   ssize_t_ctype, PTYPE_MAX|PTYPE_TYPE|PTYPE_WIDTH);
 	predefined_ctype("UINTPTR",   size_t_ctype, PTYPE_MAX|PTYPE_TYPE);
 	predefined_ctype("PTRDIFF",  ssize_t_ctype, PTYPE_ALL_T|PTYPE_TYPE);
diff --git a/target.c b/target.c
index 279d1142d..313288258 100644
--- a/target.c
+++ b/target.c
@@ -6,6 +6,8 @@ 
 
 struct symbol *size_t_ctype = &uint_ctype;
 struct symbol *ssize_t_ctype = &int_ctype;
+struct symbol *intmax_ctype = &llong_ctype;
+struct symbol *uintmax_ctype = &ullong_ctype;
 struct symbol *wchar_ctype = &int_ctype;
 struct symbol *wint_ctype = &uint_ctype;
 
diff --git a/target.h b/target.h
index 998d25af5..d764d4182 100644
--- a/target.h
+++ b/target.h
@@ -3,6 +3,8 @@ 
 
 extern struct symbol *size_t_ctype;
 extern struct symbol *ssize_t_ctype;
+extern struct symbol *intmax_ctype;
+extern struct symbol *uintmax_ctype;
 extern struct symbol *wchar_ctype;
 extern struct symbol *wint_ctype;
 
diff --git a/validation/preprocessor/predef.c b/validation/preprocessor/predef.c
index df0944b33..22e89bbc0 100644
--- a/validation/preprocessor/predef.c
+++ b/validation/preprocessor/predef.c
@@ -17,6 +17,8 @@  int test(void)
 	TEST_SMAX(INT, int);
 	TEST_SMAX(LONG, long);
 	TEST_SMAX(LONG_LONG, long long);
+	TEST_SMAX(INTMAX, __INTMAX_TYPE__);
+	TEST_UMAX(UINTMAX, __UINTMAX_TYPE__);
 	TEST_SMAX(INTPTR, __INTPTR_TYPE__);
 	TEST_UMAX(UINTPTR, __UINTPTR_TYPE__);
 	TEST_SMAX(PTRDIFF, __PTRDIFF_TYPE__);