Fix bm_huge initialization for 64-bit targets (gctest)
authorIvan Maidanski <ivmai@mail.ru>
Thu, 22 Dec 2016 21:39:10 +0000 (00:39 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 22 Dec 2016 21:39:10 +0000 (00:39 +0300)
* tests/test.c (bm_huge): Make array size depend on word size
(5 elements for 64-bit targets); initialize elements (except the last
one) to -1 instead of 0xffffffff (so that all bits are ones even on
a 64-bit target); initialize last element to ((word)-1)>>8 instead of
0x00ffffff value.
* tests/test.c (typed_test): Fail if bm_huge descriptor contains wrong
bit values at certain positions (as it had before this fix).

tests/test.c

index ef70aef..7123bd1 100644 (file)
@@ -1065,17 +1065,19 @@ void tree_test(void)
 
 unsigned n_tests = 0;
 
-const GC_word bm_huge[10] = {
+const GC_word bm_huge[320 / CPP_WORDSZ] = {
+# if CPP_WORDSZ == 32
     0xffffffff,
     0xffffffff,
     0xffffffff,
     0xffffffff,
     0xffffffff,
-    0xffffffff,
-    0xffffffff,
-    0xffffffff,
-    0xffffffff,
-    0x00ffffff,
+# endif
+    (GC_signed_word)-1,
+    (GC_signed_word)-1,
+    (GC_signed_word)-1,
+    (GC_signed_word)-1,
+    ((GC_word)((GC_signed_word)-1)) >> 8 /* highest byte is zero */
 };
 
 /* A very simple test of explicitly typed allocation    */
@@ -1096,6 +1098,11 @@ void typed_test(void)
       (void)GC_make_descriptor(&bm_large, 32);
 #   endif
     collectable_count++;
+    if (GC_get_bit(bm_huge, 32) == 0 || GC_get_bit(bm_huge, 311) == 0
+        || GC_get_bit(bm_huge, 319) != 0) {
+      GC_printf("Bad GC_get_bit() or bm_huge initialization\n");
+      FAIL;
+    }
     old = 0;
     for (i = 0; i < 4000; i++) {
         collectable_count++;