[flang-commits] [PATCH] D119744: [flang] Accept structure constructor value for polymorphic component

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Feb 14 16:00:51 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbca13174bc77: [flang] Accept structure constructor value for polymorphic component (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119744/new/

https://reviews.llvm.org/D119744

Files:
  flang/lib/Evaluate/tools.cpp
  flang/lib/Semantics/expression.cpp
  flang/test/Semantics/data02.f90
  flang/test/Semantics/structconst01.f90
  flang/test/Semantics/structconst02.f90


Index: flang/test/Semantics/structconst02.f90
===================================================================
--- flang/test/Semantics/structconst02.f90
+++ flang/test/Semantics/structconst02.f90
@@ -32,9 +32,9 @@
 !    call scalararg(scalar(4)(5.,6,(7._8,8._2),4_'b',.true._4))
     call scalararg(scalar(4)(ix=5.,rx=6,zx=(7._8,8._2),cx=4_'b',lx=.true.))
     call scalararg(scalar(4)(5.,6,(7._8,8._2),4_'b',.true.))
-    !ERROR: Value in structure constructor of type CHARACTER(1) is incompatible with component 'ix' of type INTEGER(4)
+    !ERROR: Value in structure constructor of type 'CHARACTER(1)' is incompatible with component 'ix' of type 'INTEGER(4)'
     call scalararg(scalar(4)(ix='a'))
-    !ERROR: Value in structure constructor of type LOGICAL(4) is incompatible with component 'ix' of type INTEGER(4)
+    !ERROR: Value in structure constructor of type 'LOGICAL(4)' is incompatible with component 'ix' of type 'INTEGER(4)'
     call scalararg(scalar(4)(ix=.false.))
     !ERROR: Rank-1 array value is not compatible with scalar component 'ix'
     call scalararg(scalar(4)(ix=[1]))
Index: flang/test/Semantics/structconst01.f90
===================================================================
--- flang/test/Semantics/structconst01.f90
+++ flang/test/Semantics/structconst01.f90
@@ -73,11 +73,18 @@
       class(*), allocatable :: p
     end type poly
     type(poly) :: x
+    type :: poly2
+      class(type1(1)), allocatable :: p1
+      type(type1(1)), allocatable :: p2
+    end type poly2
+    type(type1(1)) :: t1val
+    type(poly2) :: x2
     ! These cases are not errors
     x = poly(1)
     x = poly('hello')
     x = poly(type1(1)(123))
-    !ERROR: Value in structure constructor is incompatible with  component 'p' of type CLASS(*)
+    x2 = poly2(t1val, t1val)
+    !ERROR: Value in structure constructor is incompatible with component 'p' of type CLASS(*)
     x = poly(z'feedface')
   end subroutine
 end module module1
Index: flang/test/Semantics/data02.f90
===================================================================
--- flang/test/Semantics/data02.f90
+++ flang/test/Semantics/data02.f90
@@ -6,7 +6,7 @@
     character(1) :: c
   end type
   type(t) :: x
-  !ERROR: Value in structure constructor of type INTEGER(4) is incompatible with component 'c' of type CHARACTER(KIND=1,LEN=1_8)
+  !ERROR: Value in structure constructor of type 'INTEGER(4)' is incompatible with component 'c' of type 'CHARACTER(KIND=1,LEN=1_8)'
   data x /t(1)/
 end
 
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1754,8 +1754,8 @@
           } else if (valueType) {
             AttachDeclaration(
                 Say(expr.source,
-                    "Value in structure constructor of type %s is "
-                    "incompatible with component '%s' of type %s"_err_en_US,
+                    "Value in structure constructor of type '%s' is "
+                    "incompatible with component '%s' of type '%s'"_err_en_US,
                     valueType->AsFortran(), symbol->name(),
                     symType->AsFortran()),
                 *symbol);
@@ -1763,7 +1763,7 @@
             AttachDeclaration(
                 Say(expr.source,
                     "Value in structure constructor is incompatible with "
-                    " component '%s' of type %s"_err_en_US,
+                    "component '%s' of type %s"_err_en_US,
                     symbol->name(), symType->AsFortran()),
                 *symbol);
           }
Index: flang/lib/Evaluate/tools.cpp
===================================================================
--- flang/lib/Evaluate/tools.cpp
+++ flang/lib/Evaluate/tools.cpp
@@ -653,7 +653,9 @@
     break;
   case TypeCategory::Derived:
     if (auto fromType{x.GetType()}) {
-      if (type == *fromType) {
+      if (type.IsTkCompatibleWith(*fromType)) {
+        // "x" could be assigned or passed to "type", or appear in a
+        // structure constructor as a value for a component with "type"
         return std::move(x);
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119744.408662.patch
Type: text/x-patch
Size: 4165 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220215/cd3b2450/attachment-0001.bin>


More information about the flang-commits mailing list