On Thu, Jan 28, 2016 at 11:11 AM, Florian Weimer <fwei...@redhat.com> wrote: > On 01/27/2016 04:17 PM, Richard Biener wrote: > >> We are trying to support >> >> t.c >> --- >> void *foo(); >> >> int bar() >> { >> return ((int (*)())foo) (); >> } >> >> t2.c >> ----- >> int foo () { return 0; } >> >> thus doing a direct call to a function with a (wrong) prototype via a >> function >> pointer cast to the correct type and having a matching implementation of >> that function elsewhere. > > I suspect Ada needs something like this already. I expect the following > to work (although it is quite hideous). > > with System; > > package Import is > > function Foo return System.Address; > pragma Import (C, Foo); > > function Bar return Integer; > > end Import; > > package body Import is > > function Bar return Integer is > function Foo_2 return Integer; > pragma Import (C, Foo_2); > for Foo_2'Address use Foo'Address; > begin > return Foo_2; > end Bar; > > end Import;
Heh. Well, the real reason for officially (aka in GCCs middle-end) supporting this is LTO and cross-language calls. You hardly can get 1:1 matching declarations there and penaltizing all of them by forcing us to go through indirect calls (which backends handle just fine) is no good. What the middle-end policy does is simply that the generated code should match the source input call ABI used (which is specified by the function type a call is carried out on). That makes sense from a QOI perspective anyway. And yes, it looks like the m68k backend is simply buggy here. Richard. > > Florian