[m-rev.] for review: fix compiler abort in liveness detection

Peter Wang novalazy at gmail.com
Wed Nov 18 12:02:13 AEDT 2009


Branches: main

Fix a long standing bug in the liveness detection pass.

compiler/liveness.m:
        In detect_deadness_in_goal, when the instmap delta for an if-then-else
        goal is `unreachable', call `add_branch_pre_deaths' for the condition
        and else goals with the InstmapReachable argument `no', not `yes'.

        This avoids triggering a sanity check later in the
        detect_resume_points_in_goal pass on the following test case.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/liveness_ite.m:
        Add test case.

diff --git a/compiler/liveness.m b/compiler/liveness.m
index 8e6cdad..99f2e6c 100644
--- a/compiler/liveness.m
+++ b/compiler/liveness.m
@@ -773,10 +773,11 @@ detect_deadness_in_goal(Goal0, Goal, !Deadness, !.Liveness, LiveInfo) :-
             set.union(DeadnessCond, DeadnessElse, Deadness),
             set.intersect(Deadness, CompletedNonLocals,
                 CompletedNonLocalDeadness),
+            InstmapReachable = no,
             add_branch_pre_deaths(DeadnessCond, Deadness0,
-                CompletedNonLocalDeadness, yes, Cond1, Cond),
+                CompletedNonLocalDeadness, InstmapReachable, Cond1, Cond),
             add_branch_pre_deaths(DeadnessElse, Deadness0,
-                CompletedNonLocalDeadness, yes, Else1, Else)
+                CompletedNonLocalDeadness, InstmapReachable, Else1, Else)
         ),
         !:Deadness = Deadness,
         GoalExpr = if_then_else(Vars, Cond, Then, Else),
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 7e87400..558e902 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -95,6 +95,7 @@ MCFLAGS-intermod_user_equality_nested	= --intermodule-optimization
 MCFLAGS-intermod_user_sharing	= --intermodule-optimization
 MCFLAGS-intermod_user_sharing_2	= --intermodule-optimization
 MCFLAGS-lambda_inference	= --infer-all
+MCFLAGS-liveness_ite     	= --grade none --trace shallow
 MCFLAGS-livevals_seq		= -O5 --opt-space
 MCFLAGS-livevars_shallow	= --grade none --trace shallow
 MCFLAGS-livevars_shallow2	= --grade none --trace shallow
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 111d771..95a7681 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -263,6 +263,7 @@ DEEP_PROF_CAPABLE_PROGS = \
 LLDS_PROGS= \
 	exists_cast_bug \
 	fzn_debug_abort \
+	liveness_ite \
 	livevars_shallow \
 	livevars_shallow2 \
 	untuple_bug
diff --git a/tests/valid/liveness_ite.m b/tests/valid/liveness_ite.m
new file mode 100644
index 0000000..af253d3
--- /dev/null
+++ b/tests/valid/liveness_ite.m
@@ -0,0 +1,53 @@
+%-----------------------------------------------------------------------------%
+% Regression test.
+% The compiler aborted on this module with tracing enabled.
+%
+% Uncaught Mercury exception:
+% Software Error: liveness.m: Unexpected: branches of if-then-else disagree on liveness
+% First: 
+% Rest:  TypeInfo_for_T_8
+%
+%-----------------------------------------------------------------------------%
+
+:- module liveness_ite.
+:- interface.
+
+:- pred mypred(T::in, T::out) is erroneous.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module exception.
+
+%-----------------------------------------------------------------------------%
+
+:- type rollback_exception
+    --->    rollback_invalid_transaction
+    ;       rollback_retry.
+
+:- type stm_validation_result
+    --->    stm_transaction_valid
+    ;       stm_transaction_invalid.
+
+mypred(In, _Out) :-
+    ( semidet_true ->
+        IsValid = ff,
+        (
+            IsValid = stm_transaction_valid,
+            throw(rollback_retry)
+        ;
+            IsValid = stm_transaction_invalid,
+            throw(rollback_invalid_transaction)
+        )
+    ;
+        throw(In)
+    ).
+
+:- func ff = stm_validation_result.
+:- pragma no_inline(ff/0).
+
+ff = stm_transaction_valid.
+
+%-----------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list