for review: solutions/2 bug fix

Fergus Henderson fjh at kryten.cs.mu.OZ.AU
Fri Mar 7 07:01:34 AEDT 1997


Hi Tyson,

Can you please review this one?

Fix a bug in the implementation of solutions/2 that caused
tests/hard_coded/ho_solns.m to fail in grades `fast' and `asm_fast' on
SPARCs.

library/std_util.m:
	Assign the result of deep_copy() to a C local variable, rather
	than to a Mercury register, because the immediately following
	call to restore_transient_registers() can clobber Mercury registers.

Index: std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.73
diff -u -r1.73 std_util.m
--- 1.73	1997/02/23 01:13:55
+++ std_util.m	1997/03/06 19:57:18
@@ -243,9 +243,9 @@
 */
 
 #ifdef	COMPACT_ARGS
-#define	solutions_output	r1
+  #define solutions_output_reg	r1
 #else
-#define	solutions_output	r3
+  #define solutions_output_reg	r3
 #endif
 
 Define_entry(mercury__std_util__builtin_solutions_2_0);
@@ -319,6 +319,8 @@
 {
 	/* we found a solution (in r1) */
 
+	Word solution_copy;
+
 	/* save the current heap pointer */
 	Word *temp_hp = hp;
 
@@ -331,12 +333,12 @@
 	** is transient, before/after calling deep_copy().
 	*/
 	save_transient_registers();
-	r3 = deep_copy(r1, (Word *) type_info_fv, (Word *) saved_hp_fv, 
-		heap_zone->top);
+	solution_copy = deep_copy(r1, (Word *) type_info_fv,
+				(Word *) saved_hp_fv, heap_zone->top);
 	restore_transient_registers();
 
 	/* create a cons cell on the solutions heap */
-	list_fv = list_cons(r3, list_fv);
+	list_fv = list_cons(solution_copy, list_fv);
 
 	/* save solutions heap pointer */
 	solutions_heap_pointer = (Word *) hp;
@@ -359,6 +361,7 @@
 	      of the solutions */
 
 	  Word* new_type_info[2];
+	  Word solutions_copy;
 	 
 	  new_type_info[0] = (Word *) (Word)
 	  	&mercury_data_mercury_builtin__base_type_info_list_1;
@@ -372,9 +375,11 @@
 	  ** is transient, before/after calling deep_copy().
 	  */
 	  save_transient_registers();
-	  solutions_output = deep_copy(list_fv, (Word *) new_type_info,
+	  solutions_copy = deep_copy(list_fv, (Word *) new_type_info,
 		(Word *) saved_solhp_fv, solutions_heap_zone->top);
 	  restore_transient_registers();
+
+	  solutions_output_reg = solutions_copy;
 	}
 
 	/* reset solutions heap to where it was before call to solutions  */
@@ -422,7 +427,7 @@
 Define_label(mercury__std_util__builtin_solutions_2_0_i2);
 	/* no more solutions */
 	/* return the solutions list and discard the frame we made */
-	solutions_output = framevar(0);
+	solutions_output_reg = framevar(0);
 	succeed_discard();
 
 #endif

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