diff: fix gcc warnings

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 6 03:34:31 AEDT 1998


Fix various gcc warnings.

library/std_util.m:
library/benchmarking.m:
extras/trailed_update/tests/func_trail_test.m:
extras/trailed_update/tests/func_trail_test_2.m:
	Add some casts -- without these, the code might not compile
	with compilers other than gcc.

library/private_builtin.m:
	Avoid the use of nested extern declarations, by moving
	the declarations out of the enclosing function.

runtime/mercury_array_macros.h:
	Initialize `element' in MR_bsearch().
	Without this, gcc reports lots of spurious warnings when
	compiling trace/*.c.

Index: extras/trailed_update/tests/func_trail_test.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/tests/func_trail_test.m,v
retrieving revision 1.1
diff -u -r1.1 func_trail_test.m
--- func_trail_test.m	1998/06/02 05:32:20	1.1
+++ func_trail_test.m	1998/11/05 16:17:28
@@ -98,11 +98,11 @@
 
 :- pragma c_code(enter(I::in), will_not_call_mercury, "
 	printf("">> enter (%d)\n"", (int) I);
-	MR_trail_function(leave_failing, I);
+	MR_trail_function(leave_failing, (void *) I);
 ").
 
 
 :- pragma c_code(leave(I::in), will_not_call_mercury, "
 	printf(""<< leave (%d)\n"", (int) I);
-	MR_trail_function(enter_failing, I);
+	MR_trail_function(enter_failing, (void *) I);
 ").
Index: extras/trailed_update/tests/func_trail_test_2.m
===================================================================
RCS file: /home/mercury1/repository/mercury/extras/trailed_update/tests/func_trail_test_2.m,v
retrieving revision 1.1
diff -u -r1.1 func_trail_test_2.m
--- func_trail_test_2.m	1998/06/02 05:32:23	1.1
+++ func_trail_test_2.m	1998/11/05 16:17:36
@@ -105,11 +105,11 @@
 
 :- pragma c_code(enter(I::in), will_not_call_mercury, "
 	printf("">> enter (%d)\n"", (int) I);
-	MR_trail_function(trace_fail, I);
+	MR_trail_function(trace_fail, (void *) I);
 ").
 
 
 :- pragma c_code(leave(I::in), will_not_call_mercury, "
 	printf(""<< leave (%d)\n"", (int) I);
-	MR_trail_function(trace_redo, I);
+	MR_trail_function(trace_redo, (void *) I);
 ").
Index: library/benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.18
diff -u -r1.18 benchmarking.m
--- benchmarking.m	1998/11/05 03:53:11	1.18
+++ benchmarking.m	1998/11/05 15:57:24
@@ -622,7 +622,7 @@
 	framevar(3) = 0;
 	mark_hp(framevar(5));
 #ifdef MR_USE_TRAIL
-	framevar(6) = MR_trail_ptr;
+	framevar(6) = (Word) MR_trail_ptr;
 #endif
 	framevar(4) = MR_get_user_cpu_miliseconds();
 
@@ -654,7 +654,7 @@
 	restore_hp(framevar(5));
 #ifdef MR_USE_TRAIL
 	/* ... and the trail pointer */
-	MR_trail_ptr = framevar(6);
+	MR_trail_ptr = (MR_TrailEntry *) framevar(6);
 #endif
 
 	/* are there any other iterations? */
@@ -717,7 +717,7 @@
 
 	incr_sp(BENCHMARK_DET_STACK_SLOTS);
 #ifdef MR_USE_TRAIL
-	detstackvar(7) = MR_trail_ptr;
+	detstackvar(7) = (Word) MR_trail_ptr;
 #endif
 	detstackvar(6) = (Word) succip;
 	mark_hp(detstackvar(5));
@@ -754,8 +754,9 @@
 		/* yes, so set up the call just like last time */
 #ifdef MR_USE_TRAIL
 		/* Restore the trail... */
-		MR_untrail_to(detstackvar(7), MR_undo);
-		MR_trail_ptr = detstackvar(7);
+		MR_TrailEntry *old_trail_ptr = (MR_TrailEntry *) detstackvar(7);
+		MR_untrail_to(old_trail_ptr, MR_undo);
+		MR_trail_ptr = old_trail_ptr;
 #endif
 		restore_hp(detstackvar(5));
 		r1 = detstackvar(1);
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.12
diff -u -r1.12 private_builtin.m
--- private_builtin.m	1998/11/05 03:53:17	1.12
+++ private_builtin.m	1998/11/05 15:47:48
@@ -1294,16 +1294,18 @@
 INIT sys_init_table_suspend_module
 INIT sys_init_table_resume_module
 */
+
+extern ModuleFunc table_suspend_module;
+extern ModuleFunc table_resume_module;
+
 void sys_init_table_suspend_module(void);
 	/* extra declaration to suppress gcc -Wmissing-decl warning */
 void sys_init_table_suspend_module(void) {
-	extern ModuleFunc table_suspend_module;
 	table_suspend_module();
 }
 void sys_init_table_resume_module(void);
 	/* extra declaration to suppress gcc -Wmissing-decl warning */
 void sys_init_table_resume_module(void) {
-	extern ModuleFunc table_resume_module;
 	table_resume_module();
 }
 
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.132
diff -u -r1.132 std_util.m
--- std_util.m	1998/11/05 03:53:20	1.132
+++ std_util.m	1998/11/05 15:45:33
@@ -2249,8 +2249,9 @@
                  * then we can just use the code for simple tags.
                  */
             data_value = (Word) ((Word *) data_value + 1);
-            entry_value = MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR(
-                entry_value, secondary_tag);
+            entry_value = (Word)
+	    	MR_TYPELAYOUT_COMPLICATED_VECTOR_GET_SIMPLE_VECTOR(
+		    entry_value, secondary_tag);
             entry_value = strip_tag(entry_value);
         }   /* fallthru */
 
Index: runtime/mercury_array_macros.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_array_macros.h,v
retrieving revision 1.1
diff -u -r1.1 mercury_array_macros.h
--- mercury_array_macros.h	1998/10/16 06:18:44	1.1
+++ mercury_array_macros.h	1998/11/05 16:05:55
@@ -150,6 +150,12 @@
 		int	hi;						\
 		int	diff;						\
 									\
+		/*							\
+		** We initialize `element' here only to avoid gcc	\
+		** warnings about possibly accessing an uninitialized	\
+		** variable in code using MR_bsearch().			\
+		*/							\
+		(element) = 0;						\
 		lo = 0;							\
 		hi = (next) - 1;					\
 		(found) = FALSE;					\

-- 
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.



More information about the developers mailing list