[m-dev.] for review: fix bug with --split-c-files --debug

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Mar 21 12:03:17 AEDT 2000


Zoltan, could you please review this one?

------------------------------

Estimated hours taken: 2

Fix a bug reported by Warwick Harvey where the compiler generated
invalid C code when compiling code with --debug --split-c-files.
The generated code was referring to a layout info struct without
having first declared it.

compiler/trace.m:
	When generating the C code that fills in the trace stack slot that
	holds the redo layout info, ensure that we include the redo label in
	the FixedLabel slot of the `pragma_c' instruction that we generate.

compiler/llds_out.m:
	Ensure that we generate a declaration of the layout info
	for the label in the FixedLabel slot of `pragma_c' instructions,
	if any.

tests/hard_coded/Mmakefile:
tests/hard_coded/split_c_files.m:
tests/hard_coded/split_c_files.split.exp:
	Add a regression test.

Workspace: /d-drive/home/hg/fjh/mercury
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.137
diff -u -d -r1.137 llds_out.m
--- compiler/llds_out.m	2000/03/20 05:24:56	1.137
+++ compiler/llds_out.m	2000/03/21 00:05:14
@@ -1008,16 +1008,7 @@
 	% Declare the stack layout entry for this label, if needed.
 	%
 	( { set_bbbtree__member(Label, StackLayoutLabels) } ->
-		{ Label = local(_, _) ->
-			DataName = internal_layout(Label)
-		;
-			DataName = proc_layout(Label)
-		},
-		{ ProcLabel = get_proc_label(Label) },
-		{ ModuleName = get_defining_module_name(ProcLabel) },
-		{ DataAddr = data_addr(ModuleName, DataName) },
-		output_data_addr_decls(DataAddr, "", "", 0, _,
-			DeclSet0, DeclSet1)
+		output_stack_layout_decl(Label, DeclSet0, DeclSet1)
 	;
 		{ DeclSet1 = DeclSet0 }
 	),
@@ -1052,6 +1043,21 @@
 	output_label(Label),
 	io__write_string(");\n").
 
+:- pred output_stack_layout_decl(label, decl_set, decl_set,
+		io__state, io__state).
+:- mode output_stack_layout_decl(in, in, out, di, uo) is det.
+
+output_stack_layout_decl(Label, DeclSet0, DeclSet) -->
+	{ Label = local(_, _) ->
+		DataName = internal_layout(Label)
+	;
+		DataName = proc_layout(Label)
+	},
+	{ ProcLabel = get_proc_label(Label) },
+	{ ModuleName = get_defining_module_name(ProcLabel) },
+	{ DataAddr = data_addr(ModuleName, DataName) },
+	output_data_addr_decls(DataAddr, "", "", 0, _, DeclSet0, DeclSet).
+
 :- func get_proc_label(label) = proc_label.
 get_proc_label(exported(ProcLabel)) = ProcLabel.
 get_proc_label(local(ProcLabel)) = ProcLabel.
@@ -1389,8 +1395,21 @@
 	output_rval_decls(Rval, "", "", 0, _, DeclSet0, DeclSet).
 output_instruction_decls(incr_sp(_, _), DeclSet, DeclSet) --> [].
 output_instruction_decls(decr_sp(_), DeclSet, DeclSet) --> [].
-output_instruction_decls(pragma_c(_, Comps, _, _, _, _), DeclSet0, DeclSet) -->
-	output_pragma_c_component_list_decls(Comps, DeclSet0, DeclSet).
+output_instruction_decls(pragma_c(_, Comps, _, MaybeFixedLabel, _, _),
+		DeclSet0, DeclSet) -->
+	% For some reason, the pragma_c code that trace.m
+	% generates in procedure prologues when debugging
+	% is enabled may refer to the redo label layout info,
+	% even though the corresponding redo label does not
+	% exist.  In that case, we need declare the label
+	% layout info here, otherwise the generated code
+	% won't compile with --split-files.
+	( { MaybeFixedLabel = yes(Label) } ->
+		output_stack_layout_decl(Label, DeclSet0, DeclSet1)
+	;
+		{ DeclSet1 = DeclSet0 }
+	),
+	output_pragma_c_component_list_decls(Comps, DeclSet1, DeclSet).
 output_instruction_decls(init_sync_term(Lval, _), DeclSet0, DeclSet) -->
 	output_lval_decls(Lval, "", "", 0, _, DeclSet0, DeclSet).
 output_instruction_decls(fork(Child, Parent, _), DeclSet0, DeclSet) -->
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.30
diff -u -d -r1.30 trace.m
--- compiler/trace.m	2000/02/16 02:15:38	1.30
+++ compiler/trace.m	2000/03/20 23:31:01
@@ -384,9 +384,11 @@
 			FillThreeSlots, "\n",
 			"\t\t", RedoLayoutStr, " = (Word) (const Word *) &",
 			LayoutAddrStr, ";"
-		], FillFourSlots)
+		], FillFourSlots),
+		MaybeFixedLabel = yes(RedoLayoutLabel)
 	;
-		FillFourSlots = FillThreeSlots
+		FillFourSlots = FillThreeSlots,
+		MaybeFixedLabel = no
 	),
 	(
 		% This could be done by generating proper LLDS instead of C.
@@ -423,7 +425,7 @@
 	),
 	TraceCode = node([
 		pragma_c([], [pragma_c_raw_code(TraceStmt)],
-			will_not_call_mercury, no, no, yes) - ""
+			will_not_call_mercury, MaybeFixedLabel, no, yes) - ""
 	])
 	}.
 
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.78
diff -u -d -r1.78 Mmakefile
--- tests/hard_coded/Mmakefile	2000/02/17 06:38:21	1.78
+++ tests/hard_coded/Mmakefile	2000/03/21 00:56:02
@@ -111,6 +111,9 @@
 	write \
 	write_reg1
 
+SPLIT_PROGS = \
+	split_c_files
+
 # we do no pass the following tests
 #	var_not_found -- "sorry, not implemented" in polymorphism.m.
 
@@ -129,6 +132,7 @@
 MCFLAGS-nondet_ctrl_vn	=	--optimize-value-number
 MCFLAGS-redoip_clobber	=	--no-inlining
 MCFLAGS-rnd		=	-O6
+MCFLAGS-split_c_files	=	--trace deep
 MCFLAGS-type_spec	=	--user-guided-type-specialization
 MCFLAGS-existential_types_test = --infer-all
 MCFLAGS-user_defined_equality	= --infer-all
@@ -154,6 +158,9 @@
 C2INITFLAGS-parse		= 	--trace
 MLFLAGS-parse			=	--trace --static
 
+C2INITFLAGS-split-c-files	= 	--trace
+MLFLAGS-split-c-files		=	--trace
+
 # no_fully_strict is expected to fail (it calls error/1)
 # so we need to ignore the exit status (hence the leading `-')
 no_fully_strict.out: no_fully_strict
@@ -161,15 +168,15 @@
 
 #-----------------------------------------------------------------------------#
 
-DEPS=	$(PROGS:%=%.dep)
-DEPENDS=$(PROGS:%=%.depend)
-OUTS=	$(PROGS:%=%.out)
-RESS=	$(PROGS:%=%.res)
+DEPS=	$(PROGS:%=%.dep) $(SPLIT_PROGS:%=%.dep)
+DEPENDS=$(PROGS:%=%.depend) $(SPLIT_PROGS:%=%.depend)
+OUTS=	$(PROGS:%=%.out) $(SPLIT_PROGS:%=%.split.out)
+RESS=	$(PROGS:%=%.res) $(SPLIT_PROGS:%=%.split.res)
 
 dep_local:	$(DEPS)
 depend_local:	$(DEPENDS)
 check_local:	$(OUTS) $(RESS)
-all_local:	$(PROGS)
+all_local:	$(PROGS) $(SPLIT_PROGS:%=%.split)
 
 #-----------------------------------------------------------------------------#
 
cvs diff: tests/hard_coded/split_c_files.m is a new entry, no comparison available
cvs diff: tests/hard_coded/split_c_files.split.exp is a new entry, no comparison available
==================================================
tests/hard_coded/split_c_files.m
==================================================
%% This is a regression test: mmc versions 0.8 and 0.9 generated incorrect
%% C code for this test case, when compiled with --split-c-files --debug.

:- module split_c_files.

:- interface.

:- import_module list, io.


:- pred main(state::di, state::uo) is det.

:- pred app(list(T),list(T),list(T)).
:- mode app(out,in,in) is nondet.

:- implementation.
:- import_module std_util.

main -->
	{ solutions((pred(X::out) is nondet :- app(X, [4], [1,2,3,4])),
		L) },
	write_list(L, "\n", print),
	nl.

split_c_files:(app(Z76,Ys,A77)) :-
        =(Z76,[]),
        =(A77,Ys).
split_c_files:(app(Z76,A77,B77)) :-
        =(B77,'.'(X,Zs)),
        split_c_files:(app(Xs,A77,Zs)),
        =(Z76,'.'(X,Xs)).
==================================================
tests/hard_coded/split_c_files.split.exp
==================================================
[1, 2, 3]
==================================================

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list