[Bug fortran/28443] New: gfortran does not implement the present intrinsic procedure correctly for optional character strings
In file strpresent.F90: program test_string_present call test_present(1, "foo") call test_present(2) end program subroutine test_present(a, b) integer :: a character*(*), optional :: b if (present(b)) then write (0,*) "b is present." else write (0,*) "b is not present." end if end subroutine test_present As of SVN revision 115597, this yields the output: b is present. b is present. It appears that the present() intrinsic function isn't working correctly for optional character strings. Ifort yields the expected output: b is present. b is not present. The output of gfortran -v -save-temps -o strpresent strpresent.F90: Driving: gfortran -v -save-temps -o strpresent strpresent.F90 -lgfortranbegin -lgfortran -lm -shared-libgcc Using built-in specs. Target: i686-pc-linux-gnu Configured with: /home/pfarrell/redhat/BUILD/gcc4-115597/configure --prefix=/opt/packages/gcc4 --enable-bootstrap --enable-languages=c,c++,fortran Thread model: posix gcc version 4.2.0 20060719 (experimental) /opt/packages/gcc4/libexec/gcc/i686-pc-linux-gnu/4.2.0/cc1 -E -lang-fortran -traditional-cpp -D_LANGUAGE_FORTRAN -quiet -v strpresent.F90 -mtune=generic -fpch-preprocess -o strpresent.f95 ignoring nonexistent directory "/opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/../../../../i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /opt/packages/gcc4/include /opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/include /usr/include End of search list. /opt/packages/gcc4/libexec/gcc/i686-pc-linux-gnu/4.2.0/f951 strpresent.f95 -ffree-form -quiet -dumpbase strpresent.F90 -mtune=generic -auxbase strpresent -version -fpreprocessed -I /opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/finclude -o strpresent.s GNU F95 version 4.2.0 20060719 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 4.2.0 20060719 (experimental). GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 as -V -Qy -o strpresent.o strpresent.s GNU assembler version 2.15.92.0.2 (i386-redhat-linux) using BFD version 2.15.92.0.2 20040927 /opt/packages/gcc4/libexec/gcc/i686-pc-linux-gnu/4.2.0/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o strpresent /usr/lib/crt1.o /usr/lib/crti.o /opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/crtbegin.o -L/opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0 -L/opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/../../.. strpresent.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /opt/packages/gcc4/lib/gcc/i686-pc-linux-gnu/4.2.0/crtend.o /usr/lib/crtn.o -- Summary: gfortran does not implement the present intrinsic procedure correctly for optional character strings Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: cyan+gcc at compsoc dot nuigalway dot ie GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28443
[Bug fortran/28818] New: C/Fortran interoperability: variable number of arguments passed from fortran to C causes Illegal instruction
With svn revision 116324, on x86_64-unknown-linux-gnu: [EMAIL PROTECTED]:~]$ cat test.c #include #include void test_(int *test, ...) { printf("test: %d\n", *test); return; } [EMAIL PROTECTED]:~]$ cat forttest.F90 program test_printf call test(-1, 'd') call test(-1, 'd') end program test_printf [EMAIL PROTECTED]:~]$ make gcc -c -o test.o test.c gfortran -c -o forttest.o forttest.F90 gfortran -o test test.o forttest.o [EMAIL PROTECTED]:~]$ ./test test: -1 Illegal instruction [EMAIL PROTECTED]:~]$ This does not happen if void test_(int *test, ...) is replaced with void test_(int *test, char *d) so it appears there's something wrong with variable numbers of arguments being passed between fortran and C. Here's what gdb says: Breakpoint 1, test_ (test=0x400878) at test.c:6 6 printf("test: %d\n", *test); (gdb) n test: -1 8 } (gdb) nexti 0x0040070e in test_ (test=0x400874) at test.c:8 8 } (gdb) nexti MAIN__ () at forttest.F90:4 4 call test(-1, 'd') Current language: auto; currently fortran (gdb) nexti 0x00400741 4 call test(-1, 'd') (gdb) nexti 0x00400746 4 call test(-1, 'd') (gdb) nexti 0x0040074b 4 call test(-1, 'd') (gdb) nexti Program received signal SIGILL, Illegal instruction. 0x004006ca in test_ (test=0x400878) at test.c:5 5 { Current language: auto; currently c (gdb) but I don't know enough about assembly to help any more. -- Summary: C/Fortran interoperability: variable number of arguments passed from fortran to C causes Illegal instruction Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: cyan+gcc at compsoc dot nuigalway dot ie GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28818
[Bug fortran/28818] C/Fortran interoperability: variable number of arguments passed from fortran to C causes Illegal instruction
--- Comment #3 from cyan+gcc at compsoc dot nuigalway dot ie 2006-08-25 11:06 --- (In reply to comment #2) > the Fortran program > is not calling a var-args C function, I don't understand what you mean. The fortran code calls the test function, which is written in C (called test_ due to name mangling). test_ is indeed a variable-args function: void test_(int *test, ...). Also, this code works as expected on 32-bit x86 machines. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28818