Skip to content

Commit 8ed7ea0

Browse files
authored
[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.
1 parent d0bafb5 commit 8ed7ea0

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5550,8 +5550,7 @@ void DeclarationVisitor::Post(const parser::TypeParamDefStmt &x) {
55505550
SetType(name, *type);
55515551
if (auto &init{
55525552
std::get<std::optional<parser::ScalarIntConstantExpr>>(decl.t)}) {
5553-
if (auto maybeExpr{EvaluateNonPointerInitializer(
5554-
*symbol, *init, init->thing.thing.thing.value().source)}) {
5553+
if (auto maybeExpr{AnalyzeExpr(context(), *init)}) {
55555554
if (auto *intExpr{std::get_if<SomeIntExpr>(&maybeExpr->u)}) {
55565555
symbol->get<TypeParamDetails>().set_init(std::move(*intExpr));
55575556
}

flang/test/Semantics/modfile12.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ subroutine baz(x)
4141
! real(4)::y(1_8:8_8)
4242
! type::t(c,d)
4343
! integer(4),kind::c=1_4
44-
! integer(4),len::d=3_4
44+
! integer(4),len::d=3_8
4545
! end type
4646
! type(t(c=4_4,d=:)),allocatable::z
4747
! class(t(c=5_4,d=:)),allocatable::z2

flang/test/Semantics/modfile17.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ module m
9797
!integer(k8)::j8
9898
!end type
9999
!type::defaulted(n1,n2,n4,n8)
100-
!integer(1),kind::n1=1_1
101-
!integer(2),kind::n2=int(2_4*int(int(n1,kind=1),kind=4),kind=2)
100+
!integer(1),kind::n1=1_4
101+
!integer(2),kind::n2=2_4*int(int(n1,kind=1),kind=4)
102102
!integer(4),kind::n4=2_4*int(int(n2,kind=2),kind=4)
103-
!integer(8),kind::n8=int(12_4-int(n4,kind=4),kind=8)
103+
!integer(8),kind::n8=12_4-int(n4,kind=4)
104104
!type(capture(k1=int(n1,kind=1),k2=int(n2,kind=2),k4=int(n4,kind=4),k8=n8))::cap
105105
!end type
106106
!type,extends(defaulted)::extension(k5)

flang/test/Semantics/pdt03.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
type t(kp1,kp2)
3+
integer, kind :: kp1
4+
integer(kp1), kind :: kp2 = kp1
5+
end type
6+
type(t(kp1=8_8)) x
7+
!CHECK: 4_4, 8_4, 8_4, 8_8
8+
print *, kind(x%kp1), x%kp1, kind(x%kp2), x%kp2
9+
end

0 commit comments

Comments
 (0)