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

Re: [RFC/PATCH] git-compat-util.h: Don't define NORETURN under __clang__

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 3, 2010, 13:35 UTC
Message-ID
<vpq62zr24zw.fsf@bauges.imag.fr>
In-Reply-To
<1280840883-24540-1-git-send-email-avarab@gmail.com>
Ævar Arnfjörð Bjarmason venit, vidit, dixit 03.08.2010 15:08:
Show 8 quoted lines
> clang version 1.0 on Debian testing x86_64 defines __GNUC__, but barfs
> on `void __attribute__((__noreturn__))'. E.g.:
> 
>     usage.c:56:1: error: function declared 'noreturn' should not return [-Winvalid-noreturn]
>     }
>     ^
>     1 diagnostic generated.
>     make: *** [usage.o] Error 1

It doesn't mean that it's not accepting __noreturn__, it means it was not smart enough to check that the function do not return.

In my git, usage.c:56: leads me to this function:
void usagef(const char *err, ...)
{
	va_list params;
	va_start(params, err);
	usage_routine(err, params);
	va_end(params);
}

The absence of return comes from usage_routine, which is a pointer to function, and it seems your version of clang doesn't handle __noreturn__ pointers to functions properly.

On my box:
git$ make -B CC=clang V=yes usage.o                                                                                                        
clang -o usage.o -c   -g -Wall -Werror -I.  -DHAVE_PATHS_H -DSHA1_HEADER='<openssl/sha.h>'  -DNO_STRLCPY -DNO_MKSTEMPS  usage.c
git$ clang --version
clang version 1.1 (branches/release_27)
Target: i386-pc-linux-gnu
Thread model: posix
so, more recent clang do not seem to have this issue.
Show 13 quoted lines
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 02a73ee..c651cb7 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -183,7 +183,10 @@ extern char *gitbasename(char *);
>  #define is_dir_sep(c) ((c) == '/')
>  #endif
>  
> -#ifdef __GNUC__
> +#ifdef __clang__
> +#define NORETURN
> +#define NORETURN_PTR __attribute__((__noreturn__))
> +#elif __GNUC__

If you go for something like this, you should check the version of clang, and special-case only version < 1.1.

But I'm not sure special-casing old version of a young compiler really makes sense. We're only talking about warnings here, so I'd say you should either upgrade clang or remove -Werror from your CFLAGS.

(other than that, it's cool to see someone testing another compiler ;-) )

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Michael J GruberNext: Matthieu Moy
Message 3 of 6 in “git-compat-util.h: Don't define NORETURN under __clang__”
  1. git-compat-util.h: Don't define NORETURN under __clang__Ævar Arnfjörð Bjarmason, Aug 3, 2010
  2. Michael J GruberAug 3, 2010
  3. Matthieu MoyAug 3, 2010
  4. Matthieu MoyAug 3, 2010
  5. Ævar Arnfjörð BjarmasonAug 3, 2010
  6. Benjamin KramerAug 3, 2010

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.