[PATCH] D86172: [flang] Fix assert on constant folding of extended types
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 18 14:56:18 PDT 2020
PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld requested review of this revision.
When we define a derived type that extends another derived type, we can then
create a structure constructor that contains values for the fields of both the
child type and its parent. The compiler's internal representation of that
value contained the name of the parent type where a component name would
normally appear. This caused an assert during contant folding.
I fixed this by changing the function "CreateComponent()" in
lib/Semantics/expression.cpp to no longer include type names in values of type
"evaluate::Component".
I also added the test Evaluate/folding12.f90 to exercise the affected code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86172
Files:
flang/lib/Semantics/expression.cpp
flang/test/Evaluate/folding12.f90
Index: flang/test/Evaluate/folding12.f90
===================================================================
--- /dev/null
+++ flang/test/Evaluate/folding12.f90
@@ -0,0 +1,23 @@
+! RUN: %S/test_folding.sh %s %t %f18
+! Test folding of structure constructors
+module m
+ type parent_type
+ integer :: parent_field
+ end type parent_type
+ type, extends(parent_type) :: child_type
+ integer :: child_field
+ end type child_type
+ type(child_type), parameter :: child_var1 = child_type(343, 2)
+ logical, parameter :: test_direct = child_var1%child_field == 2
+ logical, parameter :: test_parent = child_var1%parent_field == 343
+ type(child_type), parameter :: array_var(2) = &
+ [child_type(343, 2), child_type(256, 4)]
+ logical, parameter :: test_array_child = array_var(2)%child_field == 4
+ logical, parameter :: test_array_parent = array_var(2)%parent_field == 256
+ type array_type
+ real, dimension(3) :: real_field
+ end type array_type
+ type(array_type), parameter :: array_var2 = &
+ array_type([(real(i*i), i = 1,3)])
+ logical, parameter :: test_array_var = array_var2%real_field(2) == 4.0
+end module
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -953,19 +953,11 @@
std::move(designator.u));
}
-// Components of parent derived types are explicitly represented as such.
static std::optional<Component> CreateComponent(
DataRef &&base, const Symbol &component, const semantics::Scope &scope) {
- if (&component.owner() == &scope) {
+ if (scope.FindComponent(component.name())) {
return Component{std::move(base), component};
}
- if (const semantics::Scope * parentScope{scope.GetDerivedTypeParent()}) {
- if (const Symbol * parentComponent{parentScope->GetSymbol()}) {
- return CreateComponent(
- DataRef{Component{std::move(base), *parentComponent}}, component,
- *parentScope);
- }
- }
return std::nullopt;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86172.286404.patch
Type: text/x-patch
Size: 2060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200818/563bf0e4/attachment.bin>
More information about the llvm-commits
mailing list