[m-dev.] diff: fixes for bugs in RTTI changes

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Mar 18 19:09:46 AEDT 2000


Estimated hours taken: 1

Fix some bugs and compiler warnings introduced in Zoltan's recent change.

runtime/mercury_tabling.c:
	Fix some bugs:
	- in many places, `type_ctor_layout' was being used when it
	  was uninitialized;
	- in one place, `data_value' was being used when it was uninitialized;
	- one of the calls to MR_deallocate() was misplaced in unreachable
	  code (following the break in the last case of a switch,
	  rather than following the switch).

	Also simplify the code a little: typeinfos, univs, and closures
	are all represented by untagged pointers, so we don't need
	to strip off the tag in those cases.

runtime/mercury_tabling.c:
runtime/mercury_deep_copy_body.h:
	Add default cases to some switches, to avoid spurious
	warnings from gcc and to ensure that we catch invalid data.

Workspace: /home/mercury0/fjh/mercury-other
Index: runtime/mercury_deep_copy_body.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_deep_copy_body.h,v
retrieving revision 1.19
diff -u -d -b -r1.19 mercury_deep_copy_body.h
--- runtime/mercury_deep_copy_body.h	2000/03/10 13:38:10	1.19
+++ runtime/mercury_deep_copy_body.h	2000/03/18 08:02:59
@@ -198,7 +198,9 @@
 
                 break;
                 }
-            }
+	    default:
+	        fatal_error("copy(): unknown tag representation");
+            } /* end switch */
         } else {
             MR_DuPtagLayout     *ptag_layout;
             int                 ptag;
@@ -435,7 +437,11 @@
                     found_forwarding_pointer(data);
                 }
                 break;
-            }
+
+	    default:
+	    	fatal_error("copy(): unknown sectag_locn");
+
+            } /* end switch on sectag_locn */
         }
         break;
 
Index: runtime/mercury_tabling.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_tabling.c,v
retrieving revision 1.22
diff -u -d -b -r1.22 mercury_tabling.c
--- runtime/mercury_tabling.c	2000/03/10 13:38:12	1.22
+++ runtime/mercury_tabling.c	2000/03/18 07:45:52
@@ -626,16 +626,13 @@
         case MR_TYPECTOR_REP_ENUM: 
         case MR_TYPECTOR_REP_ENUM_USEREQ: 
             if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
-                MR_TypeCtorLayout   type_ctor_layout;
                 Word                layout_for_tag;
                 Word                *layout_vector_for_tag;
                 int                 data_tag;
                 int                 functors;
 
                 data_tag = MR_tag(data);
-                type_ctor_layout = type_ctor_info->type_ctor_layout;
-
-                layout_for_tag = type_ctor_layout[data_tag];
+                layout_for_tag = type_ctor_info->type_ctor_layout[data_tag];
                 layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
                 functors = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
                                     layout_vector_for_tag);
@@ -650,21 +647,20 @@
         case MR_TYPECTOR_REP_DU_USEREQ: 
             if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
                 MR_DiscUnionTagRepresentation tag_rep;
-                MR_TypeCtorLayout   type_ctor_layout;
                 MR_MemoryList       allocated_memory_cells = NULL;
                 Word                layout_for_tag;
                 Word                *layout_vector_for_tag;
-                Word                *data_value;
                 int                 data_tag;
 
                 data_tag = MR_tag(data);
-                layout_for_tag = type_ctor_layout[data_tag];
+                layout_for_tag = type_ctor_info->type_ctor_layout[data_tag];
                 layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
                 tag_rep = MR_get_tag_representation((Word) layout_for_tag);
 
                 switch(tag_rep) {
                 case MR_DISCUNIONTAG_SHARED_LOCAL: {
-                    int functors = MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
+                        int functors =
+				MR_TYPE_CTOR_LAYOUT_ENUM_VECTOR_NUM_FUNCTORS(
                                     layout_vector_for_tag);
                     MR_DEBUG_TABLE_TAG(table, data_tag);
                     MR_DEBUG_TABLE_ENUM(table, functors, MR_unmkbody(data));
@@ -705,6 +701,7 @@
                     Word    secondary_tag;
                     Word    num_sharers;
                     Word    *new_layout_vector;
+                        Word    *data_value;
 
                     data_value = (Word *) MR_body(data, data_tag);
                     secondary_tag = *data_value;
@@ -734,9 +731,10 @@
                     }
                     break;
                 }
+                } /* end switch(tag_rep) */
 
                 MR_deallocate(allocated_memory_cells);
-                }
+
             } else {
                 MR_MemoryList           allocated_memory_cells = NULL;
                 const MR_DuPtagLayout   *ptag_layout;
@@ -769,6 +767,8 @@
                     functor_desc = ptag_layout->MR_sectag_alternatives[sectag];
                     arg_vector = (Word *) MR_body(data, ptag) + 1;
                     break;
+		default:
+		    fatal_error("MR_table_type(): unknown sectag_locn");
                 }
 
                 MR_DEBUG_TABLE_ENUM(table,
@@ -815,7 +815,6 @@
         case MR_TYPECTOR_REP_NOTAG: 
         case MR_TYPECTOR_REP_NOTAG_USEREQ:
             if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
-                MR_TypeCtorLayout   type_ctor_layout;
                 MR_MemoryList       allocated_memory_cells = NULL;
                 Word                layout_for_tag;
                 Word                *layout_vector_for_tag;
@@ -823,7 +822,7 @@
                 Word                *new_type_info;
 
                 data_tag = MR_tag(data);
-                layout_for_tag = type_ctor_layout[data_tag];
+                layout_for_tag = type_ctor_info->type_ctor_layout[data_tag];
                 layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
                 new_type_info = MR_make_type_info(type_info,
                     (Word *) *MR_TYPE_CTOR_LAYOUT_NO_TAG_VECTOR_ARGS(
@@ -851,7 +850,6 @@
 
         case MR_TYPECTOR_REP_EQUIV:
             if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
-                MR_TypeCtorLayout   type_ctor_layout;
                 MR_MemoryList       allocated_memory_cells = NULL;
                 Word                layout_for_tag;
                 Word                *layout_vector_for_tag;
@@ -859,7 +857,7 @@
                 Word                *new_type_info;
 
                 data_tag = MR_tag(data);
-                layout_for_tag = type_ctor_layout[data_tag];
+                layout_for_tag = type_ctor_info->type_ctor_layout[data_tag];
                 layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
                 new_type_info = MR_make_type_info(type_info, (Word *)
                     MR_TYPE_CTOR_LAYOUT_EQUIV_TYPE(layout_vector_for_tag),
@@ -885,13 +883,12 @@
 
         case MR_TYPECTOR_REP_EQUIV_VAR:
             if (type_ctor_info->type_ctor_version <= MR_RTTI_VERSION__USEREQ) {
-                MR_TypeCtorLayout   type_ctor_layout;
                 Word                layout_for_tag;
                 Word                *layout_vector_for_tag;
                 int                 data_tag;
 
                 data_tag = MR_tag(data);
-                layout_for_tag = type_ctor_layout[data_tag];
+                layout_for_tag = type_ctor_info->type_ctor_layout[data_tag];
                 layout_vector_for_tag = (Word *) MR_strip_tag(layout_for_tag);
                 MR_DEBUG_TABLE_ANY(table,
                     (Word *) type_info[(Word) layout_vector_for_tag], data);
@@ -927,7 +924,7 @@
             ** of figuring out the closure argument types.
             */
     #if 0
-            MR_closure  closure = (MR_Closure *) data_value;
+            MR_closure  closure = (MR_Closure *) data;
             Word        num_hidden_args = closure->MR_closure_num_hidden_args;
             int         i;
 
@@ -942,22 +939,14 @@
             ** Instead, we use the following rather simplistic means of
             ** tabling closures: we just table based on the closure address.
             */
-            Word    *data_value;
-            int     data_tag;
-
-            data_tag = MR_tag(data);
-            data_value = (Word *) MR_body(data, data_tag);
-            MR_DEBUG_TABLE_INT(table, (Word) data_value);
+            MR_DEBUG_TABLE_INT(table, data);
     #endif
             break;
         }
         case MR_TYPECTOR_REP_UNIV: {
             Word    *data_value;
-            int     data_tag;
 
-            data_tag = MR_tag(data);
-            data_value = (Word *) MR_body(data, data_tag);
-
+	    data_value = (Word *) data;
             MR_DEBUG_TABLE_TYPEINFO(table,
                 (Word *) data_value[UNIV_OFFSET_FOR_TYPEINFO]);
             MR_DEBUG_TABLE_ANY(table,
@@ -975,12 +964,7 @@
             break;
 
         case MR_TYPECTOR_REP_TYPEINFO: {
-            Word    *data_value;
-            int     data_tag;
-
-            data_tag = MR_tag(data);
-            data_value = (Word *) MR_body(data, data_tag);
-            MR_DEBUG_TABLE_TYPEINFO(table, (Word *) data_value);
+            MR_DEBUG_TABLE_TYPEINFO(table, (Word *) data);
             break;
         }
 
@@ -990,13 +974,12 @@
 
         case MR_TYPECTOR_REP_ARRAY: {
             MR_MemoryList   allocated_memory_cells = NULL;
-            Word            *data_value;
             int             i;
             MR_ArrayType    *array;
             Word            *new_type_info;
             Integer         array_size;
 
-            array = (MR_ArrayType *) data_value;
+            array = (MR_ArrayType *) data;
             array_size = array->size;
 
             new_type_info = MR_make_type_info(type_info, (Word *) 1,
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list