@@ -634,65 +634,102 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
634
634
635
635
void
636
636
gfc_advance_section (mpz_t *section_index, gfc_array_ref *ar,
637
- mpz_t *offset_ret)
637
+ mpz_t *offset_ret, int *vector_offset )
638
638
{
639
639
int i;
640
640
mpz_t delta;
641
641
mpz_t tmp;
642
642
bool forwards;
643
643
int cmp;
644
- gfc_expr *start, *end, *stride;
644
+ gfc_expr *start, *end, *stride, *elem;
645
+ gfc_constructor_base base;
645
646
646
647
for (i = 0 ; i < ar->dimen ; i++)
647
648
{
648
- if (ar->dimen_type [i] != DIMEN_RANGE)
649
- continue ;
649
+ bool advance = false ;
650
650
651
- if (ar->stride [i])
651
+ switch (ar->dimen_type [i])
652
652
{
653
- stride = gfc_copy_expr (ar->stride [i]);
654
- if (!gfc_simplify_expr (stride, 1 ))
655
- gfc_internal_error (" Simplification error" );
656
- mpz_add (section_index[i], section_index[i],
657
- stride->value .integer );
658
- if (mpz_cmp_si (stride->value .integer , 0 ) >= 0 )
659
- forwards = true ;
653
+ case DIMEN_ELEMENT:
654
+ /* Loop to advance the next index. */
655
+ advance = true ;
656
+ break ;
657
+
658
+ case DIMEN_RANGE:
659
+ if (ar->stride [i])
660
+ {
661
+ stride = gfc_copy_expr (ar->stride [i]);
662
+ if (!gfc_simplify_expr (stride, 1 ))
663
+ gfc_internal_error (" Simplification error" );
664
+ mpz_add (section_index[i], section_index[i],
665
+ stride->value .integer );
666
+ if (mpz_cmp_si (stride->value .integer , 0 ) >= 0 )
667
+ forwards = true ;
668
+ else
669
+ forwards = false ;
670
+ gfc_free_expr (stride);
671
+ }
660
672
else
661
- forwards = false ;
662
- gfc_free_expr (stride);
663
- }
664
- else
665
- {
666
- mpz_add_ui (section_index[i], section_index[i], 1 );
667
- forwards = true ;
668
- }
673
+ {
674
+ mpz_add_ui (section_index[i], section_index[i], 1 );
675
+ forwards = true ;
676
+ }
669
677
670
- if (ar->end [i])
671
- {
672
- end = gfc_copy_expr (ar->end [i]);
673
- if (!gfc_simplify_expr (end, 1 ))
674
- gfc_internal_error (" Simplification error" );
675
- cmp = mpz_cmp (section_index[i], end->value .integer );
676
- gfc_free_expr (end);
677
- }
678
- else
679
- cmp = mpz_cmp (section_index[i], ar->as ->upper [i]->value .integer );
678
+ if (ar->end [i])
679
+ {
680
+ end = gfc_copy_expr (ar->end [i]);
681
+ if (!gfc_simplify_expr (end, 1 ))
682
+ gfc_internal_error (" Simplification error" );
683
+ cmp = mpz_cmp (section_index[i], end->value .integer );
684
+ gfc_free_expr (end);
685
+ }
686
+ else
687
+ cmp = mpz_cmp (section_index[i], ar->as ->upper [i]->value .integer );
680
688
681
- if ((cmp > 0 && forwards) || (cmp < 0 && !forwards))
682
- {
683
- /* Reset index to start, then loop to advance the next index. */
684
- if (ar->start [i])
689
+ if ((cmp > 0 && forwards) || (cmp < 0 && !forwards))
685
690
{
686
- start = gfc_copy_expr (ar->start [i]);
687
- if (!gfc_simplify_expr (start, 1 ))
688
- gfc_internal_error (" Simplification error" );
691
+ /* Reset index to start, then loop to advance the next index. */
692
+ if (ar->start [i])
693
+ {
694
+ start = gfc_copy_expr (ar->start [i]);
695
+ if (!gfc_simplify_expr (start, 1 ))
696
+ gfc_internal_error (" Simplification error" );
697
+ mpz_set (section_index[i], start->value .integer );
698
+ gfc_free_expr (start);
699
+ }
700
+ else
701
+ mpz_set (section_index[i], ar->as ->lower [i]->value .integer );
702
+ advance = true ;
703
+ }
704
+ break ;
705
+
706
+ case DIMEN_VECTOR:
707
+ vector_offset[i]++;
708
+ base = ar->start [i]->value .constructor ;
709
+ elem = gfc_constructor_lookup_expr (base, vector_offset[i]);
710
+
711
+ if (elem == NULL )
712
+ {
713
+ /* Reset to first vector element and advance the next index. */
714
+ vector_offset[i] = 0 ;
715
+ elem = gfc_constructor_lookup_expr (base, 0 );
716
+ advance = true ;
717
+ }
718
+ if (elem)
719
+ {
720
+ start = gfc_copy_expr (elem);
721
+ if (!gfc_simplify_expr (start, 1 ))
722
+ gfc_internal_error (" Simplification error" );
689
723
mpz_set (section_index[i], start->value .integer );
690
- gfc_free_expr (start);
724
+ gfc_free_expr (start);
691
725
}
692
- else
693
- mpz_set (section_index[i], ar->as ->lower [i]->value .integer );
726
+ break ;
727
+
728
+ default :
729
+ gcc_unreachable ();
694
730
}
695
- else
731
+
732
+ if (!advance)
696
733
break ;
697
734
}
698
735
@@ -793,12 +830,14 @@ gfc_formalize_init_value (gfc_symbol *sym)
793
830
offset. */
794
831
795
832
void
796
- gfc_get_section_index (gfc_array_ref *ar, mpz_t *section_index, mpz_t *offset)
833
+ gfc_get_section_index (gfc_array_ref *ar, mpz_t *section_index, mpz_t *offset,
834
+ int *vector_offset)
797
835
{
798
836
int i;
799
837
mpz_t delta;
800
838
mpz_t tmp;
801
- gfc_expr *start;
839
+ gfc_expr *start, *elem;
840
+ gfc_constructor_base base;
802
841
803
842
mpz_set_si (*offset, 0 );
804
843
mpz_init (tmp);
@@ -810,29 +849,35 @@ gfc_get_section_index (gfc_array_ref *ar, mpz_t *section_index, mpz_t *offset)
810
849
{
811
850
case DIMEN_ELEMENT:
812
851
case DIMEN_RANGE:
813
- if (ar->start [i])
814
- {
815
- start = gfc_copy_expr (ar->start [i]);
816
- if (!gfc_simplify_expr (start, 1 ))
817
- gfc_internal_error (" Simplification error" );
818
- mpz_sub (tmp, start->value .integer ,
819
- ar->as ->lower [i]->value .integer );
820
- mpz_mul (tmp, tmp, delta);
821
- mpz_add (*offset, tmp, *offset);
822
- mpz_set (section_index[i], start->value .integer );
823
- gfc_free_expr (start);
824
- }
825
- else
826
- mpz_set (section_index[i], ar->as ->lower [i]->value .integer );
852
+ elem = ar->start [i];
827
853
break ;
828
854
829
855
case DIMEN_VECTOR:
830
- gfc_internal_error (" TODO: Vector sections in data statements" );
856
+ vector_offset[i] = 0 ;
857
+ base = ar->start [i]->value .constructor ;
858
+ elem = gfc_constructor_lookup_expr (base, vector_offset[i]);
859
+ break ;
831
860
832
861
default :
833
862
gcc_unreachable ();
834
863
}
835
864
865
+ if (elem)
866
+ {
867
+ start = gfc_copy_expr (elem);
868
+ if (!gfc_simplify_expr (start, 1 ))
869
+ gfc_internal_error (" Simplification error" );
870
+ mpz_sub (tmp, start->value .integer ,
871
+ ar->as ->lower [i]->value .integer );
872
+ mpz_mul (tmp, tmp, delta);
873
+ mpz_add (*offset, tmp, *offset);
874
+ mpz_set (section_index[i], start->value .integer );
875
+ gfc_free_expr (start);
876
+ }
877
+ else
878
+ /* Fallback for empty section or constructor. */
879
+ mpz_set (section_index[i], ar->as ->lower [i]->value .integer );
880
+
836
881
mpz_sub (tmp, ar->as ->upper [i]->value .integer ,
837
882
ar->as ->lower [i]->value .integer );
838
883
mpz_add_ui (tmp, tmp, 1 );
0 commit comments