-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang] Extension: accept NULL([MOLD=]) for ALLOCATABLE INTENT(IN) du… #66256
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
flang
Flang issues not falling into any other category
flang:semantics
labels
Sep 13, 2023
@llvm/pr-subscribers-flang-semantics Changes…mmy argumentSeveral compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well.Full diff: https://github.com/llvm/llvm-project/pull/66256.diff 4 Files Affected:
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md index 49e78a10fa6bcdb..1d6680a0708c0b5 100644 --- a/flang/docs/Extensions.md +++ b/flang/docs/Extensions.md @@ -298,6 +298,8 @@ end * Unrestricted `INTRINSIC` functions are accepted for use in `PROCEDURE` statements in generic interfaces, as in some other compilers. +* A `NULL()` pointer is treated as an unallocated allocatable + when associated with an `INTENT(IN)` allocatable dummy argument. ### Extensions supported when enabled by options diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h index 5cbe1d6e157f2f9..94a39c50e049b11 100644 --- a/flang/include/flang/Common/Fortran-features.h +++ b/flang/include/flang/Common/Fortran-features.h @@ -37,7 +37,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines, DistinguishableSpecifics, DefaultSave, PointerInSeqType, NonCharacterFormat, SaveMainProgram, SaveBigMainProgramVariables, DistinctArrayConstructorLengths, PPCVector, RelaxedIntentInChecking, - ForwardRefImplicitNoneData) + ForwardRefImplicitNoneData, NullActualForAllocatable) // Portability and suspicious usage warnings for conforming code ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable, diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index c48c382218dc9bb..574cdee3d665372 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -658,18 +658,35 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, // 15.5.2.6 -- dummy is ALLOCATABLE bool actualIsAllocatable{evaluate::IsAllocatableDesignator(actual)}; + bool actualIsNull{evaluate::IsNullPointer(actual)}; if (dummyIsAllocatable) { - if (!actualIsAllocatable) { + if (actualIsAllocatable) { + if (actualIsCoindexed && dummy.intent != common::Intent::In) { + messages.Say( + "ALLOCATABLE %s must have INTENT(IN) to be associated with a coindexed actual argument"_err_en_US, + dummyName); + } + } else if (actualIsNull) { + if (dummy.intent == common::Intent::In) { + // Extension (Intel, NAG, XLF): a NULL() pointer is an acceptable + // actual argument for an INTENT(IN) allocatable dummy, and it + // is treated as an unassociated allocatable. + if (context.languageFeatures().ShouldWarn( + common::LanguageFeature::NullActualForAllocatable)) { + messages.Say( + "Allocatable %s is associated with a null pointer"_port_en_US, + dummyName); + } + } else { + messages.Say( + "A null pointer may not be associated with allocatable %s without INTENT(IN)"_err_en_US, + dummyName); + } + } else { messages.Say( "ALLOCATABLE %s must be associated with an ALLOCATABLE actual argument"_err_en_US, dummyName); } - if (actualIsAllocatable && actualIsCoindexed && - dummy.intent != common::Intent::In) { - messages.Say( - "ALLOCATABLE %s must have INTENT(IN) to be associated with a coindexed actual argument"_err_en_US, - dummyName); - } if (!actualIsCoindexed && actualLastSymbol && actualLastSymbol->Corank() != dummy.type.corank()) { messages.Say( @@ -790,8 +807,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, // NULL(MOLD=) checking for non-intrinsic procedures bool dummyIsOptional{ dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)}; - bool actualIsNull{evaluate::IsNullPointer(actual)}; - if (!intrinsic && !dummyIsPointer && !dummyIsOptional && actualIsNull) { + if (!intrinsic && !dummyIsAllocatableOrPointer && !dummyIsOptional && + actualIsNull) { messages.Say( "Actual argument associated with %s may not be null pointer %s"_err_en_US, dummyName, actual.AsFortran()); @@ -1083,12 +1100,19 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg, } else if (object.attrs.test(characteristics::DummyDataObject:: Attr::Allocatable) && evaluate::IsNullPointer(*expr)) { - // Unsupported extension that more or less naturally falls - // out of other Fortran implementations that pass separate - // base address and descriptor address physical arguments - messages.Say( - "Null actual argument '%s' may not be associated with allocatable %s"_err_en_US, - expr->AsFortran(), dummyName); + if (object.intent == common::Intent::In) { + // Extension (Intel, NAG, XLF); see CheckExplicitDataArg. + if (context.languageFeatures().ShouldWarn(common:: + LanguageFeature::NullActualForAllocatable)) { + messages.Say( + "Allocatable %s is associated with NULL()"_port_en_US, + dummyName); + } + } else { + messages.Say( + "NULL() actual argument '%s' may not be associated with allocatable %s without INTENT(IN)"_err_en_US, + expr->AsFortran(), dummyName); + } } else { messages.Say( "Actual argument '%s' associated with %s is not a variable or typed expression"_err_en_US, diff --git a/flang/test/Semantics/call27.f90 b/flang/test/Semantics/call27.f90 index 965ec401953f430..062df6e45da8908 100644 --- a/flang/test/Semantics/call27.f90 +++ b/flang/test/Semantics/call27.f90 @@ -1,10 +1,10 @@ -! RUN: %python %S/test_errors.py %s %flang_fc1 +! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic ! Catch NULL() actual argument association with allocatable dummy argument program test - !ERROR: Null actual argument 'NULL()' may not be associated with allocatable dummy argument 'a=' + !ERROR: NULL() actual argument 'NULL()' may not be associated with allocatable dummy argument 'a=' without INTENT(IN) call foo1(null()) - !ERROR: Null actual argument 'NULL()' may not be associated with allocatable dummy argument 'a=' - call foo2(null()) ! perhaps permissible later on user request + !PORTABILITY: Allocatable dummy argument 'a=' is associated with NULL() + call foo2(null()) call foo3(null()) ! ok contains subroutine foo1(a) |
jeanPerier
approved these changes
Sep 18, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
…mmy argument Several compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well. Pull request: llvm#66256
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
llvm#66256) …mmy argument Several compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
llvm#66256) …mmy argument Several compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
llvm#66256) …mmy argument Several compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…mmy argument
Several compilers accept a null pointer (with or without a MOLD=) as an actual argument for association with an INTENT(IN) allocatable dummy argument. At runtime, the allocatable dummy argument appears to be in the unallocated state. This seems useful, unambiguous, unlikely to invalidate conforming code, and works with Intel, NAG, & XLF, so it should be supported with an optional portability warning in this compiler as well.