git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] remove NORETURN from function pointers

From
Jeff King <peff@peff.net>
Date
Sep 14, 2009, 10:57 UTC
Message-ID
<20090914105750.GB9216@sigill.intra.peff.net>
In-Reply-To
<1252923370-5768-2-git-send-email-kusmabite@gmail.com>
On Mon, Sep 14, 2009 at 12:16:10PM +0200, Erik Faye-Lund wrote:
Show 8 quoted lines
> From: Erik Faye-Lund <kusmabite@googlemail.com>
> 
> Some compilers (including at least MSVC and ARM RVDS) supports
> NORETURN on function declarations, but not on function pointers.
> 
> This patch makes it possible to define NORETURN for these compilers.
> 
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>

I didn't see a patch 1/2, so maybe it impacts this in some way, but by itself, I don't think this patch is a good idea. See below.

Show 9 quoted lines
> ---
> 
> __attribute__((noreturn)) is, according to the GCC documentation, about
> two things: code generation (performance, really) and warnings.
> 
> On the warnings-side, we need to keep the code warning-free for
> compilers who doesn't support noreturn anyway, so hiding potential
> warnings through this mechanism is probably not a good idea in the
> first place.

[Your justification text would almost certainly be useful as part of the commit message itself, and should go there.]

Unfortunately, this patch _introduces_ warnings when running with gcc, as it now thinks those function pointers return (which means it thinks die() returns). So simply removing the NORETURN is not a good idea.

If I understand you correctly, the problem is that there are actually three classes of compilers:

  1. Ones which understand some NORETURN syntax for both functions and
     function pointers, and correctly trace returns through both (e.g.,
     gcc).
  2. Ones which understand some NORETURN syntax for just functions, and
     complain about it on function pointers. We currently turn off
     NORETURN for these compilers (from your commit message, MSVC,
     for example).
  3. Ones which have no concept of NORETURN at all.

I think the right solution to turn on NORETURN for (2) is to split it into two cases: NORETURN and NORETURN_PTR. Gcc platforms can define both identically, platforms under (2) above can define NORETURN_PTR as empty, and (3) will keep both off.

I do have to wonder, though. What do compilers that fall under (2) do with calls to function pointers from NORETURN functions? Do they assume they don't return, or that they do? Or do they not check that NORETURN functions actually don't return?

I.e., what does this program do under MSVC:

#include <stdlib.h> void (*exit_fun)(int) = exit; static void die(void) __attribute__((__noreturn__)); static void die(void) { exit_fun(1); } int main(void) { die(); }

In gcc, it rightly complains:
  foo.c: In function ‘die’:
  foo.c:4: warning: ‘noreturn’ function does return
-Peff
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 2 of 17 in “remove NORETURN from function pointers”
  1. 2/2 remove NORETURN from function pointersErik Faye-Lund, Sep 14, 2009
  2. Jeff KingSep 14, 2009
  3. Erik Faye-LundSep 14, 2009
  4. Erik Faye-LundSep 14, 2009
  5. Jeff KingSep 14, 2009
  6. Jeff KingSep 14, 2009
  7. Erik Faye-LundSep 14, 2009
  8. Jeff KingSep 14, 2009
  9. Erik Faye-LundSep 14, 2009
  10. Johannes SixtSep 14, 2009
  11. Erik Faye-LundSep 14, 2009
  12. Johannes SixtSep 14, 2009
  13. Erik Faye-LundSep 14, 2009
  14. Johannes SixtSep 14, 2009
  15. Junio C HamanoSep 22, 2009
  16. Erik Faye-LundSep 25, 2009
  17. Erik Faye-LundSep 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.