[m-rev.] diff: fix abort while generatic static constructions

Peter Wang novalazy at gmail.com
Thu Jun 3 16:03:55 AEST 2010


Branches: main, 10.04

Fix a compiler abort when generating code for static constructions, where one
of the arguments cannot be found in the known constants map because the
construction of that variable was replaced by a cast.

compiler/ml_call_gen.m:
        In ml_gen_cast, add the destination variable to the known constants map
        if the source variable is a known constant.

diff --git a/compiler/ml_call_gen.m b/compiler/ml_call_gen.m
index 059f21b..628f066 100644
--- a/compiler/ml_call_gen.m
+++ b/compiler/ml_call_gen.m
@@ -287,6 +287,7 @@ ml_gen_cast(Context, ArgVars, Decls, Statements, !Info) :-
     ml_gen_var_list(!.Info, ArgVars, ArgLvals),
     ml_variable_types(!.Info, ArgVars, ArgTypes),
     (
+        ArgVars = [SrcVar, DestVar],
         ArgLvals = [SrcLval, DestLval],
         ArgTypes = [SrcType, DestType]
     ->
@@ -302,7 +303,14 @@ ml_gen_cast(Context, ArgVars, Decls, Statements, !Info) :-
             Assign = ml_gen_assign(DestLval, CastRval, Context),
             Statements = [Assign]
         ),
-        Decls = []
+        Decls = [],
+        ( ml_gen_info_search_const_var(!.Info, SrcVar, GroundTerm) ->
+            % If the source variable is a constant, so is the target after
+            % this cast.
+            ml_gen_info_set_const_var(DestVar, GroundTerm, !Info)
+        ;
+            true
+        )
     ;
         unexpected(this_file, "ml_gen_cast: wrong number of args for cast")
     ).

--------------------------------------------------------------------------
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