| 1 |
! { dg-do run { target i?86-*-linux* x86_64-*-linux* } } |
| 2 |
! disable DCE so the allocations are not optimized away |
| 3 |
! { dg-additional-options "-fno-malloc-dce" } |
| 4 |
! { dg-additional-sources set_vm_limit.c } |
| 5 |
! |
| 6 |
! This test calls set_vm_limit to set an artificially low address space |
| 7 |
! limit. set_vm_limit calls setrlimit, which has some portability |
| 8 |
! considerations. setrlimit gets errors on arm*linux and aarch64*linux, |
| 9 |
! and when the main program calls malloc(), it in turn fails on Darwin. |
| 10 |
! The code being tested is portable, calling ALLOCATED() or ASSOCIATED() |
| 11 |
! to verify that allocation was successful, so the operating assumption |
| 12 |
! is that as long as this test runs on at least one system, we can call |
| 13 |
! it good. |
| 14 |
|
| 15 |
USE :: ISO_C_BINDING !, only: C_INT |
| 16 |
IMPLICIT NONE |
| 17 |
|
| 18 |
INTERFACE |
| 19 |
SUBROUTINE set_vm_limit(n) bind(C) |
| 20 |
import |
| 21 |
integer(C_INT), value, intent(in) :: n |
| 22 |
END SUBROUTINE set_vm_limit |
| 23 |
END INTERFACE |
| 24 |
|
| 25 |
TYPE foo |
| 26 |
INTEGER, DIMENSION(10000) :: data = 42 |
| 27 |
END TYPE |
| 28 |
TYPE(foo), POINTER :: foo_ptr |
| 29 |
TYPE(foo), ALLOCATABLE :: foo_obj |
| 30 |
TYPE(foo), ALLOCATABLE, DIMENSION(:) :: foo_array |
| 31 |
|
| 32 |
INTEGER istat |
| 33 |
|
| 34 |
CALL set_vm_limit(1000000) |
| 35 |
|
| 36 |
DO |
| 37 |
ALLOCATE(foo_ptr, stat = istat) |
| 38 |
IF (istat .NE. 0) THEN |
| 39 |
PRINT *, "foo_ptr allocation failed" |
| 40 |
EXIT |
| 41 |
ENDIF |
| 42 |
ENDDO |
| 43 |
|
| 44 |
ALLOCATE(foo_obj, stat = istat) |
| 45 |
IF (istat .NE. 0) THEN |
| 46 |
PRINT *, "foo_obj allocation failed" |
| 47 |
ENDIF |
| 48 |
|
| 49 |
ALLOCATE(foo_array(5), stat = istat) |
| 50 |
IF (istat .NE. 0) THEN |
| 51 |
PRINT *, "foo_array allocation failed" |
| 52 |
ENDIF |
| 53 |
|
| 54 |
END |
| 55 |
! { dg-output " *foo_ptr allocation failed(\n|\r\n|\r)" } |
| 56 |
! { dg-output " *foo_obj allocation failed(\n|\r\n|\r)" } |
| 57 |
! { dg-output " *foo_array allocation failed(\n|\r\n|\r)" } |