[flang-commits] [PATCH] D143827: [flang] Pointers returned from functions are not definable as pointers
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Feb 13 16:15:58 PST 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30d932305567: [flang] Pointers returned from functions are not definable as pointers (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143827/new/
https://reviews.llvm.org/D143827
Files:
flang/lib/Semantics/definable.cpp
flang/test/Semantics/definable04.f90
Index: flang/test/Semantics/definable04.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/definable04.f90
@@ -0,0 +1,27 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+module m
+ integer, target :: n
+ contains
+ function ptr()
+ integer, pointer :: ptr
+ ptr => n
+ end
+ subroutine s1(p)
+ integer, pointer, intent(in) :: p
+ end
+ subroutine s2(p)
+ integer, pointer, intent(in out) :: p
+ end
+end
+
+program test
+ use m
+ integer, pointer :: p
+ p => ptr() ! ok
+ ptr() = 1 ! ok
+ call s1(ptr()) ! ok
+ call s1(null()) ! ok
+ !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'p=' is not definable
+ !BECAUSE: 'ptr()' is not a definable pointer
+ call s2(ptr())
+end
Index: flang/lib/Semantics/definable.cpp
===================================================================
--- flang/lib/Semantics/definable.cpp
+++ flang/lib/Semantics/definable.cpp
@@ -267,11 +267,10 @@
expr.AsFortran());
}
return WhyNotDefinable(at, scope, flags, *dataRef);
- }
- if (evaluate::IsVariable(expr)) {
- return std::nullopt; // result of function returning a pointer - ok
- }
- if (flags.test(DefinabilityFlag::PointerDefinition)) {
+ } else if (evaluate::IsNullPointer(expr)) {
+ return parser::Message{
+ at, "'%s' is a null pointer"_because_en_US, expr.AsFortran()};
+ } else if (flags.test(DefinabilityFlag::PointerDefinition)) {
if (const auto *procDesignator{
std::get_if<evaluate::ProcedureDesignator>(&expr.u)}) {
// Defining a procedure pointer
@@ -288,13 +287,14 @@
}
}
}
- }
- if (evaluate::IsNullPointer(expr)) {
return parser::Message{
- at, "'%s' is a null pointer"_because_en_US, expr.AsFortran()};
+ at, "'%s' is not a definable pointer"_because_en_US, expr.AsFortran()};
+ } else if (!evaluate::IsVariable(expr)) {
+ return parser::Message{at,
+ "'%s' is not a variable or pointer"_because_en_US, expr.AsFortran()};
+ } else {
+ return std::nullopt;
}
- return parser::Message{
- at, "'%s' is not a variable or pointer"_because_en_US, expr.AsFortran()};
}
} // namespace Fortran::semantics
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143827.497144.patch
Type: text/x-patch
Size: 2246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230214/75b3679e/attachment-0001.bin>
More information about the flang-commits
mailing list