On Fri, Feb 27, 2026 at 1:01 PM Richard Biener
<[email protected]> wrote:
>
> On Fri, Feb 27, 2026 at 12:56 PM Tobias Burnus <[email protected]> wrote:
> >
> > Hi Jerry & Andre,
> >
> > the commit r16-7734-g136940891b16ba breaks cross compilation:
> >
> > Jerry D wrote:
> > > From: Andre Vehreschild<[email protected]>
> > > Date: Thu, 12 Feb 2026 11:17:47 -0800
> > > Subject: [PATCH] Fortran: Add a shared memory coarray implementation 
> > > [PR88076]
> > >
> > > Add caf_shmem, a shared memory multi process coarray implementation.
> > > The library adheres to the existing coarray ABI and is controlled by
> > > environment variables for selecting the number of images and virtual
> > > memory size.
> > ...
> > > libgfortran/ChangeLog:
> > >
> > >       * Makefile.am: Add new library.
> > >       * Makefile.in: Regenerated
> > >       * acinclude.m4: Add check for reasonable clzl.
> > >       * config.h.in: Regenerate.
> > >       * configure: Regenerate.
> > >       * configure.ac: Call clzl check.
> > * * *
> > > --- a/libgfortran/acinclude.m4
> > > +++ b/libgfortran/acinclude.m4
> > ...
> > > +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)])
> > > +])
>
> What does this test anyway?  clzl (256) should not return 8 but 55.
> Did  you want to check c_T_zl here?  I suggest to simply drop this given
> it's broken?

I'm also not convinced by

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

which uses VOIDP_BITS, not 'unsigned long' bits, and it seems to
correlate size_t width with unsigned long width by using INTPTR_WIDTH.
What do you do for long == 32bits targets (windows) which have 64bit
pointers?  You want to use __builtin_clzll there I think.

Of course the FP fallback

#else
  return 1 << (int)ceil(log2(size));
#endif

is also a bit questionable.  See gcc/hwint.{h,cc} for ceil_log2 on
uint64_t.

Richard.

>
> Richard.
>
> > This fails with:
> >
> > configure: error: in 
> > build-gcc-trunk-offload-amdgcn/amdgcn-amdhsa/libgfortran'
> > configure: error: cannot run test program while cross compiling
> >
> > Namely, the generated configure file contains:
> > > # 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
> >
> > In the code, you can either use code like:
> >    if test "$cross_compiling" != no; then
> > for the current code and the following in an else branch.
> > Or just the following:
> >
> >    case "${host}" in
> >    *-*-mingw32*)
> >        ....
> >      ;;
> >    *)
> >      ....
> >      ;;
> >    esac
> >
> > In any case, AC_RUN_IFELSE is wrong for cross compilation,
> > AC_COMPILE_IFELSE is fine.
> >
> > Tobias
> >

Reply via email to