@@ -44,26 +44,23 @@ void RTDEF(AllocatableInitDerived)(Descriptor &descriptor,
44
44
45
45
void RTDEF (AllocatableInitIntrinsicForAllocate)(Descriptor &descriptor,
46
46
TypeCategory category, int kind, int rank, int corank) {
47
- if (descriptor.IsAllocated ()) {
48
- return ;
47
+ if (! descriptor.IsAllocated ()) {
48
+ RTNAME (AllocatableInitIntrinsic)(descriptor, category, kind, rank, corank) ;
49
49
}
50
- RTNAME (AllocatableInitIntrinsic)(descriptor, category, kind, rank, corank);
51
50
}
52
51
53
52
void RTDEF (AllocatableInitCharacterForAllocate)(Descriptor &descriptor,
54
53
SubscriptValue length, int kind, int rank, int corank) {
55
- if (descriptor.IsAllocated ()) {
56
- return ;
54
+ if (! descriptor.IsAllocated ()) {
55
+ RTNAME (AllocatableInitCharacter)(descriptor, length, kind, rank, corank) ;
57
56
}
58
- RTNAME (AllocatableInitCharacter)(descriptor, length, kind, rank, corank);
59
57
}
60
58
61
59
void RTDEF (AllocatableInitDerivedForAllocate)(Descriptor &descriptor,
62
60
const typeInfo::DerivedType &derivedType, int rank, int corank) {
63
- if (descriptor.IsAllocated ()) {
64
- return ;
61
+ if (! descriptor.IsAllocated ()) {
62
+ RTNAME (AllocatableInitDerived)(descriptor, derivedType, rank, corank) ;
65
63
}
66
- RTNAME (AllocatableInitDerived)(descriptor, derivedType, rank, corank);
67
64
}
68
65
69
66
std::int32_t RTDEF (MoveAlloc)(Descriptor &to, Descriptor &from,
@@ -114,46 +111,49 @@ std::int32_t RTDEF(MoveAlloc)(Descriptor &to, Descriptor &from,
114
111
void RTDEF (AllocatableSetBounds)(Descriptor &descriptor, int zeroBasedDim,
115
112
SubscriptValue lower, SubscriptValue upper) {
116
113
INTERNAL_CHECK (zeroBasedDim >= 0 && zeroBasedDim < descriptor.rank ());
117
- descriptor.GetDimension (zeroBasedDim).SetBounds (lower, upper);
118
- // The byte strides are computed when the object is allocated.
114
+ if (descriptor.IsAllocatable () && !descriptor.IsAllocated ()) {
115
+ descriptor.GetDimension (zeroBasedDim).SetBounds (lower, upper);
116
+ // The byte strides are computed when the object is allocated.
117
+ }
119
118
}
120
119
121
120
void RTDEF (AllocatableSetDerivedLength)(
122
121
Descriptor &descriptor, int which, SubscriptValue x) {
123
- DescriptorAddendum *addendum{descriptor.Addendum ()};
124
- INTERNAL_CHECK (addendum != nullptr );
125
- addendum->SetLenParameterValue (which, x);
122
+ if (descriptor.IsAllocatable () && !descriptor.IsAllocated ()) {
123
+ DescriptorAddendum *addendum{descriptor.Addendum ()};
124
+ INTERNAL_CHECK (addendum != nullptr );
125
+ addendum->SetLenParameterValue (which, x);
126
+ }
126
127
}
127
128
128
129
void RTDEF (AllocatableApplyMold)(
129
130
Descriptor &descriptor, const Descriptor &mold, int rank) {
130
- if (descriptor.IsAllocated ()) {
131
- // 9.7.1.3 Return so the error can be emitted by AllocatableAllocate.
132
- return ;
131
+ if (descriptor.IsAllocatable () && !descriptor.IsAllocated ()) {
132
+ descriptor.ApplyMold (mold, rank);
133
133
}
134
- descriptor.ApplyMold (mold, rank);
135
134
}
136
135
137
136
int RTDEF (AllocatableAllocate)(Descriptor &descriptor, bool hasStat,
138
137
const Descriptor *errMsg, const char *sourceFile, int sourceLine) {
139
138
Terminator terminator{sourceFile, sourceLine};
140
139
if (!descriptor.IsAllocatable ()) {
141
140
return ReturnError (terminator, StatInvalidDescriptor, errMsg, hasStat);
142
- }
143
- if (descriptor.IsAllocated ()) {
141
+ } else if (descriptor.IsAllocated ()) {
144
142
return ReturnError (terminator, StatBaseNotNull, errMsg, hasStat);
145
- }
146
- int stat{ReturnError (terminator, descriptor.Allocate (), errMsg, hasStat)};
147
- if (stat == StatOk) {
148
- if (const DescriptorAddendum * addendum{descriptor.Addendum ()}) {
149
- if (const auto *derived{addendum->derivedType ()}) {
150
- if (!derived->noInitializationNeeded ()) {
151
- stat = Initialize (descriptor, *derived, terminator, hasStat, errMsg);
143
+ } else {
144
+ int stat{ReturnError (terminator, descriptor.Allocate (), errMsg, hasStat)};
145
+ if (stat == StatOk) {
146
+ if (const DescriptorAddendum * addendum{descriptor.Addendum ()}) {
147
+ if (const auto *derived{addendum->derivedType ()}) {
148
+ if (!derived->noInitializationNeeded ()) {
149
+ stat =
150
+ Initialize (descriptor, *derived, terminator, hasStat, errMsg);
151
+ }
152
152
}
153
153
}
154
154
}
155
+ return stat;
155
156
}
156
- return stat;
157
157
}
158
158
159
159
int RTDEF (AllocatableAllocateSource)(Descriptor &alloc,
@@ -173,14 +173,14 @@ int RTDEF(AllocatableDeallocate)(Descriptor &descriptor, bool hasStat,
173
173
Terminator terminator{sourceFile, sourceLine};
174
174
if (!descriptor.IsAllocatable ()) {
175
175
return ReturnError (terminator, StatInvalidDescriptor, errMsg, hasStat);
176
- }
177
- if (!descriptor.IsAllocated ()) {
176
+ } else if (!descriptor.IsAllocated ()) {
178
177
return ReturnError (terminator, StatBaseNull, errMsg, hasStat);
178
+ } else {
179
+ return ReturnError (terminator,
180
+ descriptor.Destroy (
181
+ /* finalize=*/ true , /* destroyPointers=*/ false , &terminator),
182
+ errMsg, hasStat);
179
183
}
180
- return ReturnError (terminator,
181
- descriptor.Destroy (
182
- /* finalize=*/ true , /* destroyPointers=*/ false , &terminator),
183
- errMsg, hasStat);
184
184
}
185
185
186
186
int RTDEF (AllocatableDeallocatePolymorphic)(Descriptor &descriptor,
0 commit comments