git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Carlo Arenas <carenas@gmail.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types
Date: Wed, 22 Sep 2021 23:20:43 -0700	[thread overview]
Message-ID: <CAPUEspjaKUxq4_kptMC305Rkc7mEUEY_JGTxrRTiTaw5km87oQ@mail.gmail.com> (raw)
In-Reply-To: <2793c9c0-57ee-c7e0-957c-01d9aa27b44b@kdbg.org>

On Wed, Sep 22, 2021 at 2:21 PM Johannes Sixt <j6t@kdbg.org> wrote:
>
> Am 22.09.21 um 22:16 schrieb Carlo Arenas:
> > On Wed, Sep 22, 2021 at 12:56 PM Johannes Sixt <j6t@kdbg.org> wrote:
> >>
> >> Here, GCC warns about every use of the INIT_PROC_ADDR macro, for example:
> >>
> >> In file included from compat/mingw.c:8:
> >> compat/mingw.c: In function 'mingw_strftime':
> >> compat/win32/lazyload.h:38:12: warning: assignment to
> >>    'size_t (*)(char *, size_t,  const char *, const struct tm *)'
> >>    {aka 'long long unsigned int (*)(char *, long long unsigned int,
> >>       const char *, const struct tm *)'} from incompatible pointer type
> >>    'FARPROC' {aka 'long long int (*)()'} [-Wincompatible-pointer-types]
> >>    38 |  (function = get_proc_addr(&proc_addr_##function))
> >>       |            ^
> >> compat/mingw.c:1014:6: note: in expansion of macro 'INIT_PROC_ADDR'
> >>  1014 |  if (INIT_PROC_ADDR(strftime))
> >>       |      ^~~~~~~~~~~~~~
> >
> > did you have CFLAGS adding -Wincompatible-pointer-types explicitly?
>
> I don't know of the top of my head (am not at that Windows box right
> now). I am fairly certain that I do not have DEVELOPER set.

the config.mak.uname for MinGW sets that for you.

> > This is the reason why the code that got merged to master had -Wno
> > for this case.
> >
> >> (message wrapper for convenience). Insert a cast to keep the compiler
> >> happy. A cast is fine in these cases because they are generic function
> >> pointer values that have been looked up in a DLL.
> >
> > I have a more complete "fix" which I got stuck testing GGG[1]; you are likely
> > going to also hit -Wcast-function-type otherwise.

Sadly, as predicted your fix, broke the build [1], so submitted[2] and
adaptation
of the original fix on top of yours with the rest of the code that
will be needed
so it can be added in top of js/win-lazyload-buildfix and merged into "seen" to
fix that.

> I think that the correct solution is that get_proc_addr() returns void*,
> not FARPROC. Then either no cast is needed (because void* can be
> converted to function pointer type implicitly) or a cast is needed and
> that is then not between incompatible function pointer types and should
> not trigger -Wcast-function-type, theoretically.

The reasons behind why won't work are fairly academic IMHO, but there is
an obvious clash between POSIX and C specs here and "pedantic" just
reflects that.

Note that the return type for GetProcAddress[3] is FARPROC, and the C
standard says that any function pointer can be assigned to any other so
your code should work, but gcc has no way to know that FARPROC is not
the "real" function type and therefore warns that you might crash if using it.

Carlo

[1] https://github.com/git/git/runs/3680695336
[2] https://lore.kernel.org/git/20210923060306.21073-1-carenas@gmail.com/
[3] https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress

  reply	other threads:[~2021-09-23  6:20 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 19:56 [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types Johannes Sixt
2021-09-22 20:16 ` Carlo Arenas
2021-09-22 21:21   ` Johannes Sixt
2021-09-23  6:20     ` Carlo Arenas [this message]
2021-09-23  6:03 ` [PATCH] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-23  6:33   ` Johannes Sixt
2021-09-23  6:49     ` Carlo Arenas
2021-09-23  6:52   ` [PATCH v2] " Carlo Marcelo Arenas Belón
2021-09-26 10:05     ` [PATCH v3 0/2] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-26 10:05       ` [PATCH v3 1/2] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-27  2:58         ` Eric Sunshine
2021-09-26 10:05       ` [PATCH v3 2/2] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-27 16:35         ` Junio C Hamano
2021-09-27 18:50           ` Carlo Arenas
2021-09-27 20:13             ` Junio C Hamano
2021-09-29  0:48       ` [PATCH v4 0/3] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 1/3] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 2/3] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-29  0:48         ` [PATCH v4 3/3] Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format better Carlo Marcelo Arenas Belón
2021-09-29  1:14           ` Ramsay Jones
2021-09-29  3:19         ` [PATCH v5 0/3] js/win-lazyload-buildfix Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 1/3] lazyload.h: fix warnings about mismatching function pointer types Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 2/3] lazyload.h: use an even more generic function pointer than FARPROC Carlo Marcelo Arenas Belón
2021-09-29  3:19           ` [PATCH v5 3/3] Makefile: restrict -Wpedantic and -Wno-pedantic-ms-format better Carlo Marcelo Arenas Belón
2021-09-23 21:00 ` [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types Carlo Arenas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPUEspjaKUxq4_kptMC305Rkc7mEUEY_JGTxrRTiTaw5km87oQ@mail.gmail.com \
    --to=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).