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

via flang-commits flang-commits at lists.llvm.org
Fri May 1 11:05:43 PDT 2026


Author: Caroline Newcombe
Date: 2026-05-01T13:05:38-05:00
New Revision: 1bbfade93ff3ea1df295a740ef5547763304f891

URL: https://github.com/llvm/llvm-project/commit/1bbfade93ff3ea1df295a740ef5547763304f891
DIFF: https://github.com/llvm/llvm-project/commit/1bbfade93ff3ea1df295a740ef5547763304f891.diff

LOG: [flang] Fix crash on PARAMETER attribute applied to POINTER (#194885)

Issue #194725: 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.

Added: 
    flang/test/Semantics/resolve129.f90

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 9ed2e73c155b0..86eefc57f9749 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5904,7 +5904,7 @@ 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 || 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
new file mode 100644
index 0000000000000..579fe50240eaf
--- /dev/null
+++ b/flang/test/Semantics/resolve129.f90
@@ -0,0 +1,18 @@
+!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
+
+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