[flang-commits] [flang] [flang] Refine handling of NULL() actual to non-optional allocatable … (PR #116126)

via flang-commits flang-commits at lists.llvm.org
Fri Nov 15 01:57:36 PST 2024


https://github.com/jeanPerier commented:

Should lowering now generate conditional deallocation in case the dummy argument associated to NULL is allocated inside the function?

Currently, lowering does not do that (relying on the INTENT(IN) aspect). But with this patch, the following code will now compile (with a warning) and leak memory:

````
module m
contains
subroutine foo(x)
  real, allocatable :: x(:)
  allocate(x(10))
end subroutine
end module
  use m, only : foo
  do i=1,10
  call foo(null())
  end do
end
```` 

valgrind:
````
==2914349== HEAP SUMMARY:
==2914349==     in use at exit: 400 bytes in 10 blocks
==2914349==   total heap usage: 10 allocs, 0 frees, 400 bytes allocated
==2914349== 
==2914349== LEAK SUMMARY:
==2914349==    definitely lost: 400 bytes in 10 blocks
````

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


More information about the flang-commits mailing list