Skip to content

Commit 29a6f42

Browse files
committed
address PR comments
1 parent 84c95d6 commit 29a6f42

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ static ModRefResult getCallModRef(fir::CallOp call, mlir::Value var) {
371371
// Fortran semantics apply (e.g., a bare alloca/allocmem result may very well
372372
// be placed in an allocatable/pointer descriptor and escape).
373373

374-
// All the logic bellows are based on Fortran semantics and only holds if this
375-
// is a call to a procedure form the Fortran source and this is a variable
374+
// All the logic below is based on Fortran semantics and only holds if this
375+
// is a call to a procedure from the Fortran source and this is a variable
376376
// from the Fortran source. Compiler generated temporaries or functions may
377377
// not adhere to this semantic.
378378
// TODO: add some opt-in or op-out mechanism for compiler generated temps.

flang/test/Analysis/AliasAnalysis/gen_mod_ref_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
Add attributes hook in an HLFIR code to test fir.call ModRef effects
55
with the test-fir-alias-analysis-modref pass.
6-
6+
77
This will insert mod ref test hook:
88
- to any fir.call to a function which name starts with "test_effect_"
99
- to any hlfir.declare for variable which name starts with "test_var_"
@@ -13,6 +13,14 @@
1313
import re
1414

1515
for line in sys.stdin:
16-
line = re.sub(r'(fir.call @_\w*P)(test_effect_\w*)(\(.*) : ', r'\1\2\3 {test.ptr ="\2"} : ', line)
17-
line = re.sub(r'(hlfir.declare .*uniq_name =.*E)(test_var_\w*)"', r'\1\2", test.ptr ="\2"', line)
18-
sys.stdout.write(line)
16+
line = re.sub(
17+
r"(fir.call @_\w*P)(test_effect_\w*)(\(.*) : ",
18+
r'\1\2\3 {test.ptr ="\2"} : ',
19+
line,
20+
)
21+
line = re.sub(
22+
r'(hlfir.declare .*uniq_name =.*E)(test_var_\w*)"',
23+
r'\1\2", test.ptr ="\2"',
24+
line,
25+
)
26+
sys.stdout.write(line)

flang/test/Analysis/AliasAnalysis/modref-call-globals.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ subroutine test_saved_target
4545
! CHECK-LABEL: Testing : "_QPtest_saved_target"
4646
! CHECK: test_effect_external -> test_var_target_xsaved#0: ModRef
4747

48+
subroutine test_saved_target_2
49+
use somemod, only : may_capture
50+
implicit none
51+
real, save, target :: test_var_target_xsaved
52+
! Pointer associations made to SAVE variables remain valid after the
53+
! procedure exit, so it cannot be ruled out that the variable has been
54+
! captured in a previous call to `test_var_target_xsaved` even though the
55+
! call to `test_effect_external` appears first here.
56+
call test_effect_external()
57+
call may_capture(test_var_target_xsaved)
58+
end subroutine
59+
! CHECK-LABEL: Testing : "_QPtest_saved_target_2"
60+
! CHECK: test_effect_external -> test_var_target_xsaved#0: ModRef
61+
4862
subroutine test_saved_used_in_internal
4963
implicit none
5064
real, save :: test_var_saved_captured

flang/test/Analysis/AliasAnalysis/modref-call-internal-proc.f90

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ subroutine test_effect_internal()
3333

3434
subroutine test_associate()
3535
implicit none
36-
real :: test_var_x(10)
36+
real :: test_var_x(10), test_var_a(10)
3737
associate (test_var_y=>test_var_x)
38-
test_var_y = test_effect_internal()
38+
test_var_a = test_effect_internal()
3939
end associate
4040
contains
4141
function test_effect_internal() result(res)
@@ -44,6 +44,7 @@ function test_effect_internal() result(res)
4444
end function
4545
end subroutine
4646
! CHECK-LABEL: Testing : "_QPtest_associate"
47+
! CHECK: test_effect_internal -> test_var_a#0: NoModRef
4748
! CHECK: test_effect_internal -> test_var_x#0: ModRef
4849
! CHECK: test_effect_internal -> test_var_y#0: ModRef
4950

@@ -55,7 +56,8 @@ subroutine effect_inside_internal()
5556
call internal_sub()
5657
contains
5758
subroutine internal_sub
58-
test_var_x = test_effect_internal_func()
59+
real :: test_var_y(10)
60+
test_var_y = test_effect_internal_func()
5961
end subroutine
6062
function test_effect_internal_func() result(res)
6163
real :: res(10)
@@ -64,6 +66,7 @@ function test_effect_internal_func() result(res)
6466
end subroutine
6567
! CHECK-LABEL: Testing : "_QFeffect_inside_internalPinternal_sub"
6668
! CHECK: test_effect_internal_func -> test_var_x#0: ModRef
69+
! CHECK: test_effect_internal_func -> test_var_y#0: NoModRef
6770

6871
! Test that captured variables are considered to be affected when calling
6972
! any procedure

0 commit comments

Comments
 (0)