aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2012-04-16 01:13:25 +0200
committerMichael Matz <matz@suse.de>2012-04-18 20:57:14 +0200
commit718fd591fa93ff254a9ca68a0ad2ff8a55756489 (patch)
tree69ef5bb9cdfa3673317df44c8ba402526e758ef8 /tests
parentb068e29df753192bdcec5b1e41401bdc21812136 (diff)
downloadtinycc-718fd591fa93ff254a9ca68a0ad2ff8a55756489.tar.gz
tinycc-718fd591fa93ff254a9ca68a0ad2ff8a55756489.tar.bz2
Make sizeof() be of type size_t
This matters when sizeof is directly used in arithmetic, ala "uintptr_t t; t &= -sizeof(long)" (for alignment). When sizeof isn't size_t (as it's specified to be) this masking will truncate the high bits of the uintptr_t object (if uintptr_t is larger than uint).
Diffstat (limited to 'tests')
-rw-r--r--tests/tcctest.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c
index eeabb7c..9598fa4 100644
--- a/tests/tcctest.c
+++ b/tests/tcctest.c
@@ -2155,6 +2155,8 @@ void c99_vla_test(int size1, int size2)
#endif
}
+typedef __SIZE_TYPE__ uintptr_t;
+
void sizeof_test(void)
{
int a;
@@ -2175,6 +2177,20 @@ void sizeof_test(void)
ptr = NULL;
printf("sizeof(**ptr) = %d\n", sizeof (**ptr));
+ /* The type of sizeof should be as large as a pointer, actually
+ it should be size_t. */
+ printf("sizeof(sizeof(int) = %d\n", sizeof(sizeof(int)));
+ uintptr_t t = 1;
+ uintptr_t t2;
+ /* Effectively <<32, but defined also on 32bit machines. */
+ t <<= 16;
+ t <<= 16;
+ t++;
+ /* This checks that sizeof really can be used to manipulate
+ uintptr_t objects, without truncation. */
+ t2 = t & -sizeof(uintptr_t);
+ printf ("%lu %lu\n", t, t2);
+
/* some alignof tests */
printf("__alignof__(int) = %d\n", __alignof__(int));
printf("__alignof__(unsigned int) = %d\n", __alignof__(unsigned int));