[PATCH] Fix Bug 124286 - [16 regression] libfortran cannot be cross compiled

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
Attached patch is to fix the subject PR. I am not set up to do cross compiling 
so could not test that aspect.

Used autoconf 2.69 for that issue as well.

Regression tested on x86_64-linux.

OK for trunk?

Regards,

Jerry

Author: Jerry DeLisle <[email protected]>
Date:   Sat Feb 28 17:30:41 2026 -0800

     Fortran: Fix libfortran cannot be cross compiled [PR124286]

     Remove unneeded check for a sane CLZL and regenerate using
     the correct version of autoconf.

             PR fortran/124286

     libgfortran/ChangeLog:

             * acinclude.m4: Remove LIBGFOR_CHECK_SANE_BUILTIN_CLZL.
             * caf/shmem/allocator.c (next_power_of_two): Use known sane
             builtin.
             * configure: Regenerate.
             * configure.ac: Remove use of LIBGFOR_CHECK_SANE_BUILTIN_CLZL.
pr124286.diff (text/x-patch, 5.2 KB)
commit fd2f12ef226c369f54c351b7c6e319f1b6a7b010
Author: Jerry DeLisle <[email protected]>
Date:   Sat Feb 28 17:30:41 2026 -0800

    Fortran: Fix libfortran cannot be cross compiled [PR124286]
    
    Remove unneeded check for a sane CLZL and regenerate using
    the correct version of autoconf.
    
            PR fortran/124286
    
    libgfortran/ChangeLog:
    
            * acinclude.m4: Remove LIBGFOR_CHECK_SANE_BUILTIN_CLZL.
            * caf/shmem/allocator.c (next_power_of_two): Use known sane
            builtin.
            * configure: Regenerate.
            * configure.ac: Remove use of LIBGFOR_CHECK_SANE_BUILTIN_CLZL.

diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
index 13097b4ab92..239ab714750 100644
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -579,14 +579,3 @@ main ()
   fi
 ])
 
-AC_DEFUN([LIBGFOR_CHECK_SANE_BUILTIN_CLZL], [
-  AC_RUN_IFELSE([AC_LANG_PROGRAM([[
-      int main()
-      {
-	return __builtin_clzl(256) != 8;
-      }]], [[]])],
-    AC_DEFINE(HAVE_SANE_BUILTIN_CLZL, 1,
-      [Define if __builtin_clzl behaves as expected.])
-    AM_CONDITIONAL([HAVE_SANE_BUILTIN_CLZL],true),
-    [AM_CONDITIONAL([HAVE_SANE_BUILTIN_CLZL],false)])
-])
diff --git a/libgfortran/caf/shmem/allocator.c b/libgfortran/caf/shmem/allocator.c
index bd88f33e200..795647cdbba 100644
--- a/libgfortran/caf/shmem/allocator.c
+++ b/libgfortran/caf/shmem/allocator.c
@@ -78,16 +78,8 @@ allocator_init_supervisor (allocator *a, allocator_shared *s, shared_memory sm)
 static size_t
 next_power_of_two (size_t size)
 {
-#ifdef HAVE_SANE_BUILTIN_CLZL
-  assert (size);
-#if (__INTPTR_WIDTH__ == 64)
-  return 1 << (VOIDP_BITS - __builtin_clzl (size - 1));
-#else
-  return 1 << (VOIDP_BITS - __builtin_clz (size - 1));
-#endif
-#else
-  return 1 << (int)ceil(log2(size));
-#endif
+  assert (size != 1);
+  return (size_t)1 << (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ - __builtin_clzll (size - 1));
 }
 
 shared_mem_ptr
diff --git a/libgfortran/configure b/libgfortran/configure
index 798db4eca3a..68f111a6d48 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -637,8 +637,6 @@ am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
 get_gcc_base_ver
-HAVE_SANE_BUILTIN_CLZL_FALSE
-HAVE_SANE_BUILTIN_CLZL_TRUE
 HAVE_AVX128_FALSE
 HAVE_AVX128_TRUE
 tmake_file
@@ -13520,7 +13518,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13523 "configure"
+#line 13521 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13626,7 +13624,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 13629 "configure"
+#line 13627 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -32790,57 +32788,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   CFLAGS="$ac_save_CFLAGS"
 
 
-# Check if __builtin_clzl behaves (it doesn't on Msys2/ucrt64).
-
-  if test "$cross_compiling" = yes; then :
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run test program while cross compiling
-See \`config.log' for more details" "$LINENO" 5; }
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-      int main()
-      {
-	return __builtin_clzl(256) != 8;
-      }
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-
-$as_echo "#define HAVE_SANE_BUILTIN_CLZL 1" >>confdefs.h
-
-     if true; then
-  HAVE_SANE_BUILTIN_CLZL_TRUE=
-  HAVE_SANE_BUILTIN_CLZL_FALSE='#'
-else
-  HAVE_SANE_BUILTIN_CLZL_TRUE='#'
-  HAVE_SANE_BUILTIN_CLZL_FALSE=
-fi
-
-else
-   if false; then
-  HAVE_SANE_BUILTIN_CLZL_TRUE=
-  HAVE_SANE_BUILTIN_CLZL_FALSE='#'
-else
-  HAVE_SANE_BUILTIN_CLZL_TRUE='#'
-  HAVE_SANE_BUILTIN_CLZL_FALSE=
-fi
-
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
-
-
 # Determine what GCC version number to use in filesystem paths.
 
   get_gcc_base_ver="cat"
@@ -33148,14 +33095,6 @@ if test -z "${HAVE_AVX128_TRUE}" && test -z "${HAVE_AVX128_FALSE}"; then
   as_fn_error $? "conditional \"HAVE_AVX128\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
-if test -z "${HAVE_SANE_BUILTIN_CLZL_TRUE}" && test -z "${HAVE_SANE_BUILTIN_CLZL_FALSE}"; then
-  as_fn_error $? "conditional \"HAVE_SANE_BUILTIN_CLZL\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
-fi
-if test -z "${HAVE_SANE_BUILTIN_CLZL_TRUE}" && test -z "${HAVE_SANE_BUILTIN_CLZL_FALSE}"; then
-  as_fn_error $? "conditional \"HAVE_SANE_BUILTIN_CLZL\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
-fi
 
 : "${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index fea8292225b..530d15f0152 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -799,9 +799,6 @@ LIBGFOR_CHECK_FMA4
 # Check if AVX128 works
 LIBGFOR_CHECK_AVX128
 
-# Check if __builtin_clzl behaves (it doesn't on Msys2/ucrt64).
-LIBGFOR_CHECK_SANE_BUILTIN_CLZL
-
 # Determine what GCC version number to use in filesystem paths.
 GCC_BASE_VER
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.