[m-rev.] diff: fix a bug with foreign_enum pragmas and --intermodule-optimization

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Oct 5 03:40:24 AEDT 2011


Branches: main, 11.07

Fix a bug that causes the compiler to erroneously emit an error message about
multiple foreign_enum pragmas when --intermodule-optimization is enabled. 
The problem only shows up with a particular arrangement of submodules and
module imports -- illustrated in the test case -- it is caused by the fact that
the foreign_enum pragma ends up in both the .int and .int0 file and the
existing code for adding pragmas to the HLDS didn't take account of the fact
that both might be present.

compiler/add_pragma.m:
 	Don't emit an error about duplicate foreign_enum pragmas if one of
 	them is opt-imported.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/Mercury.options:
tests/hard_coded/sub-modules/g12_fe_bug*.m:
tests/hard_coded/sub-modules/g12_fe_bug.exp:
 	Add a regression test.

Julien.

Index: compiler/add_pragma.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_pragma.m,v
retrieving revision 1.122
diff -u -r1.122 add_pragma.m
--- compiler/add_pragma.m	16 Aug 2011 03:26:29 -0000	1.122
+++ compiler/add_pragma.m	4 Oct 2011 15:02:41 -0000
@@ -1093,7 +1093,11 @@
                  )
              ;
                  DuTypeKind0 = du_type_kind_foreign_enum(_),
-                ( LangForForeignEnums \= Lang ->
+                ( 
+                    ( LangForForeignEnums \= Lang
+                    ; ImportStatus = status_opt_imported
+                    )
+                ->
                       MaybeSeverity = no,
                       ErrorPieces = []
                  ;
Index: tests/hard_coded/sub-modules/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/Mercury.options,v
retrieving revision 1.3
diff -u -r1.3 Mercury.options
--- tests/hard_coded/sub-modules/Mercury.options	24 Feb 2006 05:44:49 -0000	1.3
+++ tests/hard_coded/sub-modules/Mercury.options	4 Oct 2011 14:28:39 -0000
@@ -1,4 +1,8 @@

+MCFLAGS-g12_fe_bug = 			--intermodule-optimization
+MCFLAGS-g12_fe_bug.generic_search = --no-warn-interface-imports --intermodule-optimization
+MCFLAGS-g12_fe_bug.solvers = 		--intermodule-optimization
+MCFLAGS-g12_fe_bug.solvers.bounds = 	--intermodule-optimization
  MCFLAGS-nested_intermod	=	--intermodule-optimization
  MCFLAGS-nested_intermod_main =	--intermodule-optimization
  MCFLAGS-non_word_mutable =	--intermodule-optimization --no-intermodule-analysis
Index: tests/hard_coded/sub-modules/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/Mmakefile,v
retrieving revision 1.18
diff -u -r1.18 Mmakefile
--- tests/hard_coded/sub-modules/Mmakefile	30 Sep 2010 07:23:35 -0000	1.18
+++ tests/hard_coded/sub-modules/Mmakefile	4 Oct 2011 14:24:14 -0000
@@ -20,6 +20,7 @@
  	class \
  	deeply_nested \
  	finalise_parent \
+	g12_fe_bug \
  	initialise_parent \
  	mutable_parent \
  	nested \
Index: tests/hard_coded/sub-modules/g12_fe_bug.exp
===================================================================
RCS file: tests/hard_coded/sub-modules/g12_fe_bug.exp
diff -N tests/hard_coded/sub-modules/g12_fe_bug.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/g12_fe_bug.exp	4 Oct 2011 14:24:47 -0000
@@ -0,0 +1 @@
+Ok
Index: tests/hard_coded/sub-modules/g12_fe_bug.generic_search.m
===================================================================
RCS file: tests/hard_coded/sub-modules/g12_fe_bug.generic_search.m
diff -N tests/hard_coded/sub-modules/g12_fe_bug.generic_search.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/g12_fe_bug.generic_search.m	4 Oct 2011 14:28:43 -0000
@@ -0,0 +1,7 @@
+:- module g12_fe_bug.generic_search.
+:- interface.
+
+:- import_module g12_fe_bug.solvers.
+:- import_module g12_fe_bug.solvers.bounds.
+
+:- type foo ---> foo.
Index: tests/hard_coded/sub-modules/g12_fe_bug.m
===================================================================
RCS file: tests/hard_coded/sub-modules/g12_fe_bug.m
diff -N tests/hard_coded/sub-modules/g12_fe_bug.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/g12_fe_bug.m	4 Oct 2011 16:29:26 -0000
@@ -0,0 +1,19 @@
+% Compilation of this program with rotd-2011-09-04 and before resulted
+% in there being an erroneous error message about multiple foreign_enum
+% pragams being emitted when generating the .c file for the generic_search
+% sub-module.
+
+:- module g12_fe_bug.
+:- interface.
+
+:- import_module io.
+
+:- include_module solvers.
+:- include_module generic_search.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+	io.write_string("Ok\n", !IO).
Index: tests/hard_coded/sub-modules/g12_fe_bug.solvers.bounds.m
===================================================================
RCS file: tests/hard_coded/sub-modules/g12_fe_bug.solvers.bounds.m
diff -N tests/hard_coded/sub-modules/g12_fe_bug.solvers.bounds.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/g12_fe_bug.solvers.bounds.m	4 Oct 2011 14:28:43 -0000
@@ -0,0 +1,4 @@
+:- module g12_fe_bug.solvers.bounds.
+:- interface.
+
+:- type bounds_solver ---> bounds_solver.
Index: tests/hard_coded/sub-modules/g12_fe_bug.solvers.m
===================================================================
RCS file: tests/hard_coded/sub-modules/g12_fe_bug.solvers.m
diff -N tests/hard_coded/sub-modules/g12_fe_bug.solvers.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/sub-modules/g12_fe_bug.solvers.m	4 Oct 2011 14:28:43 -0000
@@ -0,0 +1,20 @@
+:- module g12_fe_bug.solvers.
+:- interface.
+
+:- include_module bounds.
+
+:- type trailing_mode
+    --->    no_trailing
+    ;       trailing. 
+
+:- implementation.
+
+%----------------------------------------------------------------------------%
+
+:- pragma foreign_enum("C", trailing_mode/0, [
+    no_trailing - "0",
+    trailing    - "1"
+]).
+
+%----------------------------------------------------------------------------%
+%----------------------------------------------------------------------------%

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