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

            Bug ID: 108618
           Summary: ISO C-Fortran Interface fails to pass CFI descriptor
                    version check when using code coverage flags for
                    fortran
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kyle.shores44 at gmail dot com
  Target Milestone: ---

Created attachment 54378
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54378&action=edit
A zipped archive with 5 files, a dockerfile, CMakeLists.txt, a cmake file for
code coverage, a fortran source file, a c++ source file

The C-Fortran interface fails to pass a runtime Fortran check for the CFI
descriptor when checking code coverage. Specifically, the `-fcheck=bounds` flag
causes the runtime failure.

Included is a zip file that has a minimal working example. It's a cmake project
with two source files (one c++, one fortran), a Dockerfile, a CMakeLists.txt
file as well as the necessary code coverage cmake file. Fortran creates some
strings and passes them to C(++) through the `CFI_cdesc_t` struct defined in
ISO_Fortran_binding.h.

Inside of the CMakeLists.txt file there are two calls to
`set(CMAKE_Fortran_FLAGS ...`. Above each is a comment indicating which of the
flags passes and which fails. You can comment and uncomment the pair to watch
the created executable fail intermittently. 

When I compile the sources on my machine with the below versions of tools, I
see the failure.

os: macOS 12.5
architecture: Apple M1 Pro
gfortran: GNU Fortran (Homebrew GCC 12.2.0) 12.2.0
g++: (Homebrew GCC 12.2.0) 12.2.0
cmake: 3.25.1

I also see the failure in the Dockerfile included in the zipped archive
(hopefully this aids in the reproducibility of the issue). The tool versions in
the Dockerfile are

os: Fedora Linux 38
architecture: Apple M1 Pro
gfortran: GNU Fortran (GCC) 13.0.1 20230127 (Red Hat 13.0.1-0)
g++: (GCC) 13.0.1 20230127 (Red Hat 13.0.1-0)
cmake: 3.25.2

The specific flag that causes the issue is `-fcheck=bounds`.

The full list of compiler flags passed to gfortran on my machine:

/opt/homebrew/bin/gfortran 
-I/Users/kshores/Downloads/mwe/build/_deps/googletest-src/googletest/include
-I/Users/kshores/Downloads/mwe/build/_deps/googletest-src/googletest -g -O0
-fprofile-arcs -ftest-coverage -fcheck=bounds,do,pointer
-ffpe-trap=zero,overflow,invalid -fprofile-abs-path -isysroot
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk -c
/Users/kshores/Downloads/mwe/fortran_strings.F90 -o
CMakeFiles/bad_version.dir/fortran_strings.F90.o

The full list of compiler flags passed to gfortran in the Dockerfile:

/usr/bin/gfortran  -I/build/_deps/googletest-src/googletest/include
-I/build/_deps/googletest-src/googletest -g -O0 -fprofile-arcs -ftest-coverage
-fcheck=bounds,do,pointer -ffpe-trap=zero,overflow,invalid -fprofile-abs-path
-c /mwe/fortran_strings.F90 -o CMakeFiles/bad_version.dir/fortran_strings.F90.o


I hope that this is enough information. Please let me know if there is more
that is needed from me.

Reply via email to