Skip to content

Commit

Permalink
ArgSizeMismatchRule: can now check for two indirections of arg size n…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
awnawab committed Aug 14, 2023
1 parent a357911 commit 5ed914c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 16 additions & 3 deletions lint_rules/lint_rules/debug_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,22 @@ def check_subroutine(cls, subroutine, rule_report, config, **kwargs):
dummy_size = Product(dummy_arg_size)
stat = cls.compare_sizes(arg_size, alt_arg_size, dummy_size)

# if necessary, update dimension names and check
if not stat:
dummy_size = Product(SubstituteExpressions(assign_map).visit(dummy_arg_size))
# we check for a maximum of two indirections for the dummy and arg dimension names
for _ in range(2):
if stat:
break

# if necessary, update dummy arg dimension names and check
dummy_arg_size = SubstituteExpressions(assign_map).visit(dummy_arg_size)
dummy_size = Product(dummy_arg_size)
stat = cls.compare_sizes(arg_size, alt_arg_size, dummy_size)

if stat:
break

# if necessary, update arg dimension names and check
arg_size = SubstituteExpressions(assign_map).visit(arg_size)
alt_arg_size = SubstituteExpressions(assign_map).visit(alt_arg_size)
stat = cls.compare_sizes(arg_size, alt_arg_size, dummy_size)

if not stat:
Expand Down
12 changes: 8 additions & 4 deletions lint_rules/tests/test_debug_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ def test_arg_size_array_slices(rules, frontend):
real, intent(in) :: var6(:,:), var7(:,:)
real, intent(inout) :: var0(klon, nblk), var1(klon, 138, nblk)
real(kind=jphook) :: zhook_handle
integer :: klev, ibl
integer :: klev, ibl, iproma, iend
if(lhook) call dr_hook('driver', 0, zhook_handle)
associate(nlev => klev)
nlev = 137
do ibl = 1, nblk
call kernel(klon, nlev, var0(:,ibl), var1(:,:,ibl), var2(1:klon, 1:nlev), &
iproma = klon
iend = iproma
call kernel(klon, nlev, var0(:,ibl), var1(:,:,ibl), var2(1:iend, 1:nlev), &
var3, var4(1:klon, 1:nlev+1), var5(:, 1:nlev+1), &
var6_d=var6, var7_d=var7(:,1:nlev))
enddo
Expand Down Expand Up @@ -113,13 +115,15 @@ def test_arg_size_array_sequence(rules, frontend):
real(kind=jphook) :: zhook_handle
real, dimension(klon, 137) :: var4, var5
real :: var6
integer :: klev, ibl
integer :: klev, ibl, iproma, iend
if(lhook) call dr_hook('driver', 0, zhook_handle)
klev = 137
do ibl = 1, nblk
call kernel(klon, klev, var0(1,ibl), var1(1,1,ibl), var2(1, 1), var3(1), &
iproma = klon
iend = iproma
call kernel(klon, klev, var0(1,ibl), var1(1,1,ibl), var2(1:iend, 1), var3(1), &
var4(1, 1), var5, var6, 1, .true.)
enddo
Expand Down

0 comments on commit 5ed914c

Please sign in to comment.