Skip to content

[Flang] Execution error of a large number as a repeat specification #79255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yus3710-fj opened this issue Jan 24, 2024 · 4 comments · Fixed by #79471
Closed

[Flang] Execution error of a large number as a repeat specification #79255

yus3710-fj opened this issue Jan 24, 2024 · 4 comments · Fixed by #79471
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior flang:runtime

Comments

@yus3710-fj
Copy link
Contributor

This is an issue from Fujitsu testsuite.

The execution of a program compiled by flang-new terminates with a fatal error.
In the program, a large number (the maximum number of INTEGER(4)) is used as a repeat specification in a format specification.
Flang doesn't violate the Fortran standard but some other compilers support this number as a repeat specification.

The following are the test program and the execution result of Flang-new, gfortran and ifort.

! test.f90
integer ::n_part(10)=1
write(1,'(32767(tr1,i0))') n_part
write(1,'(32768(tr1,i0))') n_part
write(1,'(1000000(tr1,i0))') n_part
write(1,'(2147483647(tr1,i0))') n_part

print *,'ok'
end
$ flang-new -v test.f90 
flang-new version 18.0.0git (https://github.com/llvm/llvm-project.git 2759e47067ea286f6302adcfe93b653cfaf6f2eb)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/test-e0a21e.o -x f95-cpp-input test.f90
 "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../bin/ld" -EL --hash-style=gnu --eh-frame-hdr -m aarch64linux -pie -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /lib/../lib64/Scrt1.o /lib/../lib64/crti.o /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtbeginS.o -L/path/to/install/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-e0a21e.o -L/path/to/install/lib --whole-archive -lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtendS.o /lib/../lib64/crtn.o
$ ./a.out 

fatal Fortran runtime error(/path/to/test.f90:6): FORMAT integer field out of range
Aborted (core dumped)
$ gfortran -v test.f90 
Driving: gfortran -v test.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC)
 :
$ ./a.out 
 ok
$ ifort -v test.f90
ifort version 2021.10.0 
:
$ ./a.out 
 ok
@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2024

@llvm/issue-subscribers-flang-runtime

Author: Yusuke MINATO (yus3710-fj)

This is an issue from Fujitsu testsuite.

The execution of a program compiled by flang-new terminates with a fatal error.
In the program, a large number (the maximum number of INTEGER(4)) is used as a repeat specification in a format specification.
Flang doesn't violate the Fortran standard but some other compilers support this number as a repeat specification.

The following are the test program and the execution result of Flang-new, gfortran and ifort.

! test.f90
integer ::n_part(10)=1
write(1,'(32767(tr1,i0))') n_part
write(1,'(32768(tr1,i0))') n_part
write(1,'(1000000(tr1,i0))') n_part
write(1,'(2147483647(tr1,i0))') n_part

print *,'ok'
end
$ flang-new -v test.f90 
flang-new version 18.0.0git (https://github.com/llvm/llvm-project.git 2759e47067ea286f6302adcfe93b653cfaf6f2eb)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Candidate multilib: .;@<!-- -->m64
Selected multilib: .;@<!-- -->m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/test-e0a21e.o -x f95-cpp-input test.f90
 "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../bin/ld" -EL --hash-style=gnu --eh-frame-hdr -m aarch64linux -pie -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /lib/../lib64/Scrt1.o /lib/../lib64/crti.o /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtbeginS.o -L/path/to/install/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-e0a21e.o -L/path/to/install/lib --whole-archive -lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtendS.o /lib/../lib64/crtn.o
$ ./a.out 

fatal Fortran runtime error(/path/to/test.f90:6): FORMAT integer field out of range
Aborted (core dumped)
$ gfortran -v test.f90 
Driving: gfortran -v test.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC)
 :
$ ./a.out 
 ok
$ ifort -v test.f90
ifort version 2021.10.0 
:
$ ./a.out 
 ok

@psteinfeld psteinfeld added the bug Indicates an unexpected problem or unintended behavior label Jan 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 24, 2024

@llvm/issue-subscribers-bug

Author: Yusuke MINATO (yus3710-fj)

This is an issue from Fujitsu testsuite.

The execution of a program compiled by flang-new terminates with a fatal error.
In the program, a large number (the maximum number of INTEGER(4)) is used as a repeat specification in a format specification.
Flang doesn't violate the Fortran standard but some other compilers support this number as a repeat specification.

The following are the test program and the execution result of Flang-new, gfortran and ifort.

! test.f90
integer ::n_part(10)=1
write(1,'(32767(tr1,i0))') n_part
write(1,'(32768(tr1,i0))') n_part
write(1,'(1000000(tr1,i0))') n_part
write(1,'(2147483647(tr1,i0))') n_part

print *,'ok'
end
$ flang-new -v test.f90 
flang-new version 18.0.0git (https://github.com/llvm/llvm-project.git 2759e47067ea286f6302adcfe93b653cfaf6f2eb)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Candidate multilib: .;@<!-- -->m64
Selected multilib: .;@<!-- -->m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -mframe-pointer=non-leaf -o /tmp/test-e0a21e.o -x f95-cpp-input test.f90
 "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../bin/ld" -EL --hash-style=gnu --eh-frame-hdr -m aarch64linux -pie -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /lib/../lib64/Scrt1.o /lib/../lib64/crti.o /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtbeginS.o -L/path/to/install/lib/clang/18/lib/aarch64-unknown-linux-gnu -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 -L/opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/test-e0a21e.o -L/path/to/install/lib --whole-archive -lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12/crtendS.o /lib/../lib64/crtn.o
$ ./a.out 

fatal Fortran runtime error(/path/to/test.f90:6): FORMAT integer field out of range
Aborted (core dumped)
$ gfortran -v test.f90 
Driving: gfortran -v test.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC)
 :
$ ./a.out 
 ok
$ ifort -v test.f90
ifort version 2021.10.0 
:
$ ./a.out 
 ok

@klausler klausler self-assigned this Jan 24, 2024
klausler added a commit to klausler/llvm-project that referenced this issue Jan 24, 2024
The integer overflow check used for repeat counts &c. in FORMAT
specifications was incorrect; fix it.

Fixes llvm#79255.
@klausler
Copy link
Contributor

#79368

klausler added a commit to klausler/llvm-project that referenced this issue Jan 24, 2024
The integer overflow check used for repeat counts &c. in FORMAT
specifications was incorrect; fix it.

Fixes llvm#79255.
klausler added a commit to klausler/llvm-project that referenced this issue Jan 25, 2024
The code that parses repeat counts, field widths, &c. from FORMAT
strings has an incorrect overflow check, so the maximum integer
value is not accepted.  Fix.

Fixes llvm#79255.
klausler added a commit to klausler/llvm-project that referenced this issue Jan 25, 2024
The code that parses repeat counts, field widths, &c. from FORMAT
strings has an incorrect overflow check, so the maximum integer
value is not accepted.  Fix.

Fixes llvm#79255.
klausler added a commit that referenced this issue Jan 26, 2024
The code that parses repeat counts, field widths, &c. from FORMAT
strings has an incorrect overflow check, so the maximum integer value is
not accepted. Fix.

Fixes #79255.
@klausler
Copy link
Contributor

Fix #79471 merged into llvm-project/main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior flang:runtime
4 participants