[flang-commits] [PATCH] D117152: [flang] Allow initialization in blank COMMON

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jan 12 14:06:23 PST 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
klausler requested review of this revision.

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


https://reviews.llvm.org/D117152

Files:
  flang/docs/Extensions.md
  flang/lib/Semantics/check-data.cpp
  flang/test/Semantics/data04.f90
  flang/test/Semantics/data14.f90


Index: flang/test/Semantics/data14.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/data14.f90
@@ -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
Index: flang/test/Semantics/data04.f90
===================================================================
--- flang/test/Semantics/data04.f90
+++ flang/test/Semantics/data04.f90
@@ -134,19 +134,8 @@
 
   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 @@
     !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
Index: flang/lib/Semantics/check-data.cpp
===================================================================
--- flang/lib/Semantics/check-data.cpp
+++ flang/lib/Semantics/check-data.cpp
@@ -63,7 +63,6 @@
                 : 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 @@
           "%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) {
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -190,6 +190,7 @@
   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
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117152.399451.patch
Type: text/x-patch
Size: 3361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220112/cc328c41/attachment.bin>


More information about the flang-commits mailing list