Page MenuHomePhabricator

[Flang] Add `INTENT` for non-dummy arguments extension
AbandonedPublic

Authored by unterumarmung on Apr 5 2022, 3:09 AM.

Details

Summary

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.

Diff Detail

Unit TestsFailed

TimeTest
50 msx64 debian > ScudoStandalone-Unit-GwpAsanTorture._/ScudoCUnitTest-x86_64-Test::ScudoWrappersCTest.MallocInfo
Script: -- /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/scudo/standalone/tests/./ScudoCUnitTest-x86_64-Test --gtest_filter=ScudoWrappersCTest.MallocInfo
20 msx64 debian > ScudoStandalone-Unit._/ScudoCUnitTest-x86_64-Test::ScudoWrappersCTest.MallocInfo
Script: -- /var/lib/buildkite-agent/builds/llvm-project/build/projects/compiler-rt/lib/scudo/standalone/tests/./ScudoCUnitTest-x86_64-Test --gtest_filter=ScudoWrappersCTest.MallocInfo

Event Timeline

unterumarmung created this revision.Apr 5 2022, 3:09 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
unterumarmung requested review of this revision.Apr 5 2022, 3:09 AM
unterumarmung retitled this revision from [Flang] Add `INTENT` for non-dummy arguments extension nvfortran compiler supports using INTENT attributes for non-dummy arguments. For example, for local variables. to [Flang] Add `INTENT` for non-dummy arguments extension.
unterumarmung edited the summary of this revision. (Show Details)

Fixed revision description

This comment was removed by unterumarmung.
ekieri added a subscriber: ekieri.

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

flang/docs/Extensions.md

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.

clang/include/clang/Driver/Options.td
4734–4735

Feel free to use my suggestion literally or to work out something better, whichever you prefer.

flang/lib/Frontend/CompilerInvocation.cpp
536
flang/lib/Semantics/check-declarations.cpp
536

Please check for the feature-enablement together with the INTENT attributes above. Like this, the check for OPTIONAL below might get lost.

771

Same as above.

flang/test/Driver/driver-help-hidden.f90
45

Update description as per above.

flang/test/Driver/driver-help.f90
45

Update description as per above.

119

Update description as per above.

What is going on here? I don't understand.

@ekieri, hello! Thank you for the comment, it is really helpful!
It turns out that I've researched the issue poorly.

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.

ekieri added a comment.Apr 6 2022, 7:36 AM

Ok, good. Then please abandon this revision (Add Action... down by the comment box), so that its status is clear to everybody. Cheers!

unterumarmung abandoned this revision.Apr 7 2022, 6:48 AM