commit 375f058c901b29a768e806b6de5e46aa76744990
Author: Robert Haas <rhaas@postgresql.org>
Date:   Wed Mar 22 09:40:39 2023 -0400

    Remove hard dependency on fls().
    
    Prior to PostgreSQL 15, fls() was included in libpgport if not
    provided by the operating system, allowing pg_catcheck to rely on
    it unconditionally. However, that's no longer true, which causes
    compilation failures on platforms where fls() is not provided by
    the OS. Switch to using pg_leftmost_one_pos32() instead when
    compiling against newer PostgreSQL versions.
    
    Robert Haas and Shruthi KC

diff --git a/pgrhash.c b/pgrhash.c
index 436053a..5ba9b93 100644
--- a/pgrhash.c
+++ b/pgrhash.c
@@ -15,6 +15,10 @@
 
 #include "pg_catcheck.h"
 
+#if PG_VERSION_NUM >= 150000
+#include "port/pg_bitutils.h"
+#endif
+
 typedef struct pgrhash_entry
 {
 	struct pgrhash_entry *next; /* link to next entry in same bucket */
@@ -45,10 +49,21 @@ pgrhash_create(PGresult *result, int nkeycols, int *keycols)
 {
 	unsigned	bucket_shift;
 	pgrhash    *ht;
+	int ntuples;
 
 	Assert(nkeycols >= 1 && nkeycols <= MAX_KEY_COLS);
 
-	bucket_shift = fls(PQntuples(result));
+	ntuples = PQntuples(result);
+
+#if PG_VERSION_NUM >= 150000
+	if (ntuples == 0)
+		bucket_shift = 0;
+	else
+		bucket_shift = pg_leftmost_one_pos32(ntuples) + 1;
+#else
+	bucket_shift = fls(ntuples);
+#endif
+
 	if (bucket_shift >= sizeof(unsigned) * BITS_PER_BYTE)
 		pgcc_log(PGCC_FATAL, "too many tuples");
 
