> Am 29.05.2024 um 15:30 schrieb Eric Botcazou <botca...@adacore.com>:
>
> Hi,
>
> Ada doesn't have an equivalent to transparent union types in GNU C so, when it
> needs to interface a C function that takes a parameter of a transparent union
> type, GNAT uses the type of the first member of the union on the Ada side
> (which is the type used to determine the passing mechanism of the parameter).
>
> This works fine, except that LTO may warn about it; for the attached testcase:
>
> .> gcc -c t.c -O2 -flto -D_GNU_SOURCE
> .> gnatmake -q p -O2 -flto -largs t.o
>
> q.ads:6:12: warning: type of 'q__c_getpeername' does not match original
> declaration [-Wlto-type-mismatch]
> 6 | function C_Getpeername
> | ^
> /usr/include/sys/socket.h:130:12: note: type mismatch in parameter 2
> 130 | extern int getpeername (int __fd, __SOCKADDR_ARG __addr,
> | ^
> /usr/include/sys/socket.h:130:12: note: 'getpeername' was previously declared
> here
> /usr/include/sys/socket.h:130:12: note: code may be misoptimized unless '-fno-
> strict-aliasing' is used
>
>
> The attached patch recognizes the situation and checks the compatibility with
> the type of the first member of the union in this case.
>
> Tested on x86-64/Linux, OK for the mainline?
Do function pointers inter-operate TBAA wise for this case and would this
possibly
An issue?
Richard
>
> 2024-05-29 Eric Botcazou <ebotca...@adacore.com>
>
> * lto/lto-symtab.cc (warn_type_compatibility_p): Deal with
> parameters whose type is a transparent union specially.
>
> --
> Eric Botcazou
> <q.diff>
> <p.adb>
> <q.ads>
> <t.c>