[m-rev.] diff: fix bug #204
Peter Wang
novalazy at gmail.com
Wed Jul 13 10:42:00 AEST 2011
Branches: main
Fix bug #204. Deconstruct of packed arguments was broken due to a mistake in
the RTTI tables.
compiler/prog_data.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Correct the computation of the number of bits occupied by a packed
argument, given the bit-mask.
tests/hard_coded/Mmakefile:
tests/hard_coded/zinc_pack_bug.exp:
tests/hard_coded/zinc_pack_bug.m:
Add test case.
diff --git a/compiler/prog_data.m b/compiler/prog_data.m
index 07f4702..424d0fd 100644
--- a/compiler/prog_data.m
+++ b/compiler/prog_data.m
@@ -1707,7 +1707,7 @@ equivalent_cons_ids(ConsIdA, ConsIdB) :-
% two or more arguments which share the same word. The argument occupies
% the lowest bits in the word so no shifting is required. The other
% arguments can be masked out with the bit-mask `Mask'. The actual number
- % of bits occupied by the argument is `int.log2(Mask)'.
+ % of bits occupied by the argument is `int.log2(Mask + 1)'.
%
% `partial_word_shifted(Shift, Mask)' indicates that the argument is one of
% the subsequent arguments which share the same word. `Shift' is the
diff --git a/compiler/rtti_out.m b/compiler/rtti_out.m
index a88a77e..e70ed32 100644
--- a/compiler/rtti_out.m
+++ b/compiler/rtti_out.m
@@ -1167,11 +1167,11 @@ output_du_arg_locns_2([ArgInfo | ArgInfos], PrevSlotNum, !IO) :-
;
ArgWidth = partial_word_first(Mask),
Shift = 0,
- int.log2(Mask, Bits),
+ int.log2(Mask + 1, Bits),
SlotNum = PrevSlotNum + 1
;
ArgWidth = partial_word_shifted(Shift, Mask),
- int.log2(Mask, Bits),
+ int.log2(Mask + 1, Bits),
SlotNum = PrevSlotNum
),
io.format("\t{ %d, %d, %d },\n", [i(SlotNum), i(Shift), i(Bits)], !IO),
diff --git a/compiler/rtti_to_mlds.m b/compiler/rtti_to_mlds.m
index 074ac16..dd28f46 100644
--- a/compiler/rtti_to_mlds.m
+++ b/compiler/rtti_to_mlds.m
@@ -999,10 +999,10 @@ gen_field_locn(RttiId, ArgInfo, ArgLocnInitializer, !Offset) :-
ArgWidth = partial_word_first(Mask),
!:Offset = !.Offset + 1,
Shift = 0,
- int.log2(Mask, Bits)
+ int.log2(Mask + 1, Bits)
;
ArgWidth = partial_word_shifted(Shift, Mask),
- int.log2(Mask, Bits)
+ int.log2(Mask + 1, Bits)
),
ArgLocnInitializer = init_struct(mlds_rtti_type(item_type(RttiId)), [
gen_init_int(!.Offset),
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 0a9189b..2819c4e 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -318,7 +318,8 @@ ORDINARY_PROGS= \
write_reg1 \
write_reg2 \
write_xml \
- xmlable_test
+ xmlable_test \
+ zinc_pack_bug
# --transitive-intermodule-optimization is incompatible with mmc --make.
ifneq ($(MMAKE_USE_MMC_MAKE),yes)
diff --git a/tests/hard_coded/zinc_pack_bug.exp b/tests/hard_coded/zinc_pack_bug.exp
new file mode 100644
index 0000000..1a9a2e6
--- /dev/null
+++ b/tests/hard_coded/zinc_pack_bug.exp
@@ -0,0 +1 @@
+sym_variable(ti_par_int, undefined, global_var)
diff --git a/tests/hard_coded/zinc_pack_bug.m b/tests/hard_coded/zinc_pack_bug.m
new file mode 100644
index 0000000..a000058
--- /dev/null
+++ b/tests/hard_coded/zinc_pack_bug.m
@@ -0,0 +1,43 @@
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+
+% rotd-2011-07-09 generates code that seg. faults when executed.
+
+:- module zinc_pack_bug.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- type type_inst
+ ---> ti_par_bottom
+ ; ti_par_int
+ ; ti_var_int
+ ; ti_unknown
+ .
+:- type symbol
+ ---> sym_variable(
+ type_inst :: type_inst,
+ is_defined :: is_defined,
+ variable_kind :: variable_kind
+ ).
+
+:- type is_defined
+ ---> defined
+ ; undefined.
+
+:- type variable_kind
+ ---> global_var
+ ; type_constraint_var
+ ; let_var
+ ; generator_var
+ ; pred_arg
+ ; func_arg
+ ; ann_arg.
+
+main(!IO) :-
+ NewSym = sym_variable(ti_par_int, undefined, global_var),
+ io.write(NewSym, !IO),
+ io.nl(!IO).
--------------------------------------------------------------------------
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