[flang] Allow initialization in blank COMMON

This is nonconformant usage, but widely accepted as an extension.
Downgrade the error message to a warning.

Differential Revision: https://reviews.llvm.org/D117152
This commit is contained in:
Peter Klausler 2021-12-30 08:14:59 -08:00
parent bfd0cbd4eb
commit 63a2987d51
4 changed files with 24 additions and 16 deletions

View File

@ -196,6 +196,7 @@ end
exactly one is unlimited polymorphic).
* External unit 0 is predefined and connected to the standard error output,
and defined as `ERROR_UNIT` in the intrinsic `ISO_FORTRAN_ENV` module.
* Objects in blank COMMON may be initialized.
### Extensions supported when enabled by options

View File

@ -63,7 +63,6 @@ public:
: IsFunctionResult(symbol) ? "Function result"
: IsAllocatable(symbol) ? "Allocatable"
: IsInitialized(symbol, true) ? "Default-initialized"
: IsInBlankCommon(symbol) ? "Blank COMMON object"
: IsProcedure(symbol) && !IsPointer(symbol) ? "Procedure"
// remaining checks don't apply to components
: !isFirstSymbol ? nullptr
@ -77,11 +76,17 @@ public:
"%s '%s' must not be initialized in a DATA statement"_err_en_US,
whyNot, symbol.name());
return false;
} else if (IsProcedurePointer(symbol)) {
}
if (IsProcedurePointer(symbol)) {
context_.Say(source_,
"Procedure pointer '%s' in a DATA statement is not standard"_en_US,
symbol.name());
}
if (IsInBlankCommon(symbol)) {
context_.Say(source_,
"Blank COMMON object '%s' in a DATA statement is not standard"_en_US,
symbol.name());
}
return true;
}
bool operator()(const evaluate::Component &component) {

View File

@ -134,19 +134,8 @@ module m
program new
use m2
integer a
real b,c
type seqType
sequence
integer number
end type
type(SeqType) num
COMMON b,a,c,num
type(newType) m2_number2
!C876
!ERROR: Blank COMMON object 'b' must not be initialized in a DATA statement
DATA b /1/
!C876
!ERROR: USE-associated object 'm2_i' must not be initialized in a DATA statement
DATA m2_i /1/
!C876
@ -155,7 +144,4 @@ module m
!C876
!OK: m2_number2 is not associated through use association
DATA m2_number2%number /1/
!C876
!ERROR: Blank COMMON object 'num' must not be initialized in a DATA statement
DATA num%number /1/
end program

View File

@ -0,0 +1,16 @@
! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s
! Verify varnings on nonconforming DATA statements
! As a common extension, C876 violations are not errors.
program main
type :: seqType
sequence
integer :: number
end type
type(seqType) :: x
integer :: j
common j, x, y
!CHECK: Blank COMMON object 'j' in a DATA statement is not standard
data j/1/
!CHECK: Blank COMMON object 'x' in a DATA statement is not standard
data x%number/2/
end