[flang-commits] [flang] 2503f28 - [flang] Accept TYPE(intrinsic type) in declarations only for non-extension type

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Thu Apr 14 18:19:50 PDT 2022


Author: Peter Klausler
Date: 2022-04-14T18:19:37-07:00
New Revision: 2503f286486c1f545d22dd03923478727946caf4

URL: https://github.com/llvm/llvm-project/commit/2503f286486c1f545d22dd03923478727946caf4
DIFF: https://github.com/llvm/llvm-project/commit/2503f286486c1f545d22dd03923478727946caf4.diff

LOG: [flang] Accept TYPE(intrinsic type) in declarations only for non-extension type

To avoid clashing with names of user derived types, the redundant
syntax TYPE(intrinsic type spec) must be interpreted as a monomorphic
derived type when "intrinsic type spec" is a single word.  This
affects TYPE(BYTE) and TYPE(DOUBLECOMPLEX), but not TYPE(DOUBLE COMPLEX)
in free form source.

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

Added: 
    

Modified: 
    flang/docs/Extensions.md
    flang/lib/Parser/Fortran-parsers.cpp

Removed: 
    


################################################################################
diff  --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index a648d717d82e5..e25331c85a21a 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -82,13 +82,14 @@ end
 * `$` and `@` as legal characters in names
 * Initialization in type declaration statements using `/values/`
 * Kind specification with `*`, e.g. `REAL*4`
-* `DOUBLE COMPLEX`
+* `DOUBLE COMPLEX` as a synonym for `COMPLEX(KIND(0.D0))` --
+  but not when spelled `TYPE(DOUBLECOMPLEX)`.
 * Signed complex literal constants
 * DEC `STRUCTURE`, `RECORD`, with '%FILL'; but `UNION`, and `MAP`
   are not yet supported throughout compilation, and elicit a
   "not yet implemented" message.
 * Structure field access with `.field`
-* `BYTE` as synonym for `INTEGER(KIND=1)`
+* `BYTE` as synonym for `INTEGER(KIND=1)`; but not when spelled `TYPE(BYTE)`.
 * Quad precision REAL literals with `Q`
 * `X` prefix/suffix as synonym for `Z` on hexadecimal literals
 * `B`, `O`, `Z`, and `X` accepted as suffixes as well as prefixes

diff  --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index 39dbd2c3179ab..81f704bc34cc7 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -168,10 +168,13 @@ TYPE_CONTEXT_PARSER("type spec"_en_US,
 // for TYPE (...), rather than putting the alternatives within it, which
 // would fail on "TYPE(real_derived)" with a misrecognition of "real" as an
 // intrinsic-type-spec.
+// N.B. TYPE(x) is a derived type if x is a one-word extension intrinsic
+// type (BYTE or DOUBLECOMPLEX), not the extension intrinsic type.
 TYPE_CONTEXT_PARSER("declaration type spec"_en_US,
     construct<DeclarationTypeSpec>(intrinsicTypeSpec) ||
         "TYPE" >>
-            (parenthesized(construct<DeclarationTypeSpec>(intrinsicTypeSpec)) ||
+            (parenthesized(construct<DeclarationTypeSpec>(
+                 !"DOUBLECOMPLEX"_tok >> !"BYTE"_tok >> intrinsicTypeSpec)) ||
                 parenthesized(construct<DeclarationTypeSpec>(
                     construct<DeclarationTypeSpec::Type>(derivedTypeSpec))) ||
                 construct<DeclarationTypeSpec>(
@@ -209,7 +212,7 @@ TYPE_CONTEXT_PARSER("intrinsic type spec"_en_US,
             "LOGICAL" >> maybe(kindSelector))),
         extension<LanguageFeature::DoubleComplex>(
             "nonstandard usage: DOUBLE COMPLEX"_port_en_US,
-            construct<IntrinsicTypeSpec>("DOUBLE COMPLEX" >>
+            construct<IntrinsicTypeSpec>("DOUBLE COMPLEX"_sptok >>
                 construct<IntrinsicTypeSpec::DoubleComplex>())),
         extension<LanguageFeature::Byte>("nonstandard usage: BYTE"_port_en_US,
             construct<IntrinsicTypeSpec>(construct<IntegerTypeSpec>(


        


More information about the flang-commits mailing list