Skip to content

Commit 265c9c9

Browse files
committed
Fix issue with pointers with strides
In the simply_contiguous() function, for A_SUSCR case check whether the object is a pointer. If so, we only want to return TRUE if the subscripted pointer object has the CONTIGUOUS attribute. Otherwise, we don't know what the pointer is pointing to at compile-time. Add pp73 test.
1 parent 0c8e22d commit 265c9c9

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

test/f90_correct/inc/pp73.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
#
17+
########## Make rule for test pp73 ########
18+
19+
20+
pp73: run
21+
22+
23+
build: $(SRC)/pp73.f90
24+
-$(RM) pp73.$(EXESUFFIX) core *.d *.mod FOR*.DAT FTN* ftn* fort.*
25+
@echo ------------------------------------ building test $@
26+
-$(FC) -c $(FFLAGS) $(LDFLAGS) $(SRC)/pp73.f90 -o pp73.$(OBJX)
27+
-$(FC) $(FFLAGS) $(LDFLAGS) pp73.$(OBJX) $(LIBS) -o pp73.$(EXESUFFIX)
28+
29+
30+
run:
31+
@echo ------------------------------------ executing test pp73
32+
pp73.$(EXESUFFIX)
33+
34+
verify: ;
35+

test/f90_correct/lit/pp73.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Shared lit script for each tests. Run bash commands that run tests with make.
17+
18+
# RUN: KEEP_FILES=%keep FLAGS=%flags TEST_SRC=%s MAKE_FILE_DIR=%S/.. bash %S/runmake | tee %t
19+
# RUN: cat %t | FileCheck %S/runmake

test/f90_correct/src/pp73.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
2+
!
3+
! Licensed under the Apache License, Version 2.0 (the "License");
4+
! you may not use this file except in compliance with the License.
5+
! You may obtain a copy of the License at
6+
!
7+
! http://www.apache.org/licenses/LICENSE-2.0
8+
!
9+
! Unless required by applicable law or agreed to in writing, software
10+
! distributed under the License is distributed on an "AS IS" BASIS,
11+
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
! See the License for the specific language governing permissions and
13+
! limitations under the License.
14+
!
15+
!
16+
! Tests subscripted pointer expressions that point to non-contiguous array
17+
! sections.
18+
19+
program main
20+
integer, pointer :: p1(:), p2(:)
21+
integer, target :: a(20)
22+
integer :: expect(8) = [3, 5, 7, 9, 11, 13, 15, 17]
23+
integer :: j
24+
a = [(j,j=1,20)]
25+
p1 => a(::2)
26+
p2(1:8) => p1(2:9)
27+
if (all(p2 .eq. expect)) then
28+
print *, 'PASS'
29+
else
30+
print *, 'FAIL'
31+
endif
32+
end program main

tools/flang1/flang1exe/ast.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,10 @@ simply_contiguous(int arr_ast)
34293429
}
34303430
break;
34313431
case A_SUBSCR:
3432+
sptr = memsym_of_ast(arr_ast);
3433+
if (POINTERG(sptr)) {
3434+
return CONTIGATTRG(sptr);
3435+
}
34323436
return contiguous_array_section(arr_ast);
34333437
}
34343438

0 commit comments

Comments
 (0)