Fix a compiler abort when generating code for determistic string

Estimated hours taken: 1
Branches: main

compiler/ml_string_switch.m:
	Fix a compiler abort when generating code for determistic string
	switches.

tests/valid/Mmakefile:
tests/valid/det_string_switch.m:
	Add test case.
This commit is contained in:
Peter Wang
2007-09-14 00:57:06 +00:00
parent 853622ad87
commit a6e28abc32
3 changed files with 51 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
%-----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%-----------------------------------------------------------------------------%
% Copyright (C) 1994-2006 The University of Melbourne.
% Copyright (C) 1994-2007 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
%-----------------------------------------------------------------------------%
@@ -103,7 +103,21 @@ generate(Cases, Var, CodeModel, _CanFail, Context, Decls, Statements, !Info) :-
switch_util.calc_hash_slots(HashValsList, HashValsMap, HashSlotsMap),
% Generate the code for when the hash lookup fails.
ml_gen_failure(CodeModel, Context, FailStatements, !Info),
(
CodeModel = model_det,
FailComment =
statement(ml_stmt_atomic(comment("switch cannot fail")),
MLDS_Context),
FailStatements = []
;
( CodeModel = model_semi
; CodeModel = model_non
),
FailComment =
statement(ml_stmt_atomic(comment("no match, so fail")),
MLDS_Context),
ml_gen_failure(CodeModel, Context, FailStatements, !Info)
),
% Generate the code etc. for the hash table.
gen_hash_slots(0, TableSize, HashSlotsMap, CodeModel,
@@ -196,9 +210,6 @@ generate(Cases, Var, CodeModel, _CanFail, Context, Decls, Statements, !Info) :-
yes), % This is a do...while loop.
MLDS_Context)
],
FailComment =
statement(ml_stmt_atomic(comment("no match, so fail")),
MLDS_Context),
EndLabelStatement = statement(ml_stmt_label(EndLabel), MLDS_Context),
EndComment =
statement(ml_stmt_atomic(comment("end of hashed string switch")),

View File

@@ -75,6 +75,7 @@ OTHER_PROGS= \
deforest_rerun_det \
det_condition \
det_inference \
det_string_switch \
det_switch \
double_vn \
easy_nondet_test \

View File

@@ -0,0 +1,34 @@
% This is a regression test for a bug in MLDS code generation where it would
% abort while generating the code of a deterministic string switch.
%
% Uncaught Mercury exception:
% Software Error: ml_code_util.m: Unexpected: ml_gen_failure: `fail' has determinism `det'
:- module det_string_switch.
:- interface.
:- import_module io.
% Need this many cases to make a string switch.
:- inst bar
---> "a"
; "b"
; "c"
; "d"
; "e"
; "f"
; "g"
; "h".
:- pred foo(string::in(bar), io::di, io::uo) is det.
:- implementation.
foo("a", !IO).
foo("b", !IO).
foo("c", !IO).
foo("d", !IO).
foo("e", !IO).
foo("f", !IO).
foo("g", !IO).
foo("h", !IO).