https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69931

            Bug ID: 69931
           Summary: fortran address sanitizer does not work with
                    optimization
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: physiker at toast2 dot net
  Target Milestone: ---

When the code bnd11.f90, included in polyhedrons linux fortran testsuite, is
compiled without optimization the address sanitizer catches the error. With
optimization turned on, the address sanitizer does not spot the error. The
execution of the program is not stopped by the sanitizer.

bash-3.2$ gfortran-6 -v -W -Wall bnd11.f90 -fsanitize=address -o bnd11
Driving: gfortran-6 -v -W -Wall bnd11.f90 -fsanitize=address -o bnd11
-mmacosx-version-min=10.9.4 -l gfortran -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-6
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc/configure --enable-languages=c,c++,fortran,lto
--with-gmp=/sw --with-libiconv-prefix=/sw --with-isl=/sw --with-mpc=/sw
--with-system-zlib --program-suffix=-6
Thread model: posix
gcc version 6.0.0 20160213 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fsanitize=address' '-o' 'bnd11'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 /usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/f951 bnd11.f90 -fPIC
-quiet -dumpbase bnd11.f90 -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase
bnd11 -Wextra -Wall -version -fsanitize=address -fintrinsic-modules-path
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/finclude -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccqDq0Sb.s
GNU Fortran (GCC) version 6.0.0 20160213 (experimental)
(x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.0.0 20160213 (experimental), GMP version
6.1.0, MPFR version 3.1.3, MPC version 1.0.3, isl version 0.14 or 0.13
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU Fortran2008 (GCC) version 6.0.0 20160213 (experimental)
(x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.0.0 20160213 (experimental), GMP version
6.1.0, MPFR version 3.1.3, MPC version 1.0.3, isl version 0.14 or 0.13
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fsanitize=address' '-o' 'bnd11'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 as -arch x86_64 -force_cpusubtype_ALL -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccSUHTPj.o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccqDq0Sb.s
Reading specs from
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../../libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fsanitize=address' '-o' 'bnd11'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
COMPILER_PATH=/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../../
COLLECT_GCC_OPTIONS='-v' '-Wextra' '-Wall' '-fsanitize=address' '-o' 'bnd11'
'-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 /usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/collect2 -dynamic -arch
x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o bnd11
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccSUHTPj.o -lgfortran -lasan
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
collect2 version 6.0.0 20160213 (experimental)
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.4
-weak_reference_mismatches non-weak -o bnd11
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccSUHTPj.o -lgfortran -lasan
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7m armv7em
Library search paths:
        /usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
        /usr/local/lib
        /usr/lib
        /usr/local/lib
Framework search paths:
        /Library/Frameworks/
        /System/Library/Frameworks/
 /usr/bin/nm -n /var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccSUHTPj.o
bash-3.2$ ./bnd11
=================================================================
==643==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400000dcb8
at pc 0x00010f4b6c16 bp 0x7fff5074a1a0 sp 0x7fff5074a198
WRITE of size 4 at 0x60400000dcb8 thread T0
    #0 0x10f4b6c15 in MAIN__ (bnd11+0x100001c15)
    #1 0x10f4b6c60 in main (bnd11+0x100001c60)
    #2 0x7fff8aca95fc in start (libdyld.dylib+0x35fc)
    #3 0x0  (<unknown module>)

0x60400000dcb8 is located 0 bytes to the right of 40-byte region
[0x60400000dc90,0x60400000dcb8)
allocated by thread T0 here:
    #0 0x10f510b27 in wrap_malloc sanitizer_malloc_mac.inc:96
    #1 0x10f4b67e8 in MAIN__ (bnd11+0x1000017e8)
    #2 0x10f4b6c60 in main (bnd11+0x100001c60)
    #3 0x7fff8aca95fc in start (libdyld.dylib+0x35fc)
    #4 0x0  (<unknown module>)

SUMMARY: AddressSanitizer: heap-buffer-overflow (bnd11+0x100001c15) in MAIN__
Shadow bytes around the buggy address:
  0x1c0800001b40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0800001b50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0800001b60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0800001b70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0800001b80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x1c0800001b90: fa fa 00 00 00 00 00[fa]fa fa 00 00 00 00 00 00
  0x1c0800001ba0: fa fa 00 00 00 00 00 05 fa fa 00 00 00 00 00 07
  0x1c0800001bb0: fa fa 00 00 00 00 00 05 fa fa 00 00 00 00 00 05
  0x1c0800001bc0: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fd
  0x1c0800001bd0: fa fa fd fd fd fd fd fa fa fa 00 00 00 00 01 fa
  0x1c0800001be0: fa fa 00 00 00 00 00 00 fa fa 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==643==ABORTING

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x110211729
#1  0x110210b05
#2  0x7fff850025a9
Abort trap: 6
bash-3.2$ gfortran-6 -v -O -W -Wall bnd11.f90 -fsanitize=address -o bnd11
Driving: gfortran-6 -v -O -W -Wall bnd11.f90 -fsanitize=address -o bnd11
-mmacosx-version-min=10.9.4 -l gfortran -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-6
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/lto-wrapper
Target: x86_64-apple-darwin13.4.0
Configured with: ../gcc/configure --enable-languages=c,c++,fortran,lto
--with-gmp=/sw --with-libiconv-prefix=/sw --with-isl=/sw --with-mpc=/sw
--with-system-zlib --program-suffix=-6
Thread model: posix
gcc version 6.0.0 20160213 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-O' '-Wextra' '-Wall' '-fsanitize=address' '-o'
'bnd11' '-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 /usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/f951 bnd11.f90 -fPIC
-quiet -dumpbase bnd11.f90 -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase
bnd11 -O -Wextra -Wall -version -fsanitize=address -fintrinsic-modules-path
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/finclude -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccidCMTY.s
GNU Fortran (GCC) version 6.0.0 20160213 (experimental)
(x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.0.0 20160213 (experimental), GMP version
6.1.0, MPFR version 3.1.3, MPC version 1.0.3, isl version 0.14 or 0.13
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU Fortran2008 (GCC) version 6.0.0 20160213 (experimental)
(x86_64-apple-darwin13.4.0)
        compiled by GNU C version 6.0.0 20160213 (experimental), GMP version
6.1.0, MPFR version 3.1.3, MPC version 1.0.3, isl version 0.14 or 0.13
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
COLLECT_GCC_OPTIONS='-v' '-O' '-Wextra' '-Wall' '-fsanitize=address' '-o'
'bnd11' '-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 as -arch x86_64 -force_cpusubtype_ALL -o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccwtNyyO.o
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccidCMTY.s
Reading specs from
/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../../libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-O' '-Wextra' '-Wall' '-fsanitize=address' '-o'
'bnd11' '-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
COMPILER_PATH=/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/
LIBRARY_PATH=/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../../
COLLECT_GCC_OPTIONS='-v' '-O' '-Wextra' '-Wall' '-fsanitize=address' '-o'
'bnd11' '-mmacosx-version-min=10.9.4' '-shared-libgcc' '-mtune=core2'
 /usr/local/libexec/gcc/x86_64-apple-darwin13.4.0/6.0.0/collect2 -dynamic -arch
x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o bnd11
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccwtNyyO.o -lgfortran -lasan
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
collect2 version 6.0.0 20160213 (experimental)
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.4
-weak_reference_mismatches non-weak -o bnd11
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
-L/usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0/../../..
/var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccwtNyyO.o -lgfortran -lasan
-no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lquadmath -lm -lgcc_ext.10.5
-lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h
armv6m armv7m armv7em
Library search paths:
        /usr/local/lib/gcc/x86_64-apple-darwin13.4.0/6.0.0
        /usr/local/lib
        /usr/lib
        /usr/local/lib
Framework search paths:
        /Library/Frameworks/
        /System/Library/Frameworks/
 /usr/bin/nm -n /var/folders/97/4qnhjhtn25s86s9hkz0h37_m0000gn/T//ccwtNyyO.o
bash-3.2$ ./bnd11

Does not stop

Reply via email to