Skip to content

Commit 3a164ae

Browse files
authored
Descriptor extents must be nonnegative (#1025)
1 parent fa3e602 commit 3a164ae

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

flang/lib/Lower/BoxAnalyzer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
393393
lbounds.push_back(*lb); // origin for this dim
394394
if (auto high = subs.ubound().GetExplicit()) {
395395
if (auto ub = Fortran::evaluate::ToInt64(*high)) {
396-
shapes.push_back(*ub - *lb + 1); // extent for this dim
396+
auto extent = *ub - *lb + 1;
397+
shapes.push_back(extent < 0 ? 0 : extent);
397398
continue;
398399
}
399400
} else if (subs.ubound().isAssumed()) {

flang/test/Lower/array-constructor-1.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ module units
55
contains
66
! CHECK-LABEL: _QMunitsPis_preconnected_unit
77
logical function is_preconnected_unit(u)
8-
! CHECK: [[units_ssa:%[0-9]+]] = fir.address_of([[units_value:.*]]) :
9-
! !fir.ref<!fir.array<3xi32>>
8+
! CHECK: [[units_ssa:%[0-9]+]] = fir.address_of([[units_value:.*]]) : !fir.ref<!fir.array<3xi32>>
109
integer :: u
1110
integer :: i
1211
is_preconnected_unit = .true.

flang/test/Lower/zero-size.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! RUN: bbc -o - %s | FileCheck %s
2+
3+
! CHECK-LABEL: _QPzero
4+
subroutine zero(aa)
5+
real, dimension(:) :: aa
6+
print*, size(aa)
7+
end
8+
9+
! CHECK-LABEL: _QQmain
10+
program prog
11+
real nada(2:-1)
12+
interface
13+
subroutine zero(aa)
14+
real, dimension(:) :: aa
15+
end
16+
end interface
17+
! CHECK: %[[shape:[0-9]*]] = fir.shape_shift %c2, %c0 : (index, index) -> !fir.shapeshift<1>
18+
! CHECK: %2 = fir.embox %0(%[[shape]]) : (!fir.ref<!fir.array<0xf32>>, !fir.shapeshift<1>) -> !fir.box<!fir.array<0xf32>>
19+
call zero(nada)
20+
end

0 commit comments

Comments
 (0)