[flang-commits] [flang] [flang] Fix crash on PARAMETER attribute applied to POINTER (PR #194885)

Caroline Newcombe via flang-commits flang-commits at lists.llvm.org
Fri May 1 10:40:59 PDT 2026


https://github.com/cenewcombe updated https://github.com/llvm/llvm-project/pull/194885

>From 8e26ca80365cf063f9c580687ee30384102ba92a Mon Sep 17 00:00:00 2001
From: Caroline Newcombe <caroline.newcombe at hpe.com>
Date: Wed, 29 Apr 2026 10:18:50 -0500
Subject: [PATCH 1/2] [flang] Fix crash on PARAMETER attribute applied to
 POINTER

---
 flang/lib/Semantics/resolve-names.cpp |  3 ++-
 flang/test/Semantics/resolve129.f90   | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Semantics/resolve129.f90

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 3d42208688497..ed890b7803af9 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5893,7 +5893,8 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
   auto &symbol{HandleAttributeStmt(Attr::PARAMETER, name)};
   ConvertToObjectEntity(symbol);
   auto *details{symbol.detailsIf<ObjectEntityDetails>()};
-  if (!details || symbol.test(Symbol::Flag::CrayPointer) ||
+  if (!details || symbol.attrs().test(Attr::POINTER) ||
+      symbol.test(Symbol::Flag::CrayPointer) ||
       symbol.test(Symbol::Flag::CrayPointee)) {
     SayWithDecl(
         name, symbol, "PARAMETER attribute not allowed on '%s'"_err_en_US);
diff --git a/flang/test/Semantics/resolve129.f90 b/flang/test/Semantics/resolve129.f90
new file mode 100644
index 0000000000000..c3d4ecaf1b3ef
--- /dev/null
+++ b/flang/test/Semantics/resolve129.f90
@@ -0,0 +1,10 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1
+
+! Test that POINTER with PARAMETER doesn't crash.
+
+subroutine s1
+  !ERROR: 'a' may not have both the POINTER and PARAMETER attributes
+  pointer a
+  !ERROR: PARAMETER attribute not allowed on 'a'
+  parameter(a=3)
+end subroutine

>From 939d33cf33200b29a4922ce37c61d3c49b0400a8 Mon Sep 17 00:00:00 2001
From: Caroline Newcombe <caroline.newcombe at hpe.com>
Date: Fri, 1 May 2026 12:40:43 -0500
Subject: [PATCH 2/2] Updates per review comments

---
 flang/lib/Semantics/resolve-names.cpp | 3 +--
 flang/test/Semantics/resolve129.f90   | 8 ++++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index ed890b7803af9..8fd4d6ef9ba59 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5893,8 +5893,7 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
   auto &symbol{HandleAttributeStmt(Attr::PARAMETER, name)};
   ConvertToObjectEntity(symbol);
   auto *details{symbol.detailsIf<ObjectEntityDetails>()};
-  if (!details || symbol.attrs().test(Attr::POINTER) ||
-      symbol.test(Symbol::Flag::CrayPointer) ||
+  if (!details || IsPointer(symbol) || symbol.test(Symbol::Flag::CrayPointer) ||
       symbol.test(Symbol::Flag::CrayPointee)) {
     SayWithDecl(
         name, symbol, "PARAMETER attribute not allowed on '%s'"_err_en_US);
diff --git a/flang/test/Semantics/resolve129.f90 b/flang/test/Semantics/resolve129.f90
index c3d4ecaf1b3ef..579fe50240eaf 100644
--- a/flang/test/Semantics/resolve129.f90
+++ b/flang/test/Semantics/resolve129.f90
@@ -8,3 +8,11 @@ subroutine s1
   !ERROR: PARAMETER attribute not allowed on 'a'
   parameter(a=3)
 end subroutine
+
+subroutine s2
+  !ERROR: 'b' may not have both the POINTER and PARAMETER attributes
+  integer, pointer :: b
+  !ERROR: PARAMETER attribute not allowed on 'b'
+  parameter(b=3)
+end subroutine
+



More information about the flang-commits mailing list