[m-rev.] for review: fix foreign type import bug

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Jan 13 01:31:28 AEDT 2004


The patch below seems to be responsible for a recent warning regression,
where compiling a module which contains `pragma export' in an LLDS grade
results in a GCC warning: "no previous prototype for foo".

The problem seems to be that the change to mercury_compile.m was wrong.
So I propose to back it out.

Example input that triggers the bug:

	:- module hello.
	:- interface.
	:- import_module io.

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

	:- implementation.

	:- pragma export(main(di,uo), "foo").

	main --> io__write_string("Hello, world\n").

On 24-Dec-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> 
> If a module exports foreign types, the interface files need
> to contain a `:- pragma foreign_import_module' declaration
> for the module to avoid target code compilation errors in
> importing modules.
>
> compiler/modules.m:
> 	Add a foreign_import_module declaration to item
> 	lists files where needed.
> 
> compiler/modules.m:
> compiler/make.dependencies.m:
> 	Handle extra dependencies.
> 
> compiler/intermod.m:
> compiler/mercury_compile.m:
> 	Remove code to add foreign_import_module declarations;
> 	this is now handled in modules.m.

> tests/hard_coded/export_test2.m:
> 	Test case.
...
> Index: compiler/mercury_compile.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
> retrieving revision 1.298
> diff -u -u -r1.298 mercury_compile.m
> --- compiler/mercury_compile.m	21 Dec 2003 05:04:35 -0000	1.298
> +++ compiler/mercury_compile.m	22 Dec 2003 07:05:50 -0000
> @@ -3596,26 +3596,11 @@
>  	foreign__filter_decls(UseForeignLanguage, ForeignDecls, 
>  		WantedForeignDecls, _OtherDecls),
>  	foreign__filter_imports(UseForeignLanguage, ForeignImports, 
> -		WantedForeignImports0, _OtherImports),
> +		WantedForeignImports, _OtherImports),
>  	foreign__filter_bodys(UseForeignLanguage, ForeignBodyCode,
>  		WantedForeignBodys, _OtherBodys),
>  	export__get_foreign_export_decls(HLDS, Foreign_ExportDecls),
>  	export__get_foreign_export_defns(HLDS, Foreign_ExportDefns),
> -
> -	% If this module contains `:- pragma export' declarations,
> -	% add a "#include <module>.h" declaration.
> -	% XXX pragma export is only supported for C.
> -	Foreign_ExportDecls = foreign_export_decls(_, ExportDecls),
> -	( UseForeignLanguage = c, ExportDecls \= [] ->
> -		% We put the new include at the end since the list is
> -		% stored in reverse, and we want this include to come
> -		% first.
> -		Import = foreign_import_module(c, ModuleName,
> -				term__context_init),
> -		WantedForeignImports = WantedForeignImports0 ++ [Import]
> -	;
> -		WantedForeignImports = WantedForeignImports0
> -	),
>  
>  	Foreign_InterfaceInfo = foreign_interface_info(ModuleName,
>  		WantedForeignDecls, WantedForeignImports,

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list