nvfortran compiler supports using INTENT attributes for non-dummy arguments. For example, for local variables.
This change adds a -fnon-arg-intent flag that enables such behavior in flang.
unterumarmung on Apr 5 2022, 3:09 AM.Authored by
Hi! Thanks for this patch, and for your interest in contributing to Flang!
I will leave it to somebody more experienced to accept the patch -- I am not familiar with this extension, and am not aware on what grounds we decide which extensions to support. I hope that my suggestions and questions can be useful anyway.
We keep a list of supported extensions in
Please add this extension there. And please also explain its behaviour a bit.
I wonder about the behaviour. Is INTENT for non-dummies allowed-but-ignored, or does it change the semantics? For example, is an INTENT(IN) variable supposed to be read-only? And what about combining SAVE, INTENT(OUT)? Or PARAMETER, INTENT(INOUT)?
I would also appreciate tests for this behaviour, e.g., a check that modifying an INTENT(IN) non-dummy is allowed or disallowed, as desired.
@ekieri, hello! Thank you for the comment, it is really helpful!
Actually, nvfortran compiler forbids to use INTENT attribute on local variables, even though a "mod" file can be generated. It generates a severe error like the one below and there's no way to ignore the severe errors, if I understand correctly.
NVFORTRAN-S-0134-Illegal attribute - intent specified for nondummy argument bar2 (test.f90: 3)
But the reason why I filed the patch was that nvfortran allows to use any kind of INTENT attribute for a local variable that marked as RESULT one for a function:
function foo() result(bar) integer, intent(out) :: bar end function foo
nvfortran does not generate any message for this code, not even a warning. So, it looks like a bug in the compiler, not a feature or extension and this should not be supported in flang, I think.