[flang-commits] [flang] f2897b8 - [flang] Disallow pointer constants
Peter Steinfeld via flang-commits
flang-commits at lists.llvm.org
Fri Oct 16 12:34:32 PDT 2020
Author: Peter Steinfeld
Date: 2020-10-16T12:31:42-07:00
New Revision: f2897b8f45c1df944e45f849757d2a2507e96805
URL: https://github.com/llvm/llvm-project/commit/f2897b8f45c1df944e45f849757d2a2507e96805
DIFF: https://github.com/llvm/llvm-project/commit/f2897b8f45c1df944e45f849757d2a2507e96805.diff
LOG: [flang] Disallow pointer constants
None of the other Fortran compilers allow them.
Differential Revision: https://reviews.llvm.org/D89581
Added:
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/resolve90.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index dee26ab59227..6138297c273b 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1280,6 +1280,12 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
CheckConflicting(symbol, Attr::POINTER, Attr::TARGET);
CheckConflicting(symbol, Attr::POINTER, Attr::ALLOCATABLE); // C751
CheckConflicting(symbol, Attr::POINTER, Attr::INTRINSIC);
+ // Prohibit constant pointers. The standard does not explicitly prohibit
+ // them, but the PARAMETER attribute requires a entity-decl to have an
+ // initialization that is a constant-expr, and the only form of
+ // initialization that allows a constant-expr is the one that's not a "=>"
+ // pointer initialization. See C811, C807, and section 8.5.13.
+ CheckConflicting(symbol, Attr::POINTER, Attr::PARAMETER);
if (symbol.Corank() > 0) {
messages_.Say(
"'%s' may not have the POINTER attribute because it is a coarray"_err_en_US,
diff --git a/flang/test/Semantics/resolve90.f90 b/flang/test/Semantics/resolve90.f90
index 3260ee983fb9..12fc707dedad 100644
--- a/flang/test/Semantics/resolve90.f90
+++ b/flang/test/Semantics/resolve90.f90
@@ -1,10 +1,13 @@
! RUN: %S/test_errors.sh %s %t %f18
+! Testing for pointer constant, along with :
! C751 A component shall not have both the ALLOCATABLE and POINTER attributes.
! C752 If the CONTIGUOUS attribute is specified, the component shall be an
! array with the POINTER attribute.
! C753 The * char-length option is permitted only if the component is of type
! character.
subroutine s()
+ !ERROR: 'nullint' may not have both the POINTER and PARAMETER attributes
+ integer, pointer, parameter :: nullint => null()
type derivedType
!ERROR: 'pointerallocatablefield' may not have both the POINTER and ALLOCATABLE attributes
real, pointer, allocatable :: pointerAllocatableField
More information about the flang-commits
mailing list