* [PATCH 0/3] use internal size for __INT_MAX__ & friends
@ 2017-05-19 11:20 Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 1/3] fix hardcoded size of wide chars Luc Van Oostenryck
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-05-19 11:20 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The goal of this series is to predefine macros like __INT_MAX__
with the same size of the one used by sparse while is used to be
size of the machine on which sparse was compiled.
Luc Van Oostenryck (3):
fix hardcoded size of wide chars
avoid to redefine __INT_MAX__ and friends
fix definition of __SCHAR_MAX__ & friends
char.c | 4 ++--
lib.c | 21 ++++++++++-----------
target.c | 2 ++
target.h | 2 ++
4 files changed, 16 insertions(+), 13 deletions(-)
--
2.13.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] fix hardcoded size of wide chars
2017-05-19 11:20 [PATCH 0/3] use internal size for __INT_MAX__ & friends Luc Van Oostenryck
@ 2017-05-19 11:20 ` Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 2/3] avoid to redefine __INT_MAX__ and friends Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 3/3] fix definition of __SCHAR_MAX__ & friends Luc Van Oostenryck
2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-05-19 11:20 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The size of wide chars was hardcoded to 32.
Fix this by using a variable to hold this 'bits_in_wchar',
like done for all others datatypes.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
char.c | 4 ++--
target.c | 2 ++
target.h | 2 ++
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/char.c b/char.c
index e2b3863be..c52521bc8 100644
--- a/char.c
+++ b/char.c
@@ -84,7 +84,7 @@ void get_char_constant(struct token *token, unsigned long long *val)
end = p + type - TOKEN_WIDE_CHAR;
}
p = parse_escape(p, &v, end,
- type < TOKEN_WIDE_CHAR ? bits_in_char : 32, token->pos);
+ type < TOKEN_WIDE_CHAR ? bits_in_char : bits_in_wchar, token->pos);
if (p != end)
warning(token->pos,
"multi-character character constant");
@@ -113,7 +113,7 @@ struct token *get_string_constant(struct token *token, struct expression *expr)
done = next;
}
}
- bits = is_wide ? 32 : bits_in_char;
+ bits = is_wide ? bits_in_wchar : bits_in_char;
while (token != done) {
unsigned v;
const char *p = token->string->data;
diff --git a/target.c b/target.c
index 17b228ae9..86a9e2e63 100644
--- a/target.c
+++ b/target.c
@@ -22,6 +22,8 @@ int bits_in_long = 32;
int bits_in_longlong = 64;
int bits_in_longlonglong = 128;
+int bits_in_wchar = 32;
+
int max_int_alignment = 4;
/*
diff --git a/target.h b/target.h
index 78c85cf7e..8326fa21a 100644
--- a/target.h
+++ b/target.h
@@ -20,6 +20,8 @@ extern int bits_in_long;
extern int bits_in_longlong;
extern int bits_in_longlonglong;
+extern int bits_in_wchar;
+
extern int max_int_alignment;
/*
--
2.13.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] avoid to redefine __INT_MAX__ and friends
2017-05-19 11:20 [PATCH 0/3] use internal size for __INT_MAX__ & friends Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 1/3] fix hardcoded size of wide chars Luc Van Oostenryck
@ 2017-05-19 11:20 ` Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 3/3] fix definition of __SCHAR_MAX__ & friends Luc Van Oostenryck
2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-05-19 11:20 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
Since commit 4fae9be00 & 5466cf8f3 ("predefine __INT_MAX__ and friends" &
"predefine __SIZEOF_INT__ & friends"), macros like __INT_MAX__ and
__SIZEOF_POINTER__ are predefine twice.
Fix this by removing the old definition, based on the size of these
types on the machine where sparse was compiled.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
lib.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/lib.c b/lib.c
index cf6bea645..20eb72e95 100644
--- a/lib.c
+++ b/lib.c
@@ -1072,11 +1072,7 @@ void create_builtin_stream(void)
/* GCC defines these for limits.h */
add_pre_buffer("#weak_define __SHRT_MAX__ " STRINGIFY(__SHRT_MAX__) "\n");
add_pre_buffer("#weak_define __SCHAR_MAX__ " STRINGIFY(__SCHAR_MAX__) "\n");
- add_pre_buffer("#weak_define __INT_MAX__ " STRINGIFY(__INT_MAX__) "\n");
- add_pre_buffer("#weak_define __LONG_MAX__ " STRINGIFY(__LONG_MAX__) "\n");
- add_pre_buffer("#weak_define __LONG_LONG_MAX__ " STRINGIFY(__LONG_LONG_MAX__) "\n");
add_pre_buffer("#weak_define __WCHAR_MAX__ " STRINGIFY(__WCHAR_MAX__) "\n");
- add_pre_buffer("#weak_define __SIZEOF_POINTER__ " STRINGIFY(__SIZEOF_POINTER__) "\n");
add_pre_buffer("#weak_define __CHAR_BIT__ " STRINGIFY(__CHAR_BIT__) "\n");
}
--
2.13.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] fix definition of __SCHAR_MAX__ & friends
2017-05-19 11:20 [PATCH 0/3] use internal size for __INT_MAX__ & friends Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 1/3] fix hardcoded size of wide chars Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 2/3] avoid to redefine __INT_MAX__ and friends Luc Van Oostenryck
@ 2017-05-19 11:20 ` Luc Van Oostenryck
2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2017-05-19 11:20 UTC (permalink / raw)
To: linux-sparse; +Cc: Luc Van Oostenryck
The predefined macros __SCHAR_MAX__, __SHRT_MAX__, __WCHAR_MAX__ &
__CHAR_BIT__ are defined based on the size of these types on
the machine where sparse was compiled.
But since sparse has flags like -m32/-m64 and it's not unlikely
to have one day a flag like -march=<some arch>, better to use
the used by sparse for these types as stored in 'bits_in_char',
'bits_in_short', ...
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
lib.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/lib.c b/lib.c
index 20eb72e95..99ecdcc4a 100644
--- a/lib.c
+++ b/lib.c
@@ -832,11 +832,16 @@ static void predefined_sizeof(const char *name, unsigned bits)
add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8);
}
-static void predefined_type_size(const char *name, const char *suffix, unsigned bits)
+static void predefined_max(const char *name, const char *suffix, unsigned bits)
{
unsigned long long max = (1ULL << (bits - 1 )) - 1;
add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
+}
+
+static void predefined_type_size(const char *name, const char *suffix, unsigned bits)
+{
+ predefined_max(name, suffix, bits);
predefined_sizeof(name, bits);
}
@@ -845,6 +850,10 @@ static void predefined_macros(void)
add_pre_buffer("#define __CHECKER__ 1\n");
predefined_sizeof("SHORT", bits_in_short);
+ predefined_max("SHRT", "", bits_in_short);
+ predefined_max("SCHAR", "", bits_in_char);
+ predefined_max("WCHAR", "", bits_in_wchar);
+ add_pre_buffer("#weak_define __CHAR_BIT__ %d\n", bits_in_char);
predefined_type_size("INT", "", bits_in_int);
predefined_type_size("LONG", "L", bits_in_long);
@@ -1068,12 +1077,6 @@ void create_builtin_stream(void)
add_pre_buffer("#define __OPTIMIZE__ 1\n");
if (optimize_size)
add_pre_buffer("#define __OPTIMIZE_SIZE__ 1\n");
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-19 11:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-19 11:20 [PATCH 0/3] use internal size for __INT_MAX__ & friends Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 1/3] fix hardcoded size of wide chars Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 2/3] avoid to redefine __INT_MAX__ and friends Luc Van Oostenryck
2017-05-19 11:20 ` [PATCH 3/3] fix definition of __SCHAR_MAX__ & friends Luc Van Oostenryck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).