mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-30 08:44:37 +00:00
Branches: main
compiler/loop_inv.m:
Fix a bug. An `unused' variable in an invariant call was treated
like an output variable and added to the invariant variables list,
and hoisted.
tests/hard_coded/Mercury.options:
tests/hard_coded/loop_inv_test3.exp:
tests/hard_coded/loop_inv_test3.m:
Add test case.
51 lines
1.2 KiB
Mathematica
51 lines
1.2 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Regression test. Loop invariant hoisting incorrectly treated `unused'
|
|
% arguments in calls like outputs.
|
|
|
|
:- module loop_inv_test3.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int.
|
|
:- import_module list.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
loop(10, 10, [], L),
|
|
io.write(L, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred loop(int::in, int::in, list(int)::in, list(int)::out) is det.
|
|
|
|
loop(Factor, N, L0, L) :-
|
|
Value = foo(Factor, N1),
|
|
bar(N, N1),
|
|
( N1 = 0 ->
|
|
L = L0
|
|
;
|
|
L1 = [Factor * Value | L0],
|
|
loop(Factor, N - 1, L1, L)
|
|
).
|
|
|
|
:- func foo(int::in, int::unused) = (int::out) is det.
|
|
:- pragma no_inline(foo/2).
|
|
|
|
foo(F, _) = F.
|
|
|
|
:- pred bar(int::in, int::out) is det.
|
|
:- pragma no_inline(bar/2).
|
|
|
|
bar(N, N).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=8 sts=4 sw=4 et
|