mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 04:44:39 +00:00
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:
@@ -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")),
|
||||
|
||||
@@ -75,6 +75,7 @@ OTHER_PROGS= \
|
||||
deforest_rerun_det \
|
||||
det_condition \
|
||||
det_inference \
|
||||
det_string_switch \
|
||||
det_switch \
|
||||
double_vn \
|
||||
easy_nondet_test \
|
||||
|
||||
34
tests/valid/det_string_switch.m
Normal file
34
tests/valid/det_string_switch.m
Normal 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).
|
||||
Reference in New Issue
Block a user