[Patch] Fortran: -fno-automatic and -fopenacc / recusion check cleanup
Tobias Burnus
tobias@codesourcery.com
Fri Nov 27 10:16:41 GMT 2020
Two fixes – simple, see patch + commit text.
Longer description:
* options:
Background:
- OpenMP, OpenACC and imply that a function is called
concurrently and -frecursive implies recusive. In all those
cases, the code may fail if a local variable is in static memory
instead of stack or heap. – If a user specified 'save', we
can assume/hope that they will deal with it - but with
-fno-automatic (→ 'save' implied), the flags clash.
- Additionally, to avoid placing local arrays in static memory,
for -fopenmp/-fopenacc -frecursive and 'unlimited' stack size
use for const-size arrays is implied.
This patch:
- Handle OpenACC as OpenMP (before it didn't imply -frecursive.
* Recursive run-time check. The current code currently generates:
subroutine foo()
logical, save :: currently_called = .false.
if (currently_called) error_stop "No recursive but called"
currently_called = .true.
...
... ! Rest of code, which could indirectly call this proc again
...
currently_called = .false.
end
This works well for recursive calls but less so for concurrency
(→ OpenMP, OpenACC).
As noted above, by default OpenMP/OpenACC implies -frecursive
and, hence, there is no recursive check generated.
The question is what code should be generated for, e.g.
-fno-automatic -fopenmp or -fopenacc -fmax-stack-var-size=20
In that case, -frecursive is unset. We have two choices:
- Either still always reset, which may not detect concurrent
use (including recursive + concurrent use) do to a race condition.
- Or avoid resetting the flag
But then calling the procedure twice (e.g. beginning + end of the
program) will generate a bogus error.
The current code does the second – at least for -fopenmp.
→ PATCH: Simply use the same condition twice instead of a complicated
test; do so via: 'if (recurcheckvar == NULL_TREE)'.
Current code:
tree recurcheckvar = NULL_TREE;
...
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
&& !is_recursive && !flag_recursive && !sym->attr.artificial)
... // declare 'recurcheckvar', generate error-message code etc.
...
/* Reset recursion-check variable. */
if ((gfc_option.rtcheck & GFC_RTCHECK_RECURSION)
&& !is_recursive && !flag_openmp && recurcheckvar != NULL_TREE)
Comments? Suggestions? – If not, I will commit it as obvious in the next
days.
Tobias
-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oacc-cleanup.diff
Type: text/x-patch
Size: 3573 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20201127/b83f0f17/attachment.bin>
More information about the Fortran
mailing list