git: 3f5788e0ed8e - main - lib/libc/string/ffs*.c: work around gcc warning
Date: Fri, 14 Jul 2023 20:27:35 UTC
The branch main has been updated by fuz:
URL: https://cgit.FreeBSD.org/src/commit/?id=3f5788e0ed8e85567f651ad360596b8c330af5a9
commit 3f5788e0ed8e85567f651ad360596b8c330af5a9
Author: Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-07-10 22:10:52 +0000
Commit: Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-07-14 20:26:43 +0000
lib/libc/string/ffs*.c: work around gcc warning
Gcc warns of infinite recursion if we use __builtin_ffs*() to
implement ffs*(). This is because gcc uses ffs() to implement
these on some platforms. Sidestep the warning by using
__builtin_ctz*() for these.
Sponsored by: FreeBSD Foundation
Reported by: jlduran@gmail.com, jhb
Fixes: ee8b0c43 (D40730)
Reviewed by: jhb, mhorne
Approved by: jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D40966
---
lib/libc/string/ffs.c | 2 +-
lib/libc/string/ffsl.c | 2 +-
lib/libc/string/ffsll.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/libc/string/ffs.c b/lib/libc/string/ffs.c
index c011b3390612..34140e3e4d85 100644
--- a/lib/libc/string/ffs.c
+++ b/lib/libc/string/ffs.c
@@ -47,5 +47,5 @@ __FBSDID("$FreeBSD$");
int
ffs(int mask)
{
- return (__builtin_ffs(mask));
+ return (mask == 0 ? 0 : __builtin_ctz(mask) + 1);
}
diff --git a/lib/libc/string/ffsl.c b/lib/libc/string/ffsl.c
index 6e1ac8ec45c1..701e23cdf8f4 100644
--- a/lib/libc/string/ffsl.c
+++ b/lib/libc/string/ffsl.c
@@ -44,5 +44,5 @@ __FBSDID("$FreeBSD$");
int
ffsl(long mask)
{
- return (__builtin_ffsl(mask));
+ return (mask == 0 ? 0 : __builtin_ctzl(mask) + 1);
}
diff --git a/lib/libc/string/ffsll.c b/lib/libc/string/ffsll.c
index b945658b9008..e94fb518eb03 100644
--- a/lib/libc/string/ffsll.c
+++ b/lib/libc/string/ffsll.c
@@ -44,5 +44,5 @@ __FBSDID("$FreeBSD$");
int
ffsll(long long mask)
{
- return (__builtin_ffsll(mask));
+ return (mask == 0 ? 0 : __builtin_ctzll(mask) + 1);
}