[m-rev.] for review: fix a bug in unused argument elimination

Peter Wang wangp at students.cs.mu.OZ.AU
Wed Jan 4 11:22:54 AEDT 2006


Estimated hours taken: 3
Branches: main

compiler/unused_args.m:
	Fix a bug when unused argument elimination was enabled with
	intermodule analysis that caused an exception in the MLDS code
	generator.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/intermod_unused_args.exp:
tests/hard_coded/intermod_unused_args.m:
tests/hard_coded/intermod_unused_args2.m:
	Add a test case.

Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.115
diff -u -r1.115 unused_args.m
--- compiler/unused_args.m	12 Dec 2005 02:54:36 -0000	1.115
+++ compiler/unused_args.m	23 Dec 2005 02:46:48 -0000
@@ -1172,10 +1172,10 @@
     % Assign the old procedure to a new predicate.
     proc_info_headvars(ProcInfo0, HeadVars0),
     remove_listof_elements(1, UnusedArgs, HeadVars0, HeadVars),
-    proc_info_set_headvars(HeadVars, ProcInfo0, HeadVarsProcInfo),
-    proc_info_argmodes(HeadVarsProcInfo, ArgModes0),
+    proc_info_set_headvars(HeadVars, ProcInfo0, ProcInfo1),
+    proc_info_argmodes(ProcInfo1, ArgModes0),
     remove_listof_elements(1, UnusedArgs, ArgModes0, ArgModes),
-    proc_info_set_argmodes(ArgModes, ProcInfo0, ProcInfo),
+    proc_info_set_argmodes(ArgModes, ProcInfo1, ProcInfo),
     map__set(NewProcs0, ProcId, ProcInfo, NewProcs),
     pred_info_set_procedures(NewProcs, NewPredInfo0, NewPredInfo),
 
Index: tests/hard_coded/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mercury.options,v
retrieving revision 1.14
diff -u -r1.14 Mercury.options
--- tests/hard_coded/Mercury.options	3 Nov 2005 07:03:16 -0000	1.14
+++ tests/hard_coded/Mercury.options	23 Dec 2005 03:46:38 -0000
@@ -25,6 +25,8 @@
 MCFLAGS-intermod_type_qual2 =	--intermodule-optimization
 MCFLAGS-intermod_multimode =	--intermodule-optimization
 MCFLAGS-intermod_multimode_main = --intermodule-optimization
+MCFLAGS-intermod_unused_args =	--intermodule-analysis --optimise-unused-args
+MCFLAGS-intermod_unused_args2 =	--intermodule-analysis --optimise-unused-args
 MCFLAGS-loop_inv_test 	= 	--loop-invariants --trace-optimized
 MCFLAGS-loop_inv_test0 	= 	--loop-invariants --trace-optimized
 MCFLAGS-loop_inv_test1 	= 	--loop-invariants --trace-optimized
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.276
diff -u -r1.276 Mmakefile
--- tests/hard_coded/Mmakefile	28 Nov 2005 02:30:35 -0000	1.276
+++ tests/hard_coded/Mmakefile	23 Dec 2005 03:47:58 -0000
@@ -110,6 +110,7 @@
 	intermod_poly_mode \
 	intermod_pragma_clause \
 	intermod_type_qual \
+	intermod_unused_args \
 	int_fold_up_down \
 	join_list \
 	list_series_int \
@@ -567,6 +568,10 @@
 	grep 1234 $@
 	grep '5678\.0' $@
 
+# Force intermod_unused_args2.m to be compiled and analysed before
+# intermod_unused_args.m.
+intermod_unused_args.c: intermod_unused_args2.c
+
 #-----------------------------------------------------------------------------#
 
 dir_test.out: prepare_for_dir_test
Index: tests/hard_coded/intermod_unused_args.exp
===================================================================
RCS file: tests/hard_coded/intermod_unused_args.exp
diff -N tests/hard_coded/intermod_unused_args.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/intermod_unused_args.exp	23 Dec 2005 03:03:51 -0000
@@ -0,0 +1 @@
+4
Index: tests/hard_coded/intermod_unused_args.m
===================================================================
RCS file: tests/hard_coded/intermod_unused_args.m
diff -N tests/hard_coded/intermod_unused_args.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/intermod_unused_args.m	23 Dec 2005 03:06:26 -0000
@@ -0,0 +1,17 @@
+% In grades using the MLDS this threw the exception
+%
+% Software Error: ml_code_util.m: Unexpected: ml_gen_arg_decls: length mismatch
+
+:- module intermod_unused_args.
+
+:- interface.
+:- import_module io.
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+:- import_module intermod_unused_args2.
+
+main(!IO) :-
+    callee(1,2,3,X),
+    io.print(X,!IO),
+    io.nl(!IO).
Index: tests/hard_coded/intermod_unused_args2.m
===================================================================
RCS file: tests/hard_coded/intermod_unused_args2.m
diff -N tests/hard_coded/intermod_unused_args2.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/intermod_unused_args2.m	23 Dec 2005 02:53:01 -0000
@@ -0,0 +1,7 @@
+:- module intermod_unused_args2.
+:- interface.
+:- pred callee(int::in, int::in, int::in, int::out) is det.
+
+:- implementation.
+:- pragma no_inline(callee/4).
+callee(_,_,_,4).
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list