[m-rev.] for review: fix a name mangling bug in hlc grades
Ian MacLarty
maclarty at csse.unimelb.edu.au
Tue Nov 14 13:37:41 AEDT 2006
For review by anyone.
Estimated hours taken: 1
Branches: main
Fix a bug in the hlc grades where generated C function names were not
being mangled correctly. The generated function names contained the
Mercury module name verbatim, which meant that if the Mercury module name
wasn't a valid C identifier, then the generated C code would be invalid.
compiler/mlds_to_c.m:
Mangle function names in generated high level C code.
tests/general/Mmakefile:
tests/general/hlc_name_mangling-helper-module.m:
tests/general/hlc_name_mangling.exp:
tests/general/hlc_name_mangling.m:
Add a regression test.
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.202
diff -u -r1.202 mlds_to_c.m
--- compiler/mlds_to_c.m 5 Oct 2006 04:45:33 -0000 1.202
+++ compiler/mlds_to_c.m 14 Nov 2006 00:42:15 -0000
@@ -663,8 +663,8 @@
output_init_fn_name(ModuleName, Suffix, !IO) :-
% Here we ensure that we only get one "mercury__" at the start
% of the function name.
- ModuleNameString0 = sym_name_to_string_sep(
- mlds_module_name_to_sym_name(ModuleName), "__"),
+ ModuleNameString0 = sym_name_mangle(
+ mlds_module_name_to_sym_name(ModuleName)),
( string.prefix(ModuleNameString0, "mercury__") ->
ModuleNameString = ModuleNameString0
;
@@ -686,8 +686,8 @@
output_required_fn_name(ModuleName, Suffix, !IO) :-
% Here we ensure that we only get one "mercury__" at the start
% of the function name.
- ModuleNameString0 = sym_name_to_string_sep(
- mlds_module_name_to_sym_name(ModuleName), "__"),
+ ModuleNameString0 = sym_name_mangle(
+ mlds_module_name_to_sym_name(ModuleName)),
( string.prefix(ModuleNameString0, "mercury__") ->
ModuleNameString = ModuleNameString0
;
Index: tests/general/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/general/Mmakefile,v
retrieving revision 1.53
diff -u -r1.53 Mmakefile
--- tests/general/Mmakefile 29 Mar 2006 08:07:57 -0000 1.53
+++ tests/general/Mmakefile 14 Nov 2006 01:13:18 -0000
@@ -27,6 +27,7 @@
frameopt_mkframe_bug \
hello_again \
higher_order \
+ hlc_name_mangling \
intermod_type \
interpreter \
io_foldl \
Index: tests/general/hlc_name_mangling-helper-module.m
===================================================================
RCS file: tests/general/hlc_name_mangling-helper-module.m
diff -N tests/general/hlc_name_mangling-helper-module.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/general/hlc_name_mangling-helper-module.m 14 Nov 2006 01:12:55 -0000
@@ -0,0 +1,5 @@
+:- module 'hlc_name_mangling-helper-module'.
+
+:- interface.
+
+:- type foo ---> foo.
Index: tests/general/hlc_name_mangling.exp
===================================================================
RCS file: tests/general/hlc_name_mangling.exp
diff -N tests/general/hlc_name_mangling.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/general/hlc_name_mangling.exp 14 Nov 2006 01:13:44 -0000
@@ -0,0 +1 @@
+foo
Index: tests/general/hlc_name_mangling.m
===================================================================
RCS file: tests/general/hlc_name_mangling.m
diff -N tests/general/hlc_name_mangling.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/general/hlc_name_mangling.m 14 Nov 2006 01:14:53 -0000
@@ -0,0 +1,19 @@
+% This is a regression test for a bug in the hlc grade where
+% function names were not mangled correctly.
+%
+
+:- module hlc_name_mangling.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+:- import_module 'hlc_name_mangling-helper-module'.
+
+main(!IO) :-
+ io.write(foo, !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