Files
mercury/tests/hard_coded/redoip_clobber.m
Peter Wang 88047bbb45 Delete Erlang from tests.
tests/general/float_test.exp3:
tests/general/float_test.m:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
tests/hard_coded/remove_file.exp2:
tests/hard_coded/remove_file.m:
    Delete Erlang backend specific expected outputs.

tests/hard_coded/Mmakefile:
tests/hard_coded/erlang_deconstruct.exp:
tests/hard_coded/erlang_deconstruct.m:
tests/hard_coded/existential_list.exp:
tests/hard_coded/existential_list.m:
tests/valid/Mmakefile:
tests/valid/erl_ite_vars.m:
tests/valid/zf_erlang_bug.m:
    Delete erlang target specific tests.

tests/*:
    Delete Erlang foreign procs and foreign types.
2020-10-27 11:10:11 +11:00

86 lines
2.1 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% This is a regression test for a code generation bug, fixed
% on 16 november 1999.
%
% The bug was that if the failure continuation was a known address,
% the code in code_info.m for implementing commits assumed that the
% redoip slot of the top nondet stack frame had this address in it,
% and that therefore it could override this slot without remembering
% what was originally in it.
%
% The determinism declarations of foo and bar are intentionally too loose;
% the bug does not reveal itself, even if it exists, with the correct, tight
% determinism declarations. The test for the bug also requires compilation
% with inlining turned off.
:- module redoip_clobber.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int.
:- import_module std_util.
:- pred foo(int).
:- mode foo(out) is nondet.
foo(X) :- bar(X), fail.
foo(X) :- X = 2.
:- pred bar(int).
:- mode bar(out) is nondet.
bar(X) :- X = 1.
:- pred use(int).
:- mode use(in) is semidet.
:- pragma foreign_proc("C",
use(X::in),
[will_not_call_mercury, promise_pure],
"
/*
** To exhibit the bug, this predicate needs only to fail.
** However, the symptom of the bug is an infinite loop.
** To detect the presence of the bug in finite time,
** we abort execution if this code is executed too many times.
**
** We mention X here to shut up a warning.
*/
static int counter = 0;
if (++counter > 100) {
MR_fatal_error(""the bug is back"");
}
SUCCESS_INDICATOR = MR_FALSE;
").
:- pragma foreign_proc("C#",
use(_X::in),
[will_not_call_mercury, promise_pure],
"
SUCCESS_INDICATOR = false;
").
:- pragma foreign_proc("Java",
use(_X::in),
[will_not_call_mercury, promise_pure],
"
SUCCESS_INDICATOR = false;
").
main(!IO) :-
( if foo(X), use(X) then
io.write_string("Succeeded.\n", !IO)
else
io.write_string("Failed.\n", !IO)
).