Hello, I realised when I created the small code snippet I accidentally put the variable "m" in the default integer declaration, I checked it and moving it (to kind=16) does not make a difference either.
I also checked on Ubuntu-64, same GCC & GFortran version (9.3.0) and I get the same error message / behaviour. I re-attach the corrected f90 file, which also as a slightly improved loop exit condition. Best wishes, Bernd ---- On Wed, 19 Aug 2020 at 15:22, Bernd Eggen <bernd.eg...@gmail.com> wrote: > Hello, > > I've come across an internal compiler error (in GFortran), concerning the > function NINT(), I attach a very simple source code that illustrates the > error. Essentially I am working with 16-byte integers, and there seems no > way to ensure that NINT() returns the correct precision integer. [I am > also testing this on an Ubuntu-64 installation, see separate email.] > > I tried a number of things, to no avail: > > > 1. m=nint(y) ! this gives at best an 8 byte integer return and or > larger numbers is negative, > 2. m=nint(y,i16) ! this is the attached version, which generates > compiler error > 3. m=nint(y,kind=i16) ! also generates error > 4. integer(kind=16) :: nint; ... m=nint(y) ! does not change return > type > 5. trying to compile with "-fdefault-integer-16" # option does not > exist > > Interestingly, in the related function, IDNINT() the "KIND" optional > argument does not even seem to be implemented > > Please include all of the following items, the first three of which can be > obtained from the output of gcc -v: > > - the exact version of GCC; > - the system type; *(Cygwin 64 on top of Windows 10)* > - the options given when GCC was configured/built; > > -> *cygcheck -c cygwin* > Cygwin Package Information > Package Version Status > cygwin *3.1.6-1* OK > > -> gcc -v > Using built-in specs. > COLLECT_GCC=gcc > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/9.3.0/lto-wrapper.exe > Target: x86_64-pc-cygwin > Configured with: > /cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.x86_64/src/gcc-9.3.0/configure > --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.x86_64/src/gcc-9.3.0 > --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc > --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C > --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin > --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib > --enable-shared --enable-shared-libgcc --enable-static > --enable-version-specific-runtime-libs --enable-bootstrap > --enable-__cxa_atexit --with-dwarf2 --with-tune=generic > --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-graphite > --enable-threads=posix --enable-libatomic --enable-libgomp > --enable-libquadmath --enable-libquadmath-support --disable-libssp > --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as > --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix > --without-libintl-prefix --with-system-zlib --enable-linker-build-id > --with-default-libstdcxx-abi=gcc4-compatible > --enable-libstdcxx-filesystem-ts > Thread model: posix > gcc version 9.3.0 (GCC) > > and for Gfortran: > > -> gfortran --version > GNU Fortran (GCC) *9.3.0* > Copyright (C) 2019 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There > is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR > PURPOSE. > > -> gfortran -v > Using built-in specs. > COLLECT_GCC=gfortran > COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/9.3.0/lto-wrapper.exe > Target: x86_64-pc-cygwin > Configured with: > /cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.x86_64/src/gcc-9.3.0/configure > --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-9.3.0-2.x86_64/src/gcc-9.3.0 > --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc > --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C > --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin > --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib > --enable-shared --enable-shared-libgcc --enable-static > --enable-version-specific-runtime-libs --enable-bootstrap > --enable-__cxa_atexit --with-dwarf2 --with-tune=generic > --enable-languages=c,c++,fortran,lto,objc,obj-c++ --enable-graphite > --enable-threads=posix --enable-libatomic --enable-libgomp > --enable-libquadmath --enable-libquadmath-support --disable-libssp > --enable-libada --disable-symvers --with-gnu-ld --with-gnu-as > --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix > --without-libintl-prefix --with-system-zlib --enable-linker-build-id > --with-default-libstdcxx-abi=gcc4-compatible > --enable-libstdcxx-filesystem-ts > Thread model: posix > gcc version 9.3.0 (GCC) > > > - the complete command line that triggers the bug; *see below* > - the compiler output (error messages, warnings, etc.); *see below* and > - the *preprocessed* file (*.i*) that triggers the bug, generated by > adding -save-temps to the complete compilation command, or, in the > case of a bug report for the GNAT front end, a complete set of source files > (see below). > > -> gfortran -save-temps -o nint_error.e *nint_error.f90* > nint_error.f90:17:0: > > 17 | m=nint(y,i16) > | > internal compiler error: in build_round_expr, at > fortran/trans-intrinsic.c:396 > Please submit a full bug report, > with preprocessed source if appropriate. > See <https://gcc.gnu.org/bugs/> for instructions. > > (and with IDNINT()): > > -> gfortran -save-temps -o nint_error.e nint_error.f90 > nint_error.f90:17:7: > > 17 | m=idnint(y,i16) > | 1 > Error: Too many arguments in call to ‘idnint’ at (1) > > Thanks for looking into this, Bernd (Eggen) > > PS Here a part of the output if omitting the "KIND" optional argument in > NINT(): > -> ./nint_error.e | & more > > i16= 16 > 1 1 1.0000000000000000 0 > 2 2 2.0000000000000000 1 > 3 4 4.0000000000000000 3 > 4 8 8.0000000000000000 7 > [...] > 31 1073741824 1073741824.0000000 1073741823 > 32 2147483648 2147483648.0000000 2147483647 > 33 4294967296 4294967296.0000000 *-1* > > > As you can see, after 2^31-1 = 2147483647 it goes wrong and yields -1 > > If increasing the integer by 1, it goes wrong thus: > > [...] > 2147483647 2147483647.0000000 2147483647 > 2147483648 2147483648.0000000 -2147483648 > [...] > >
program nint_error integer :: n integer(kind=16) :: i, j, m, nint integer, parameter :: idp=selected_real_kind(9,99) integer, parameter :: i16=selected_int_kind(38) real(kind=idp) :: x, y write(*,'(*(g0:" "))') 'i16=', i16 i=1_16 x=1.0d0 do n=1, 128, 1 j=i-1_16 y=x-1.0d0 ! m=nint(y,i16) m=nint(y) write(*,'(*(g0:" "))') n, i, x, m i=i+i x=x+x if ( (n>3) .and. (m<1_16) ) exit end do stop end program nint_error