[m-rev.] diff: fix bug #145

Peter Wang novalazy at gmail.com
Wed Apr 21 14:57:36 AEST 2010


Branches: main, 10.04

Fix bug #145.

compiler/loop_inv.m:
        Fix a bug wherein the variable holding the higher order term being
        called was not considered a goal input.  Hence the goal may be
        incorrectly considered loop-invariant.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/loop_inv_test4.exp:
tests/hard_coded/loop_inv_test4.m:
        Add test case.

        Enable loop_inv_test3 which seems to have been left out accidentally.

diff --git a/compiler/loop_inv.m b/compiler/loop_inv.m
index 7961854..cfdec28 100644
--- a/compiler/loop_inv.m
+++ b/compiler/loop_inv.m
@@ -121,6 +121,7 @@
 :- import_module check_hlds.inst_util.
 :- import_module check_hlds.mode_util.
 :- import_module hlds.code_model.
+:- import_module hlds.goal_util.
 :- import_module hlds.hlds_goal.
 :- import_module hlds.instmap.
 :- import_module hlds.quantification.
@@ -1143,9 +1144,11 @@ goal_inputs(ModuleInfo, Goal) = Inputs :-
         Inputs = list.filter_map_corresponding(input_arg(ModuleInfo),
             Args, argmodes(ModuleInfo, PredId, ProcId))
     ;
-        GoalExpr = generic_call(_, Args, ArgModes, _),
-        Inputs = list.filter_map_corresponding(input_arg(ModuleInfo),
-            Args, ArgModes)
+        GoalExpr = generic_call(GenericCall, Args, ArgModes, _),
+        generic_call_vars(GenericCall, GenericCallVars),
+        Inputs0 = list.filter_map_corresponding(input_arg(ModuleInfo),
+            Args, ArgModes),
+        Inputs = GenericCallVars ++ Inputs0
     ;
         GoalExpr = call_foreign_proc(_, PredId, ProcId, ForeignArgs, _, _, _),
         Inputs = list.filter_map_corresponding(input_arg(ModuleInfo),
diff --git a/tests/hard_coded/Mercury.options b/tests/hard_coded/Mercury.options
index 115880c..efdd552 100644
--- a/tests/hard_coded/Mercury.options
+++ b/tests/hard_coded/Mercury.options
@@ -60,7 +60,8 @@ MCFLAGS-loop_inv_test 	= 	--loop-invariants --trace-optimized
 MCFLAGS-loop_inv_test0 	= 	--loop-invariants --trace-optimized
 MCFLAGS-loop_inv_test1 	= 	--loop-invariants --trace-optimized
 MCFLAGS-loop_inv_test2 	= 	--loop-invariants --trace-optimized
-MCFLAGS-loop_inv_test3 	= 	--loop-invariants --trace-optimized
+MCFLAGS-loop_inv_test3 	= 	--loop-invariants
+MCFLAGS-loop_inv_test4 	= 	--loop-invariants
 MCFLAGS-prince_frameopt = 		--intermodule-optimization -O5
 MCFLAGS-prince_frameopt_css = 		--intermodule-optimization -O5
 MCFLAGS-prince_frameopt_css.style = 	--intermodule-optimization -O5
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 19b70bd..b3d0c92 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -151,6 +151,8 @@ ORDINARY_PROGS=	\
 	lookup_switch_simple_opt \
 	loop_inv_test \
 	loop_inv_test1 \
+	loop_inv_test3 \
+	loop_inv_test4 \
 	map_fold \
 	mapped_module \
 	merge_and_remove_dups \
diff --git a/tests/hard_coded/loop_inv_test4.exp
b/tests/hard_coded/loop_inv_test4.exp
new file mode 100644
index 0000000..62d6c89
--- /dev/null
+++ b/tests/hard_coded/loop_inv_test4.exp
@@ -0,0 +1,3 @@
+6
+5
+4
diff --git a/tests/hard_coded/loop_inv_test4.m
b/tests/hard_coded/loop_inv_test4.m
new file mode 100644
index 0000000..6d3c9b1
--- /dev/null
+++ b/tests/hard_coded/loop_inv_test4.m
@@ -0,0 +1,38 @@
+%-----------------------------------------------------------------------------%
+% Regression test.  The variable holding the higher order term being called was
+% not considered a goal input.  Hence the goal may be incorrectly considered
+% loop-invariant.
+
+:- module loop_inv_test4.
+:- interface.
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list.
+:- import_module int.
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+    List = [int.plus, int.times, int.minus],
+    use_list(List, !IO).
+
+:- type myfunc == (func(int, int) = int).
+
+:- pred use_list(list(myfunc)::in, io::di, io::uo) is det.
+
+use_list([], !IO).
+use_list([P | Ps], !IO) :-
+    X = P(5, 1),
+    io.write_int(X, !IO),
+    io.write_string("\n", !IO),
+    use_list(Ps, !IO).
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=8 sts=4 sw=4 et
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list