[llvm-branch-commits] [flang] [flang] handle fir.call in AliasAnalysis::getModRef (PR #117164)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 22 06:21:09 PST 2024


================
@@ -0,0 +1,68 @@
+! RUN: bbc -emit-hlfir %s -o - | %python %S/gen_mod_ref_test.py | \
+! RUN:  fir-opt -pass-pipeline='builtin.module(func.func(test-fir-alias-analysis-modref))' \
+! RUN:  --mlir-disable-threading -o /dev/null 2>&1 | FileCheck %s
+
+! Test fir.call modref for global variables (module, saved, common).
+
+
+module somemod
+  implicit none
+  real :: test_var_xmod
+  interface
+    subroutine may_capture(x)
+      real, target :: x
+    end subroutine
+  end interface
+end module
+
+subroutine test_module
+  use somemod, only : test_var_xmod
+  implicit none
+  call test_effect_external()
+end subroutine
+! CHECK-LABEL: Testing : "_QPtest_module"
+! CHECK: test_effect_external -> test_var_xmod#0: ModRef
+
+subroutine test_saved_local
+  use somemod, only : may_capture
+  implicit none
+  real, save :: test_var_xsaved
+  ! Capture is invalid after the call because test_var_xsaved does not have the
+  ! target attribute.
+  call may_capture(test_var_xsaved)
+  call test_effect_external()
+end subroutine
+! CHECK-LABEL: Testing : "_QPtest_saved_local"
+! CHECK: test_effect_external -> test_var_xsaved#0: NoModRef
+
+subroutine test_saved_target
+  use somemod, only : may_capture
+  implicit none
+  real, save, target :: test_var_target_xsaved
----------------
jeanPerier wrote:

Agreed it should not matter here. There is an equivalent test without SAVE in the added `modref-call-locals.f90` (`test_local_target`), I am testing it because the IR looks pretty different with and without SAVE. Saved variables are lowered to global memory in lowering.

I added a more interesting case where SAVE matters because pointer associations made to targets with the SAVE variable survive the instance of the subprogram, which is not true for variables that are not saved as per F2023 19.5.2.5 point (6):

```
subroutine test_saved_target_2
  use somemod, only : may_capture
  implicit none
  real, save, target :: test_var_target_xsaved
  call test_effect_external()
  call may_capture(test_var_target_xsaved)
end subroutine
```

https://github.com/llvm/llvm-project/pull/117164


More information about the llvm-branch-commits mailing list