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

via flang-commits flang-commits at lists.llvm.org
Wed Apr 29 08:29:16 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Caroline Newcombe (cenewcombe)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/194885.diff


2 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+2-1) 
- (added) flang/test/Semantics/resolve129.f90 (+10) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list