[flang-commits] [flang] 81d857d - [flang][NFC] Document ambiguous case of DATA in BLOCK

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Sep 22 18:25:08 PDT 2022


Author: Peter Klausler
Date: 2022-09-22T18:24:52-07:00
New Revision: 81d857d037b53cb7abf4ef091e9ba6ec007b5809

URL: https://github.com/llvm/llvm-project/commit/81d857d037b53cb7abf4ef091e9ba6ec007b5809
DIFF: https://github.com/llvm/llvm-project/commit/81d857d037b53cb7abf4ef091e9ba6ec007b5809.diff

LOG: [flang][NFC] Document ambiguous case of DATA in BLOCK

Fortran is not clear about the semantics of

```
  subroutine subr
    integer n = 1
    block
      data n/2/
    end block
  end subroutine
```

which could be interpreted as having two variables, each
named 'n', or as having one variable 'n' with invalid double
initialization.  Precedents from existing compilers are also
in disagreement.

The most common interpretation, however, agrees with a subtle
reading of the standard: BLOCK constructs scope names that have
local specifications, and a DATA statement is a declaration
construct, not a specification construct.  So this example is
*not* acceptable.

Differential Revision: https://reviews.llvm.org/D134391

Added: 
    

Modified: 
    flang/docs/Extensions.md

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 9e674c15c2f1e..45eea70297f68 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -415,3 +415,25 @@ end
   to some forms of input in this situation.)
   For sequential formatted output, RECL= serves as a limit on record lengths
   that raises an error when it is exceeded.
+
+* When a `DATA` statement in a `BLOCK` construct could be construed as
+  either initializing a host-associated object or declaring a new local
+  initialized object, f18 interprets the standard's classification of
+  a `DATA` statement as being a "declaration" rather than a "specification"
+  construct, and notes that the `BLOCK` construct is defined as localizing
+  names that have specifications in the `BLOCK` construct.
+  So this example will elicit an error about multiple initialization:
+```
+subroutine subr
+  integer n = 1
+  block
+    data n/2/
+  end block
+end subroutine
+```
+
+  Other Fortran compilers disagree with each other in their interpretations
+  of this example.
+  The precedent among the most commonly used compilers
+  agrees with f18's interpretation: a `DATA` statement without any other
+  specification of the name refers to the host-associated object.


        


More information about the flang-commits mailing list