Skip to content

Instantly share code, notes, and snippets.

@pletnes
Created April 15, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pletnes/c5a9eb460af9f7fcc535c9f5c8703537 to your computer and use it in GitHub Desktop.
Save pletnes/c5a9eb460af9f7fcc535c9f5c8703537 to your computer and use it in GitHub Desktop.
program archaic
implicit none
! This is actually a program input
integer, parameter :: M = 10000
integer, allocatable, dimension(:) :: iwork
integer, pointer, dimension(:) :: ptr
integer, pointer, dimension(:,:) :: ptr_remap
integer :: i, start, length
nullify(ptr)
allocate(iwork(M))
do i = 1, M
iwork(i) = i
end do
start = 10
length = 10
call routine(iwork(start), length)
ptr => array_ptr(iwork, start, length)
call modern_routine(ptr, .false.)
! Doing it in 2 steps works fine with
! ifort 2015/2016
! nagfor 6.0
! gfortran 4.8.5 (ubuntu 14.04)
! gfortran 5.3.0 (ubuntu 14.04)
ptr => array_ptr(iwork, start, length)
ptr_remap(1:2, 1:5) => ptr
call modern_2(ptr_remap)
! Compile-time segfaults occur for:
! ifort 15.0.3.187 Build 20150407
! gfortran 4.8.5 (ubuntu 14.04)
! gfortran 5.3.0 (ubuntu 14.04)
! Compiles and runs, but gives weird behavior for:
! ifort 16.0.2.181 Build 20160204
! Compiles and runs, behaves in an intuitive fashion on
! pgfortran 15.7-0, 32-bit version
! nagfor 6.0
ptr_remap(1:2, 1:5) => array_ptr(iwork, start, length) ! sed-tag-here
call modern_2(ptr_remap) ! sed-tag-here
! Crashes due to bounds check, if enabled
call modern_routine(ptr, .true.)
contains
subroutine modern_routine(part, fail)
implicit none
integer, intent(in) :: part(:)
logical, intent(in) :: fail
integer :: i
write (*,*) "Modern routine output:"
do i = 1, size(part)
write (*,'(i10)', advance='no') part(i)
end do
write (*,*)
! This fails the bounds check if commented out. Getting bounds check
! and actual rank 2 / rank 3 arrays is the rationale for all of this.
if (fail) then
write (*,*) "Modern routine has bounds check!"
write (*,'(i10)', advance='no') part(size(part) + 1)
write (*,*)
end if
end subroutine modern_routine
subroutine modern_2(part)
implicit none
integer, intent(in) :: part(:,:)
integer :: i, j
write (*,*) "Modern rank 2 routine output:"
do i = 1, size(part, 2)
do j = 1, size(part, 1)
write (*,'(i10)', advance='no') part(j, i)
end do
end do
write (*,*)
end subroutine modern_2
function array_ptr(iwork, start, length)
implicit none
integer, pointer :: array_ptr(:)
integer, target, intent(in) :: iwork(:)
integer, intent(in) :: start, length
! Start and length is found via some logic; skipped this for brevity.
! This is the reason for writing the function array_ptr.
array_ptr => iwork(start : start + length - 1)
end function array_ptr
end program archaic
subroutine routine(part, n)
implicit none
integer :: part(*)
integer :: n
integer :: i
write (*,*) "Archaic routine output:"
do i = 1, n
write (*,'(i10)', advance='no') part(i)
end do
write (*,*)
! This is not bounds checked
write (*,*) "Archaic routine has no bounds check:"
write (*,'(i10)', advance='no') part(n + 1)
write (*,*)
end subroutine routine
@pletnes
Copy link
Author

pletnes commented Apr 15, 2016

Run script

#!/bin/bash

# Runs all compiles and checks
# OS: ubuntu 14.04 LTS

source /usr/share/modules/init/bash

echo "Begin run of tests on system:"
echo "$(uname -a | cut -c 24-)"
echo ""

run_checks() {

    # GCC
    gfortran --version
    gfortran -fcheck=bounds foo.f90 -o foo && ./foo
    gfortran-5 --version
    gfortran-5 -fcheck=bounds foo.f90 -o foo && ./foo


    # Intel
    echo "Intel Fortran 2015"
    source /opt/intel/2015/composerxe/bin/compilervars.sh intel64
    ifort -V
    ifort -check foo.f90 -o foo && ./foo


    echo "Intel Fortran 2016"
    source /opt/intel/2016_update2/compilers_and_libraries/linux/bin/compilervars.sh intel64
    ifort -V
    ifort -check foo.f90 -o foo && ./foo


    # NAG
    echo "NAG fortran 6.0"
    module purge
    module load nagfor
    nagfor -V
    nagfor -C=array foo.f90 -o foo && ./foo


    # PGI
    echo "PGI fortran 15.7 (32 bit)"
    module purge
    module load pgi32
    pgfortran -V
    pgfortran -Mbounds foo.f90 -o foo && ./foo


    # PGI
    echo "PGI fortran 15.7 (64 bit)"
    module purge
    module load pgi64
    pgfortran -V
    pgfortran -Mbounds foo.f90 -o foo && ./foo

}

run_checks
sed -ibak '/sed-tag-here/ d' foo.f90
run_checks

@pletnes
Copy link
Author

pletnes commented Apr 15, 2016

My run log

Begin run of tests on system:
3.16.0-55-generic #74~14.04.1-Ubuntu SMP Tue Nov 17 10:15:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

GNU Fortran (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

foo.f90: In function ‘archaic’:
foo.f90:45:0: internal compiler error: Segmentation fault
     ptr_remap(1:2, 1:5) => array_ptr(iwork, start, length)  ! sed-tag-here
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
GNU Fortran (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204
Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

foo.f90:45:0:

     ptr_remap(1:2, 1:5) => array_ptr(iwork, start, length)  ! sed-tag-here
 1
internal compiler error: Segmentation fault
0xa3e2ef crash_signal
        ../../src/gcc/toplev.c:383
0x686f71 gfc_get_descriptor_dimension(tree_node*)
        ../../src/gcc/fortran/trans-array.c:280
0x687068 gfc_conv_descriptor_dimension
        ../../src/gcc/fortran/trans-array.c:298
0x687068 gfc_conv_descriptor_lbound
        ../../src/gcc/fortran/trans-array.c:370
0x68c23d gfc_conv_descriptor_lbound_get(tree_node*, tree_node*)
        ../../src/gcc/fortran/trans-array.c:383
0x68c23d gfc_conv_descriptor_size_1
        ../../src/gcc/fortran/trans-array.c:4894
0x6b7fab gfc_trans_pointer_assignment(gfc_expr*, gfc_expr*)
        ../../src/gcc/fortran/trans-expr.c:7837
0x682856 trans_code
        ../../src/gcc/fortran/trans.c:1682
0x6a2493 gfc_generate_function_code(gfc_namespace*)
        ../../src/gcc/fortran/trans-decl.c:5851
0x640480 translate_all_program_units
        ../../src/gcc/fortran/parse.c:5343
0x640480 gfc_parse_file()
        ../../src/gcc/fortran/parse.c:5540
0x67f9d5 gfc_be_parse_file
        ../../src/gcc/fortran/f95-lang.c:229
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
Intel Fortran 2015
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.3.187 Build 20150407
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

foo.f90: catastrophic error: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for foo.f90 (code 1)
Intel Fortran 2016
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.181 Build 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
  34476164         0         4         0         0         0       131         0         1         0
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
forrtl: severe (408): fort: (2): Subscript #1 of the array PART has value 11 which is greater than the upper bound of 10

Image              PC                Routine            Line        Source
foo                00000000004061A6  Unknown               Unknown  Unknown
foo                00000000004036A3  Unknown               Unknown  Unknown
foo                0000000000403049  Unknown               Unknown  Unknown
foo                000000000040261E  Unknown               Unknown  Unknown
libc.so.6          00007FBF38E7EEC5  Unknown               Unknown  Unknown
foo                0000000000402529  Unknown               Unknown  Unknown
NAG fortran 6.0
NAG Fortran Compiler Release 6.0(Hibiya) Build 1057
Product NPL6A60NA for x86-64 Linux
Copyright 1990-2015 The Numerical Algorithms Group Ltd., Oxford, U.K.
NAG Fortran Compiler Release 6.0(Hibiya) Build 1057
[NAG Fortran Compiler normal termination]
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
Runtime Error: foo.f90, line 70: Subscript 1 of PART (value 11) is out of range (1:10)
Program terminated by fatal error

./runall.sh: line 12: 18714 Aborted                 (core dumped) ./foo
PGI fortran 15.7 (32 bit)

pgfortran 15.7-0 32-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
0: Subscript out of range for array part (foo.f90: 70)
    subscript=11, lower bound=1, upper bound=10, dimension=1
PGI fortran 15.7 (64 bit)

pgfortran 15.7-0 64-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
0: Subscript out of range for array part (foo.f90: 70)
    subscript=11, lower bound=1, upper bound=10, dimension=1
GNU Fortran (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
At line 68 of file foo.f90
Fortran runtime error: Index '11' of dimension 1 of array 'part' above upper bound of 10
GNU Fortran (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204
Copyright (C) 2015 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
At line 68 of file foo.f90
Fortran runtime error: Index '11' of dimension 1 of array 'part' above upper bound of 10
Intel Fortran 2015
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.3.187 Build 20150407
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
forrtl: severe (408): fort: (2): Subscript #1 of the array PART has value 11 which is greater than the upper bound of 10

Image              PC                Routine            Line        Source
foo                0000000000405FB0  Unknown               Unknown  Unknown
foo                0000000000403581  Unknown               Unknown  Unknown
foo                0000000000402E33  Unknown               Unknown  Unknown
foo                000000000040247E  Unknown               Unknown  Unknown
libc.so.6          00007FB770A74EC5  Unknown               Unknown  Unknown
foo                0000000000402389  Unknown               Unknown  Unknown
Intel Fortran 2016
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.2.181 Build 20160204
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
forrtl: severe (408): fort: (2): Subscript #1 of the array PART has value 11 which is greater than the upper bound of 10

Image              PC                Routine            Line        Source
foo                0000000000405FE6  Unknown               Unknown  Unknown
foo                00000000004034E5  Unknown               Unknown  Unknown
foo                0000000000402E8B  Unknown               Unknown  Unknown
foo                000000000040261E  Unknown               Unknown  Unknown
libc.so.6          00007FB2E9C91EC5  Unknown               Unknown  Unknown
foo                0000000000402529  Unknown               Unknown  Unknown
NAG fortran 6.0
NAG Fortran Compiler Release 6.0(Hibiya) Build 1057
Product NPL6A60NA for x86-64 Linux
Copyright 1990-2015 The Numerical Algorithms Group Ltd., Oxford, U.K.
NAG Fortran Compiler Release 6.0(Hibiya) Build 1057
[NAG Fortran Compiler normal termination]
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
Runtime Error: foo.f90, line 68: Subscript 1 of PART (value 11) is out of range (1:10)
Program terminated by fatal error

./runall.sh: line 12: 18877 Aborted                 (core dumped) ./foo
PGI fortran 15.7 (32 bit)

pgfortran 15.7-0 32-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
0: Subscript out of range for array part (foo.f90: 68)
    subscript=11, lower bound=1, upper bound=10, dimension=1
PGI fortran 15.7 (64 bit)

pgfortran 15.7-0 64-bit target on x86-64 Linux -tp sandybridge
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
 Archaic routine output:
        10        11        12        13        14        15        16        17        18        19
 Archaic routine has no bounds check:
        20
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern rank 2 routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine output:
        10        11        12        13        14        15        16        17        18        19
 Modern routine has bounds check!
0: Subscript out of range for array part (foo.f90: 68)
    subscript=11, lower bound=1, upper bound=10, dimension=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment