This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR42517: Bogus runtime error with -fopenmp -fcheck=recursion


Hi all,

I recently noticed that -fcheck=recursion does not work together with
OpenMP. This is not surprising, since all that the recursion check
does is setting some internal logical variable to true when entering
the procedure and setting it back to false when leaving. So that, if
the procedure is already being executed, a second instance of that
procedure can detect this situation and throw a runtime error.

Now, in an OpenMP program you typically have several parallel threads,
and any procedure can simultaneously be executed in multiple threads
without being called recursively. Therefore the recursion check simply
does not work for this case and throws false errors galore.

The simplest way to avoid this false alarm is to disable the recursion
checking when -fopenmp is given. This is what the attached patch does.
It also documents this behavior in the manual. I think disabling the
recursion check is most important for cases where -fopenmp is used
together with -fcheck=all, since the other checks might still be
useful.

Surely there are ways to make the check work also for parallel
programs. E.g. one could use a logical array (instead of a scalar) for
each procedure, which would hold the information for each thread
number, so that one would only get a runtime error if a procedure is
being executed twice in a single thread. The question is if it's worth
the trouble. I'm not very keen on doing this right now, and it's
surely not stage-4 compatible, but one can leave it as an option for
the future.

So, is the attached patch ok for trunk? It was regtested on
x86_64-unknown-linux-gnu.

Cheers,
Janus


gcc/fortran/
2009-12-29 Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42517
	* invoke.texi: Document the interference of
	-fcheck=recursion and -fopenmp.
	* trans-decl.c (gfc_generate_function_code): Disable -fcheck=recursion
	when used with -fopenmp.

gcc/testsuite/
2009-12-29  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/42517
	* gfortran.dg/gomp/recursion1.f90: New test.

Attachment: pr42517.diff
Description: Binary data

Attachment: recursion1.f90
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]