[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
Wed Apr 29 08:28:35 PDT 2026
https://github.com/cenewcombe created https://github.com/llvm/llvm-project/pull/194885
Issue #194725: Flang hits an internal assertion `CHECK(!IsPointer(symbol))` in check-expression.cpp when a variable is declared with both POINTER and PARAMETER attributes. This is an illegal attribute combination (a POINTER cannot be a PARAMETER).
```
subroutine a7
pointer A
parameter (A=3)
end subroutine
```
The existing check for this attribute conflict in `CheckConflicting` runs too late — after `Pre(NamedConstantDef)`
has already called `EvaluateNonPointerInitializer` on the POINTER symbol, triggering the fatal assertion.
This patch adds a POINTER check to the existing early-out guard in `DeclarationVisitor::Pre(NamedConstantDef)` that already handles CrayPointer/CrayPointee, so the error is diagnosed and we return before reaching the assertion. A LIT test has been added as well.
>From 61743b77b58917704d88ce5f1c954caa8388d14f 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] [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..32b02dfbe22c2
--- /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
\ No newline at end of file
More information about the flang-commits
mailing list