Unverified Commit 1bbfade9 authored by Caroline Newcombe's avatar Caroline Newcombe Committed by GitHub
Browse files

[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.
parent a0a1e6aa
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+18 −0
Original line number Diff line number Diff line
!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