[m-dev.] Warning compiling io.c

Fergus Henderson fjh at cs.mu.oz.au
Tue Feb 11 18:01:56 AEDT 1997


Tyson Richard DOWD, you wrote:
> 
> > The following warning:
> > io.c: In function `mercury__io_module100':
> > io.c:5418: warning: assignment makes integer from pointer without a cast
> > when compiling io.c seems to come from std_util.m (via cross module inlining).
> > I think it might be necessary to put some casts in the univ-handling code.
> > Fergus, is this yours? Tyson maybe?

This one is due to a bug in inlining/specialization of polymorphic
pragma C codes.

This warning is not spurious!  It indicates a real problem.
Well, this particular case, i.e. string, it is OK,
but if you try type_to_univ with a float literal rather than
a string literal, you will get a core dump.

> I'll fix it.

I'd rather leave the warning there, until the bug is actually fixed.

The fix is probably to include an extra field in c_code goals which
contains a list of the *original* types (before inlining/specialization)
of the arguments; it is this list, rather than the substituted types,
which should be used to determine the declarations of the local vars
used for the c_code's inputs and outputs.

Here's the bug that I reported:

Subject: inlining of polymorphic pragma c_code
To: mercury-bugs at cs.mu.oz.au
Date: Sat, 18 Jan 1997 03:14:10 +1100 (EST)

Hi,

There is a bug in the inlining of polymorphic predicates
defined using pragma c_code.  The bug is that if the
actual argument has a specific type of `float'
then the corresponding formal parameter in the pragma c_code
will be declared as being of type `Float', and the argument
will be unboxed.  However, the c_code expects the polymorphic
argument to have type `Word'.

This causes a bus error when compiling the program below with
intermodule optimization (so that type_to_univ gets inlined)
on kryten (the problem would happen on any architecture for which
floats are boxed).

%-----------------------------------------------------------------------------%
Script started on Sat Jan 18 03:06:46 1997
$ hostname 
kryten.cs.mu.OZ.AU
$ mc --intermodule-optimization a.m
a.m:001: Warning: incorrect module name in `:- module' declaration.
a.c: In function `mercury__a_module0':
a.c:151: warning: assignment makes integer from pointer without a cast
a.c:182: warning: type mismatch with previous external decl
a.c:149: warning: previous external decl of `mercury_data___base_type_info_float_0'
a.c:183: warning: assignment makes integer from pointer without a cast
$ ./a

*** Mercury runtime: caught bus error ***
cause: invalid address alignment
PC at signal: 68796 (10cbc)
address involved: 1
exiting from signal handler
$ exit

script done on Sat Jan 18 03:07:20 1997
%-----------------------------------------------------------------------------%
:- module univ_float_test.
:- interface.
:- import_module io.

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

:- implementation.
:- import_module std_util, require.

main -->
	{ type_to_univ(1.0, U) },
	io__set_globals(U),
	u(F),
	io__write_float(F),
	io__write_char('\n').

:- pred u(T, io__state, io__state).
:- mode u(out, di, uo) is det.

u(F) -->
	io__get_globals(U2),
	( { univ_to_type(U2, F2) } ->
		{ F = F2 }
	;
		{ error("univ_to_type failed\n") }
	).
%-----------------------------------------------------------------------------%

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



More information about the developers mailing list