aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2013-04-18 12:14:30 -0700
committerChristopher Li <sparse@chrisli.org>2013-04-21 20:55:05 -0700
commitf022d1c8b777af93ef25205cbc34cb6b64c698a7 (patch)
treef7a2991a2fccbfee7b705b49f3e3351ce8cb3f83
parent3b1e38c703f8a3daea26b7d201442d8e74bbe199 (diff)
downloadsparse-f022d1c8b777af93ef25205cbc34cb6b64c698a7.tar.gz
Define __SIZEOF_POINTER__
GCC defines a macro __SIZEOF_POINTER__ to the size of a pointer in bytes. Define it in sparse as well. Signed-off-by: Josh Triplett <josh@joshtriplett.org> Signed-off-by: Christopher Li <sparse@chrisli.org>
-rwxr-xr-xcgcc15
-rw-r--r--lib.c1
2 files changed, 11 insertions, 5 deletions
diff --git a/cgcc b/cgcc
index 6636cc65..c075e5f1 100755
--- a/cgcc
+++ b/cgcc
@@ -240,27 +240,32 @@ sub add_specs {
return (' -Di386=1 -D__i386=1 -D__i386__=1' .
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 21, [24,8], [53,11], [64,15]) .
- &define_size_t ($m64 ? "long unsigned int" : "unsigned int"));
+ &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
+ ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'sparc') {
return (' -Dsparc=1 -D__sparc=1 -D__sparc__=1' .
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
- &define_size_t ($m64 ? "long unsigned int" : "unsigned int"));
+ &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
+ ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'sparc64') {
return (' -Dsparc=1 -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
&integer_types (8, 16, 32, 64, 64, 128) .
&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
- &define_size_t ("long unsigned int"));
+ &define_size_t ("long unsigned int") .
+ ' -D__SIZEOF_POINTER__=8');
} elsif ($spec eq 'x86_64') {
return (' -Dx86_64=1 -D__x86_64=1 -D__x86_64__=1' . ($m32 ? '' : ' -D__LP64__=1') .
&integer_types (8, 16, 32, $m32 ? 32 : 64, 64, 128) .
&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
- &define_size_t ($m32 ? "unsigned int" : "long unsigned int"));
+ &define_size_t ($m32 ? "unsigned int" : "long unsigned int") .
+ ' -D__SIZEOF_POINTER__=' . ($m32 ? '4' : '8'));
} elsif ($spec eq 'ppc') {
return (' -D__powerpc__=1 -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
&float_types (1, 1, 21, [24,8], [53,11], [113,15]) .
- &define_size_t ($m64 ? "long unsigned int" : "unsigned int"));
+ &define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
+ ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
} elsif ($spec eq 'host_os_specs') {
my $os = `uname -s`;
chomp $os;
diff --git a/lib.c b/lib.c
index 8e2e0429..7e822eb7 100644
--- a/lib.c
+++ b/lib.c
@@ -892,6 +892,7 @@ void create_builtin_stream(void)
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");
}
static struct symbol_list *sparse_tokenstream(struct token *token)