[flang-commits] [flang] 8ed7ea0 - [flang] Defer conversion of PDT default initializers (#91026)
via flang-commits
flang-commits at lists.llvm.org
Thu May 9 09:56:06 PDT 2024
Author: Peter Klausler
Date: 2024-05-09T09:56:01-07:00
New Revision: 8ed7ea08962bb878d31052c15e811d1a6cda0f07
URL: https://github.com/llvm/llvm-project/commit/8ed7ea08962bb878d31052c15e811d1a6cda0f07
DIFF: https://github.com/llvm/llvm-project/commit/8ed7ea08962bb878d31052c15e811d1a6cda0f07.diff
LOG: [flang] Defer conversion of PDT default initializers (#91026)
As the kinds of the integer types of type parameters may well depend on
the values of other type parameters, defer the attempt to convert their
values to the point of type instantiation instead of doing it during
declaration processing.
Added:
flang/test/Semantics/pdt03.f90
Modified:
flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/modfile12.f90
flang/test/Semantics/modfile17.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 61394b0f41de7..2199e3f16e620 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5550,8 +5550,7 @@ void DeclarationVisitor::Post(const parser::TypeParamDefStmt &x) {
SetType(name, *type);
if (auto &init{
std::get<std::optional<parser::ScalarIntConstantExpr>>(decl.t)}) {
- if (auto maybeExpr{EvaluateNonPointerInitializer(
- *symbol, *init, init->thing.thing.thing.value().source)}) {
+ if (auto maybeExpr{AnalyzeExpr(context(), *init)}) {
if (auto *intExpr{std::get_if<SomeIntExpr>(&maybeExpr->u)}) {
symbol->get<TypeParamDetails>().set_init(std::move(*intExpr));
}
diff --git a/flang/test/Semantics/modfile12.f90 b/flang/test/Semantics/modfile12.f90
index 17b6e95c4a562..41ab300e00f67 100644
--- a/flang/test/Semantics/modfile12.f90
+++ b/flang/test/Semantics/modfile12.f90
@@ -41,7 +41,7 @@ subroutine baz(x)
! real(4)::y(1_8:8_8)
! type::t(c,d)
! integer(4),kind::c=1_4
-! integer(4),len::d=3_4
+! integer(4),len::d=3_8
! end type
! type(t(c=4_4,d=:)),allocatable::z
! class(t(c=5_4,d=:)),allocatable::z2
diff --git a/flang/test/Semantics/modfile17.f90 b/flang/test/Semantics/modfile17.f90
index 189d8a83de8c5..4ab5cc85db253 100644
--- a/flang/test/Semantics/modfile17.f90
+++ b/flang/test/Semantics/modfile17.f90
@@ -97,10 +97,10 @@ module m
!integer(k8)::j8
!end type
!type::defaulted(n1,n2,n4,n8)
-!integer(1),kind::n1=1_1
-!integer(2),kind::n2=int(2_4*int(int(n1,kind=1),kind=4),kind=2)
+!integer(1),kind::n1=1_4
+!integer(2),kind::n2=2_4*int(int(n1,kind=1),kind=4)
!integer(4),kind::n4=2_4*int(int(n2,kind=2),kind=4)
-!integer(8),kind::n8=int(12_4-int(n4,kind=4),kind=8)
+!integer(8),kind::n8=12_4-int(n4,kind=4)
!type(capture(k1=int(n1,kind=1),k2=int(n2,kind=2),k4=int(n4,kind=4),k8=n8))::cap
!end type
!type,extends(defaulted)::extension(k5)
diff --git a/flang/test/Semantics/pdt03.f90 b/flang/test/Semantics/pdt03.f90
new file mode 100644
index 0000000000000..2fb63d21540b1
--- /dev/null
+++ b/flang/test/Semantics/pdt03.f90
@@ -0,0 +1,9 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+type t(kp1,kp2)
+ integer, kind :: kp1
+ integer(kp1), kind :: kp2 = kp1
+end type
+type(t(kp1=8_8)) x
+!CHECK: 4_4, 8_4, 8_4, 8_8
+print *, kind(x%kp1), x%kp1, kind(x%kp2), x%kp2
+end
More information about the flang-commits
mailing list