[m-rev.] for review: Fix compiler abort during liveness detection.
Peter Wang
novalazy at gmail.com
Wed Sep 4 14:12:57 AEST 2013
[I'm not certain of the fix]
The compiler would abort during liveness detection on an if-then-else goal
with an unreachable Then branch, due to the Then goal not having its
liveness-related fields initialised. Bug #51.
compiler/liveness.m:
As above.
tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/bug51.m:
Add test case.
NEWS:
Announce the change.
---
NEWS | 1 +
compiler/liveness.m | 4 +++-
tests/valid/Mercury.options | 1 +
tests/valid/Mmakefile | 1 +
tests/valid/bug51.m | 56 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 62 insertions(+), 1 deletion(-)
create mode 100644 tests/valid/bug51.m
diff --git a/NEWS b/NEWS
index b7979b9..29f21ca 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ This is a bug-fix release.
* We have added a workaround for a problem that was preventing the
asm_fast grades working with GCC 4.8. (Bug #293)
* Fix inst for constant type_infos. (Bug #297)
+* Fix compiler abort during liveness detection. (Bug #51)
NEWS for Mercury 13.05.1
diff --git a/compiler/liveness.m b/compiler/liveness.m
index e077a87..9e99ea7 100644
--- a/compiler/liveness.m
+++ b/compiler/liveness.m
@@ -443,7 +443,9 @@ detect_liveness_in_goal(Goal0, Goal, Liveness0, FinalLiveness, LiveInfo) :-
CondDelta = goal_info_get_instmap_delta(CondInfo),
( instmap_delta_is_unreachable(CondDelta) ->
LivenessThen = LivenessCond,
- Then1 = Then0
+ % Initialize liveness-related fields.
+ detect_liveness_in_goal(Then0, Then1,
+ LivenessCond, _LivenessThen, LiveInfo)
;
detect_liveness_in_goal(Then0, Then1,
LivenessCond, LivenessThen, LiveInfo)
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 590209f..daa185b 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -40,6 +40,7 @@ MCFLAGS-ambig_pred = --type-check-constraints
MCFLAGS-ambig_types = --type-check-constraints
MCFLAGS-ambig_stress_test = --type-check-constraints
MCFLAGS-builtin_false = --intermodule-optimization
+MCFLAGS-bug51 = -O3
MCFLAGS-bug85 = -O0 --deforestation
MCFLAGS-bug100 = --halt-at-warn
MCFLAGS-bug128 = -O5 --loop-invariants
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 6df4698..20bf60b 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -67,6 +67,7 @@ OTHER_PROGS= \
any_inst_merge \
any_matches_bound \
big_foreign_type \
+ bug51 \
bug85 \
bug100 \
bug128 \
diff --git a/tests/valid/bug51.m b/tests/valid/bug51.m
new file mode 100644
index 0000000..797bcb2
--- /dev/null
+++ b/tests/valid/bug51.m
@@ -0,0 +1,56 @@
+% The compiler would abort during liveness detection on an if-then-else goal
+% with an unreachable Then branch, due to the Then goal not having its
+% liveness-related fields initialised.
+
+:- module bug51.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module list.
+
+:- type fruit
+ ---> apple
+ ; banana.
+
+main(!IO) :-
+ my_map(make, [apple], Xs),
+ do(Xs, !IO).
+
+:- pred my_map(pred(L, M), list(L), list(M)).
+:- mode my_map(pred(in, out) is det, in, out) is det.
+
+my_map(_, [], []).
+my_map(P, [H0 | T0], [H | T]) :-
+ P(H0, H),
+ my_map(P, T0, T).
+
+:- pred make(fruit::in, fruit::out) is det.
+
+make(X, X).
+
+:- pred do(list(fruit)::in, io::di, io::uo) is det.
+
+do([], !IO).
+do([X | Xs], !IO) :-
+ ( Xs = [_ | _] ->
+ S = "1"
+ ;
+ S = "2"
+ ),
+ (
+ X = apple
+ ;
+ X = banana,
+ io.write_string(S, !IO)
+ ).
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sts=4 sw=4 et
--
1.7.12.1
More information about the reviews
mailing list