This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Treelang patch - penultimate version


On 29-Jul-2001, Tim Josling <tej@melbpc.org.au> wrote:
> > > + @node Interoperating with C and C++,  , Other Languages, Other Languages
> > > + @section Tools and advice for interoperating with C and C++
> > > +
> > > + The output of treelang programs looks like c program code to the linker
> > > + and everybody else, so you should be able to freely mix treelang and C
> > > + (and C++) code.
> >
> > Does treelang promote function argument types and return types to `int'?
> > I found that was needed for binary compatibility with C when writing
> > the Mercury GCC front-end.
>
> In treelang every argument has to match exactly so this is not an issue in
> treelang.

I think you don't understand the problem.

If you write in treelang a function whose return type is `char', there's
no way to safely call that function from C.

The reason is that the calling conventions for functions returning char
is different.  The x86 code generated from the treelang source will return
the value in the bottom 8 bits of eax and will leave the other bits of eax
uninitialized.  A C function declared to have return type `char' uses a
different calling convention; the type of the argument is promoted to `int', so
it gets returned as a full 32-bit value, with the top 24 bits all zero
(or maybe sign-extended, I forget which -- I guess it depends on whether
char is signed).
If you try to call a treelang function that returns char from C,
then the C compiler will assume that the top 24 bits are already zero,
so if the C code e.g. converts it to `int', the C compiler will
assume that this can be a no-op, rather than generating a zero- or sign-
extension instruction.

...
> +     case EXTERNAL_REFERENCE_STORAGE:
> +       DECL_EXTERNAL (fn_decl) = 1; /* We should set TREE_PUBLIC also according to Justin Ferguson.  */
> +       break;

Who's Justin Ferguson?

-- 
Fergus Henderson <fjh@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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]