Bug 17887 - g77 generates code that results in segmentation fault
Summary: g77 generates code that results in segmentation fault
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 37974 95631 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-08 02:24 UTC by Fred Bacon
Modified: 2020-06-11 11:16 UTC (History)
3 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Bacon 2004-10-08 02:24:06 UTC
The following code, when compiled with g77, produces an
executable that segfaults when run.  It was simple enough 
to work around, but the problem doesn't occur with the 
Intel fortran compiler or the Portland Group fortran 
compiler.

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C  bug.f
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

      PROGRAM  MAIN
      REAL*4  ANG
      ANG = ARCCOS( -1. )
      WRITE ( 6, 100 ) ANG
100   FORMAT('ARCCOS(-1) =', F10.4)
      STOP
      END
 
      REAL FUNCTION ARCCOS(X)
      REAL X
      IF(X.GT..9999999) X=1.
      IF(X.LT.-.9999999) X=-1.
      ARCCOS = ACOS(X)
      RETURN
      END
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C END
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC


g77 -v -save-temps -fno-globals -fno-automatic -Wall -g -o bugger bug.f

Driving: g77 -v -save-temps -fno-globals -fno-automatic -Wall -g -o bugger bug.f
-lfrtbegin -lg2c -lm -shared-libgcc
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --disable-libunwind-exceptions --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.3 20040412 (Red Hat Linux 3.3.3-7)
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/f771 bug.f -quiet -dumpbase bug.f
-auxbase bug -g -Wall -version -fno-globals -fno-automatic -o bug.s
GNU F77 version 3.3.3 20040412 (Red Hat Linux 3.3.3-7) (i386-redhat-linux)
        compiled by GNU C version 3.3.3 20040412 (Red Hat Linux 3.3.3-7).
GGC heuristics: --param ggc-min-expand=63 --param ggc-min-heapsize=63613
 as -V -Qy -o bug.o bug.s
GNU assembler version 2.15.90.0.3 (i386-redhat-linux) using BFD version
2.15.90.0.3 20040415
 /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o bugger
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crt1.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crti.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtbegin.o
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3
-L/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../.. bug.o -lfrtbegin -lg2c -lm
-lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/crtend.o
/usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crtn.o
Comment 1 Andrew Pinski 2004-10-08 02:47:49 UTC
The code is invalid, you are passing in a constant to a function and in fortran it is passed by reference 
always.  So you are trying to change the value of -1.0 which is undefined at runtime, in our case both 
g77 and gfortran segfault.
Comment 2 Bud Davis 2004-10-08 03:10:47 UTC
the problem is you are attempting to change the value of a constant.

here is a minimal example:


       CALL FOO(10)
       END
       SUBROUTINE FOO(X)
       INTEGER X
       X=100
       END

gfortran also seg faults with this type of example. i will dig into the standard
and see if this is permitted or not.




--bud davis
Comment 3 Bud Davis 2004-10-08 03:15:33 UTC
IMHO, here is the part of the F77 standard that applies:

15.9.3.2 Variables as Dummy Arguments.
A dummy argument that is a variable may be associated with an actual argument
that is a variable, array element, substring, or expression.

If the actual argument is a variable name, array element name, or substring
name, the associated dummy argument may be defined or redefined within the
subprogram. If the actual argument is a constant, a symbolic name of a constant,
a function reference, an expression involving operators, or an expression
enclosed in parentheses, the associated dummy argument must not be redefined
within the subprogram. 


--bud 

Comment 4 Maciej W. Rozycki 2020-06-11 10:46:09 UTC
*** Bug 37974 has been marked as a duplicate of this bug. ***
Comment 5 Maciej W. Rozycki 2020-06-11 11:16:46 UTC
*** Bug 95631 has been marked as a duplicate of this bug. ***