* Support FALLTHROUGH macro better in glibc+clang
@ 2023-02-26 16:43 Bruno Haible
2023-03-25 21:09 ` Bruno Haible
2023-03-25 21:24 ` Paul Eggert
0 siblings, 2 replies; 5+ messages in thread
From: Bruno Haible @ 2023-02-26 16:43 UTC (permalink / raw)
To: bug-gnulib; +Cc: Paul Eggert
Looking through the FALLTHROUGH definitions in gnulib, it appears that it
has the assumption built-in that glibc will only be built by GCC.
Nowadays people are alternatively using (non-Apple) clang to build glibc, see
https://www.collabora.com/news-and-blog/blog/2021/09/30/a-tale-of-two-toolchains-and-glibc/
https://www.collabora.com/news-and-blog/blog/2023/01/17/a-brave-new-world-building-glibc-with-llvm/
To help going in this direction, how about this patch? Paul, do you object?
2023-02-26 Bruno Haible <bruno@clisp.org>
Support FALLTHROUGH macro better in glibc+clang.
* lib/fnmatch.c (FALLTHROUGH): Use __attribute__ ((__fallthrough__))
also in clang >= 10.
* lib/fts.c (FALLTHROUGH): Likewise.
* lib/regex_internal.h (FALLTHROUGH): Likewise.
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 7c9c4e0f24..306b967c62 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -64,7 +64,7 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
#endif
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if (__GNUC__ >= 7) || (__clang_major__ >= 10)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
diff --git a/lib/fts.c b/lib/fts.c
index 78584b2902..388d251252 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -203,7 +203,7 @@ enum Fts_stat
#endif
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if (__GNUC__ >= 7) || (__clang_major__ >= 10)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 149ec2e868..d4dae98534 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -822,7 +822,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
}
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if (__GNUC__ >= 7) || (__clang_major__ >= 10)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Support FALLTHROUGH macro better in glibc+clang
2023-02-26 16:43 Support FALLTHROUGH macro better in glibc+clang Bruno Haible
@ 2023-03-25 21:09 ` Bruno Haible
2023-03-25 21:24 ` Paul Eggert
1 sibling, 0 replies; 5+ messages in thread
From: Bruno Haible @ 2023-03-25 21:09 UTC (permalink / raw)
To: Paul Eggert; +Cc: bug-gnulib
Hi Paul,
Any objections against this proposed patch from
<https://lists.gnu.org/archive/html/bug-gnulib/2023-02/msg00178.html> ?
> 2023-02-26 Bruno Haible <bruno@clisp.org>
>
> Support FALLTHROUGH macro better in glibc+clang.
> * lib/fnmatch.c (FALLTHROUGH): Use __attribute__ ((__fallthrough__))
> also in clang >= 10.
> * lib/fts.c (FALLTHROUGH): Likewise.
> * lib/regex_internal.h (FALLTHROUGH): Likewise.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support FALLTHROUGH macro better in glibc+clang
2023-02-26 16:43 Support FALLTHROUGH macro better in glibc+clang Bruno Haible
2023-03-25 21:09 ` Bruno Haible
@ 2023-03-25 21:24 ` Paul Eggert
2023-03-25 21:29 ` Paul Eggert
1 sibling, 1 reply; 5+ messages in thread
From: Paul Eggert @ 2023-03-25 21:24 UTC (permalink / raw)
To: Bruno Haible, bug-gnulib
On 2023-02-26 08:43, Bruno Haible wrote:
> -# if __GNUC__ >= 7
> +# if (__GNUC__ >= 7) || (__clang_major__ >= 10)
Sorry I didn't see this earlier.
Since this is protected by #ifdef _LIBC" it might be better to do this
the glibc way. Something like the following, perhaps?
# if __GNUC_PREREQ (7,0) || __glibc_has_attribute (__fallthrough__)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support FALLTHROUGH macro better in glibc+clang
2023-03-25 21:24 ` Paul Eggert
@ 2023-03-25 21:29 ` Paul Eggert
2023-03-27 17:24 ` Bruno Haible
0 siblings, 1 reply; 5+ messages in thread
From: Paul Eggert @ 2023-03-25 21:29 UTC (permalink / raw)
To: Bruno Haible; +Cc: bug-gnulib
On 2023-03-25 14:24, Paul Eggert wrote:
> # if __GNUC_PREREQ (7,0) || __glibc_has_attribute (__fallthrough__)
Come to think of it this could be simplified further, to just:
# if __glibc_has_attribute (__fallthrough__)
since GCC started supporting __has_attribute in GCC 5.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Support FALLTHROUGH macro better in glibc+clang
2023-03-25 21:29 ` Paul Eggert
@ 2023-03-27 17:24 ` Bruno Haible
0 siblings, 0 replies; 5+ messages in thread
From: Bruno Haible @ 2023-03-27 17:24 UTC (permalink / raw)
To: Paul Eggert; +Cc: bug-gnulib
Paul Eggert wrote:
> On 2023-03-25 14:24, Paul Eggert wrote:
> > # if __GNUC_PREREQ (7,0) || __glibc_has_attribute (__fallthrough__)
>
> Come to think of it this could be simplified further, to just:
>
> # if __glibc_has_attribute (__fallthrough__)
>
> since GCC started supporting __has_attribute in GCC 5.
Good point. I'm thus committing this in your name:
2023-03-27 Paul Eggert <eggert@cs.ucla.edu>
Support FALLTHROUGH macro better in glibc+clang.
* lib/fnmatch.c (FALLTHROUGH): Use __attribute__ ((__fallthrough__))
also in clang >= 10.
* lib/fts.c (FALLTHROUGH): Likewise.
* lib/regex_internal.h (FALLTHROUGH): Likewise.
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 7c9c4e0f24..32cfb48d0f 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -64,7 +64,7 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
#endif
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if __glibc_has_attribute (__fallthrough__)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
diff --git a/lib/fts.c b/lib/fts.c
index 794a4f75d7..3fffb45d70 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -203,7 +203,7 @@ enum Fts_stat
#endif
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if __glibc_has_attribute (__fallthrough__)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 149ec2e868..ae9257eac0 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -822,7 +822,7 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx)
}
#ifdef _LIBC
-# if __GNUC__ >= 7
+# if __glibc_has_attribute (__fallthrough__)
# define FALLTHROUGH __attribute__ ((__fallthrough__))
# else
# define FALLTHROUGH ((void) 0)
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-27 17:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-26 16:43 Support FALLTHROUGH macro better in glibc+clang Bruno Haible
2023-03-25 21:09 ` Bruno Haible
2023-03-25 21:24 ` Paul Eggert
2023-03-25 21:29 ` Paul Eggert
2023-03-27 17:24 ` Bruno Haible
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).