@@ -83,10 +83,9 @@ static void Compare(Descriptor &result, const Descriptor &x,
83
83
RUNTIME_CHECK (
84
84
terminator, x.rank () == y.rank () || x.rank () == 0 || y.rank () == 0 );
85
85
int rank{std::max (x.rank (), y.rank ())};
86
- SubscriptValue lb[maxRank], ub[maxRank], xAt[maxRank], yAt[maxRank];
86
+ SubscriptValue ub[maxRank], xAt[maxRank], yAt[maxRank];
87
87
SubscriptValue elements{1 };
88
88
for (int j{0 }; j < rank; ++j) {
89
- lb[j] = 1 ;
90
89
if (x.rank () > 0 && y.rank () > 0 ) {
91
90
SubscriptValue xUB{x.GetDimension (j).Extent ()};
92
91
SubscriptValue yUB{y.GetDimension (j).Extent ()};
@@ -101,11 +100,15 @@ static void Compare(Descriptor &result, const Descriptor &x,
101
100
ub[j] = (x.rank () ? x : y).GetDimension (j).Extent ();
102
101
}
103
102
elements *= ub[j];
104
- xAt[j] = yAt[j] = 1 ;
105
103
}
104
+ x.GetLowerBounds (xAt);
105
+ y.GetLowerBounds (yAt);
106
106
result.Establish (
107
107
TypeCategory::Logical, 1 , nullptr , rank, ub, CFI_attribute_allocatable);
108
- if (result.Allocate (lb, ub) != CFI_SUCCESS) {
108
+ for (int j{0 }; j < rank; ++j) {
109
+ result.GetDimension (j).SetBounds (1 , ub[j]);
110
+ }
111
+ if (result.Allocate () != CFI_SUCCESS) {
109
112
terminator.Crash (" Compare: could not allocate storage for result" );
110
113
}
111
114
std::size_t xChars{x.ElementBytes () >> shift<CHAR>};
@@ -146,18 +149,21 @@ template <typename CHAR, bool ADJUSTR>
146
149
static void AdjustLRHelper (Descriptor &result, const Descriptor &string,
147
150
const Terminator &terminator) {
148
151
int rank{string.rank ()};
149
- SubscriptValue lb[maxRank], ub[maxRank], stringAt[maxRank];
152
+ SubscriptValue ub[maxRank], stringAt[maxRank];
150
153
SubscriptValue elements{1 };
151
154
for (int j{0 }; j < rank; ++j) {
152
- lb[j] = 1 ;
153
155
ub[j] = string.GetDimension (j).Extent ();
154
156
elements *= ub[j];
155
157
stringAt[j] = 1 ;
156
158
}
159
+ string.GetLowerBounds (stringAt);
157
160
std::size_t elementBytes{string.ElementBytes ()};
158
161
result.Establish (string.type (), elementBytes, nullptr , rank, ub,
159
162
CFI_attribute_allocatable);
160
- if (result.Allocate (lb, ub) != CFI_SUCCESS) {
163
+ for (int j{0 }; j < rank; ++j) {
164
+ result.GetDimension (j).SetBounds (1 , ub[j]);
165
+ }
166
+ if (result.Allocate () != CFI_SUCCESS) {
161
167
terminator.Crash (" ADJUSTL/R: could not allocate storage for result" );
162
168
}
163
169
for (SubscriptValue resultAt{0 }; elements-- > 0 ;
@@ -199,17 +205,19 @@ template <typename INT, typename CHAR>
199
205
static void LenTrim (Descriptor &result, const Descriptor &string,
200
206
const Terminator &terminator) {
201
207
int rank{string.rank ()};
202
- SubscriptValue lb[maxRank], ub[maxRank], stringAt[maxRank];
208
+ SubscriptValue ub[maxRank], stringAt[maxRank];
203
209
SubscriptValue elements{1 };
204
210
for (int j{0 }; j < rank; ++j) {
205
- lb[j] = 1 ;
206
211
ub[j] = string.GetDimension (j).Extent ();
207
212
elements *= ub[j];
208
- stringAt[j] = 1 ;
209
213
}
214
+ string.GetLowerBounds (stringAt);
210
215
result.Establish (TypeCategory::Integer, sizeof (INT), nullptr , rank, ub,
211
216
CFI_attribute_allocatable);
212
- if (result.Allocate (lb, ub) != CFI_SUCCESS) {
217
+ for (int j{0 }; j < rank; ++j) {
218
+ result.GetDimension (j).SetBounds (1 , ub[j]);
219
+ }
220
+ if (result.Allocate () != CFI_SUCCESS) {
213
221
terminator.Crash (" LEN_TRIM: could not allocate storage for result" );
214
222
}
215
223
std::size_t stringElementChars{string.ElementBytes () >> shift<CHAR>};
@@ -370,21 +378,27 @@ static void GeneralCharFunc(Descriptor &result, const Descriptor &string,
370
378
: arg.rank () ? arg.rank ()
371
379
: back ? back->rank ()
372
380
: 0 };
373
- SubscriptValue lb[maxRank], ub[maxRank], stringAt[maxRank], argAt[maxRank],
381
+ SubscriptValue ub[maxRank], stringAt[maxRank], argAt[maxRank],
374
382
backAt[maxRank];
375
383
SubscriptValue elements{1 };
376
384
for (int j{0 }; j < rank; ++j) {
377
- lb[j] = 1 ;
378
385
ub[j] = string.rank () ? string.GetDimension (j).Extent ()
379
386
: arg.rank () ? arg.GetDimension (j).Extent ()
380
387
: back ? back->GetDimension (j).Extent ()
381
388
: 1 ;
382
389
elements *= ub[j];
383
- stringAt[j] = argAt[j] = backAt[j] = 1 ;
390
+ }
391
+ string.GetLowerBounds (stringAt);
392
+ arg.GetLowerBounds (argAt);
393
+ if (back) {
394
+ back->GetLowerBounds (backAt);
384
395
}
385
396
result.Establish (TypeCategory::Integer, sizeof (INT), nullptr , rank, ub,
386
397
CFI_attribute_allocatable);
387
- if (result.Allocate (lb, ub) != CFI_SUCCESS) {
398
+ for (int j{0 }; j < rank; ++j) {
399
+ result.GetDimension (j).SetBounds (1 , ub[j]);
400
+ }
401
+ if (result.Allocate () != CFI_SUCCESS) {
388
402
terminator.Crash (" SCAN/VERIFY: could not allocate storage for result" );
389
403
}
390
404
std::size_t stringElementChars{string.ElementBytes () >> shift<CHAR>};
@@ -471,7 +485,7 @@ static void MaxMinHelper(Descriptor &accumulator, const Descriptor &x,
471
485
RUNTIME_CHECK (terminator,
472
486
accumulator.rank () == 0 || x.rank () == 0 ||
473
487
accumulator.rank () == x.rank ());
474
- SubscriptValue lb[maxRank], ub[maxRank], xAt[maxRank];
488
+ SubscriptValue ub[maxRank], xAt[maxRank];
475
489
SubscriptValue elements{1 };
476
490
std::size_t accumChars{accumulator.ElementBytes () >> shift<CHAR>};
477
491
std::size_t xChars{x.ElementBytes () >> shift<CHAR>};
@@ -480,10 +494,8 @@ static void MaxMinHelper(Descriptor &accumulator, const Descriptor &x,
480
494
accumChars != chars || (accumulator.rank () == 0 && x.rank () > 0 )};
481
495
int rank{std::max (accumulator.rank (), x.rank ())};
482
496
for (int j{0 }; j < rank; ++j) {
483
- lb[j] = 1 ;
484
497
if (x.rank () > 0 ) {
485
498
ub[j] = x.GetDimension (j).Extent ();
486
- xAt[j] = x.GetDimension (j).LowerBound ();
487
499
if (accumulator.rank () > 0 ) {
488
500
SubscriptValue accumExt{accumulator.GetDimension (j).Extent ()};
489
501
if (accumExt != ub[j]) {
@@ -495,17 +507,20 @@ static void MaxMinHelper(Descriptor &accumulator, const Descriptor &x,
495
507
}
496
508
} else {
497
509
ub[j] = accumulator.GetDimension (j).Extent ();
498
- xAt[j] = 1 ;
499
510
}
500
511
elements *= ub[j];
501
512
}
513
+ x.GetLowerBounds (xAt);
502
514
void *old{nullptr };
503
515
const CHAR *accumData{accumulator.OffsetElement <CHAR>()};
504
516
if (reallocate) {
505
517
old = accumulator.raw ().base_addr ;
506
518
accumulator.set_base_addr (nullptr );
507
519
accumulator.raw ().elem_len = chars << shift<CHAR>;
508
- RUNTIME_CHECK (terminator, accumulator.Allocate (lb, ub) == CFI_SUCCESS);
520
+ for (int j{0 }; j < rank; ++j) {
521
+ accumulator.GetDimension (j).SetBounds (1 , ub[j]);
522
+ }
523
+ RUNTIME_CHECK (terminator, accumulator.Allocate () == CFI_SUCCESS);
509
524
}
510
525
for (CHAR *result{accumulator.OffsetElement <CHAR>()}; elements-- > 0 ;
511
526
accumData += accumChars, result += chars, x.IncrementSubscripts (xAt)) {
@@ -553,10 +568,9 @@ void RTNAME(CharacterConcatenate)(Descriptor &accumulator,
553
568
accumulator.rank () == 0 || from.rank () == 0 ||
554
569
accumulator.rank () == from.rank ());
555
570
int rank{std::max (accumulator.rank (), from.rank ())};
556
- SubscriptValue lb[maxRank], ub[maxRank], fromAt[maxRank];
571
+ SubscriptValue ub[maxRank], fromAt[maxRank];
557
572
SubscriptValue elements{1 };
558
573
for (int j{0 }; j < rank; ++j) {
559
- lb[j] = 1 ;
560
574
if (accumulator.rank () > 0 && from.rank () > 0 ) {
561
575
ub[j] = accumulator.GetDimension (j).Extent ();
562
576
SubscriptValue fromUB{from.GetDimension (j).Extent ()};
@@ -571,20 +585,23 @@ void RTNAME(CharacterConcatenate)(Descriptor &accumulator,
571
585
(accumulator.rank () ? accumulator : from).GetDimension (j).Extent ();
572
586
}
573
587
elements *= ub[j];
574
- fromAt[j] = 1 ;
575
588
}
576
589
std::size_t oldBytes{accumulator.ElementBytes ()};
577
590
void *old{accumulator.raw ().base_addr };
578
591
accumulator.set_base_addr (nullptr );
579
592
std::size_t fromBytes{from.ElementBytes ()};
580
593
accumulator.raw ().elem_len += fromBytes;
581
594
std::size_t newBytes{accumulator.ElementBytes ()};
582
- if (accumulator.Allocate (lb, ub) != CFI_SUCCESS) {
595
+ for (int j{0 }; j < rank; ++j) {
596
+ accumulator.GetDimension (j).SetBounds (1 , ub[j]);
597
+ }
598
+ if (accumulator.Allocate () != CFI_SUCCESS) {
583
599
terminator.Crash (
584
600
" CharacterConcatenate: could not allocate storage for result" );
585
601
}
586
602
const char *p{static_cast <const char *>(old)};
587
603
char *to{static_cast <char *>(accumulator.raw ().base_addr )};
604
+ from.GetLowerBounds (fromAt);
588
605
for (; elements-- > 0 ;
589
606
to += newBytes, p += oldBytes, from.IncrementSubscripts (fromAt)) {
590
607
std::memcpy (to, p, oldBytes);
@@ -601,8 +618,7 @@ void RTNAME(CharacterConcatenateScalar1)(
601
618
accumulator.set_base_addr (nullptr );
602
619
std::size_t oldLen{accumulator.ElementBytes ()};
603
620
accumulator.raw ().elem_len += chars;
604
- RUNTIME_CHECK (
605
- terminator, accumulator.Allocate (nullptr , nullptr ) == CFI_SUCCESS);
621
+ RUNTIME_CHECK (terminator, accumulator.Allocate () == CFI_SUCCESS);
606
622
std::memcpy (accumulator.OffsetElement <char >(oldLen), from, chars);
607
623
FreeMemory (old);
608
624
}
@@ -650,9 +666,10 @@ void RTNAME(CharacterAssign)(Descriptor &lhs, const Descriptor &rhs,
650
666
for (int j{0 }; j < rank; ++j) {
651
667
lhsAt[j] = rhsAt[j];
652
668
ub[j] = rhs.GetDimension (j).UpperBound ();
669
+ lhs.GetDimension (j).SetBounds (lhsAt[j], ub[j]);
653
670
}
654
671
}
655
- RUNTIME_CHECK (terminator, lhs.Allocate (lhsAt, ub ) == CFI_SUCCESS);
672
+ RUNTIME_CHECK (terminator, lhs.Allocate () == CFI_SUCCESS);
656
673
}
657
674
switch (lhs.raw ().type ) {
658
675
case CFI_type_char:
@@ -941,7 +958,7 @@ void RTNAME(Repeat)(Descriptor &result, const Descriptor &string,
941
958
std::size_t origBytes{string.ElementBytes ()};
942
959
result.Establish (string.type (), origBytes * ncopies, nullptr , 0 , nullptr ,
943
960
CFI_attribute_allocatable);
944
- if (result.Allocate (nullptr , nullptr ) != CFI_SUCCESS) {
961
+ if (result.Allocate () != CFI_SUCCESS) {
945
962
terminator.Crash (" REPEAT could not allocate storage for result" );
946
963
}
947
964
const char *from{string.OffsetElement ()};
@@ -975,7 +992,7 @@ void RTNAME(Trim)(Descriptor &result, const Descriptor &string,
975
992
}
976
993
result.Establish (string.type (), resultBytes, nullptr , 0 , nullptr ,
977
994
CFI_attribute_allocatable);
978
- RUNTIME_CHECK (terminator, result.Allocate (nullptr , nullptr ) == CFI_SUCCESS);
995
+ RUNTIME_CHECK (terminator, result.Allocate () == CFI_SUCCESS);
979
996
std::memcpy (result.OffsetElement (), string.OffsetElement (), resultBytes);
980
997
}
981
998
0 commit comments