@@ -443,9 +443,8 @@ Expr<TR> FoldElementalIntrinsicHelper(FoldingContext &context,
443
443
// Compute the shape of the result based on shapes of arguments
444
444
ConstantSubscripts shape;
445
445
int rank{0 };
446
- const ConstantSubscripts *shapes[sizeof ...(TA)]{
447
- &std::get<I>(*args)->shape ()...};
448
- const int ranks[sizeof ...(TA)]{std::get<I>(*args)->Rank ()...};
446
+ const ConstantSubscripts *shapes[]{&std::get<I>(*args)->shape ()...};
447
+ const int ranks[]{std::get<I>(*args)->Rank ()...};
449
448
for (unsigned int i{0 }; i < sizeof ...(TA); ++i) {
450
449
if (ranks[i] > 0 ) {
451
450
if (rank == 0 ) {
@@ -470,20 +469,19 @@ Expr<TR> FoldElementalIntrinsicHelper(FoldingContext &context,
470
469
std::vector<Scalar<TR>> results;
471
470
if (TotalElementCount (shape) > 0 ) {
472
471
ConstantBounds bounds{shape};
473
- ConstantSubscripts index (rank, 1 );
472
+ ConstantSubscripts resultIndex (rank, 1 );
473
+ ConstantSubscripts argIndex[]{std::get<I>(*args)->lbounds ()...};
474
474
do {
475
475
if constexpr (std::is_same_v<WrapperType<TR, TA...>,
476
476
ScalarFuncWithContext<TR, TA...>>) {
477
- results.emplace_back (func (context,
478
- (ranks[I] ? std::get<I>(*args)->At (index)
479
- : std::get<I>(*args)->GetScalarValue ().value ())...));
477
+ results.emplace_back (
478
+ func (context, std::get<I>(*args)->At (argIndex[I])...));
480
479
} else if constexpr (std::is_same_v<WrapperType<TR, TA...>,
481
480
ScalarFunc<TR, TA...>>) {
482
- results.emplace_back (func (
483
- (ranks[I] ? std::get<I>(*args)->At (index)
484
- : std::get<I>(*args)->GetScalarValue ().value ())...));
481
+ results.emplace_back (func (std::get<I>(*args)->At (argIndex[I])...));
485
482
}
486
- } while (bounds.IncrementSubscripts (index));
483
+ (std::get<I>(*args)->IncrementSubscripts (argIndex[I]), ...);
484
+ } while (bounds.IncrementSubscripts (resultIndex));
487
485
}
488
486
// Build and return constant result
489
487
if constexpr (TR::category == TypeCategory::Character) {
@@ -732,17 +730,11 @@ template <typename T> class ArrayConstructorFolder {
732
730
Expr<T> folded{Fold (context_, common::Clone (expr.value ()))};
733
731
if (const auto *c{UnwrapConstantValue<T>(folded)}) {
734
732
// Copy elements in Fortran array element order
735
- ConstantSubscripts shape{c->shape ()};
736
- int rank{c->Rank ()};
737
- ConstantSubscripts index (GetRank (shape), 1 );
738
- for (std::size_t n{c->size ()}; n-- > 0 ;) {
739
- elements_.emplace_back (c->At (index));
740
- for (int d{0 }; d < rank; ++d) {
741
- if (++index[d] <= shape[d]) {
742
- break ;
743
- }
744
- index[d] = 1 ;
745
- }
733
+ if (c->size () > 0 ) {
734
+ ConstantSubscripts index{c->lbounds ()};
735
+ do {
736
+ elements_.emplace_back (c->At (index));
737
+ } while (c->IncrementSubscripts (index));
746
738
}
747
739
return true ;
748
740
} else {
0 commit comments