! { dg-do run }
|
! { dg-do run }
|
! { dg-options "-std=gnu" }
|
! { dg-options "-std=gnu" }
|
! Tests the fix for PR29786, in which initialization of overlapping
|
! Tests the fix for PR29786, in which initialization of overlapping
|
! equivalence elements caused a compile error.
|
! equivalence elements caused a compile error.
|
!
|
!
|
! Contributed by Bernhard Fischer
|
! Contributed by Bernhard Fischer
|
!
|
!
|
block data
|
block data
|
common /global/ ca (4)
|
common /global/ ca (4)
|
integer(4) ca, cb
|
integer(4) ca, cb
|
equivalence (cb, ca(3))
|
equivalence (cb, ca(3))
|
data (ca(i), i = 1, 2) /42,43/, ca(4) /44/
|
data (ca(i), i = 1, 2) /42,43/, ca(4) /44/
|
data cb /99/
|
data cb /99/
|
end block data
|
end block data
|
|
|
integer(4), parameter :: abcd = ichar ("a") + 256_4 * (ichar("b") + 256_4 * &
|
integer(4), parameter :: abcd = ichar ("a") + 256_4 * (ichar("b") + 256_4 * &
|
(ichar ("c") + 256_4 * ichar ("d")))
|
(ichar ("c") + 256_4 * ichar ("d")))
|
logical(4), parameter :: bigendian = transfer (abcd, "wxyz") .eq. "abcd"
|
logical(4), parameter :: bigendian = transfer (abcd, "wxyz") .eq. "abcd"
|
|
|
call int4_int4
|
call int4_int4
|
call real4_real4
|
call real4_real4
|
call complex_real
|
call complex_real
|
call check_block_data
|
call check_block_data
|
call derived_types ! Thanks to Tobias Burnus for this:)
|
call derived_types ! Thanks to Tobias Burnus for this:)
|
!
|
!
|
! This came up in PR29786 comment #9 - Note the need to treat endianess
|
! This came up in PR29786 comment #9 - Note the need to treat endianess
|
! Thanks Dominique d'Humieres:)
|
! Thanks Dominique d'Humieres:)
|
!
|
!
|
if (bigendian) then
|
if (bigendian) then
|
if (d1mach_little (1) .ne. transfer ((/0_4, 1048576_4/), 1d0)) call abort ()
|
if (d1mach_little (1) .ne. transfer ((/0_4, 1048576_4/), 1d0)) call abort ()
|
if (d1mach_little (2) .ne. transfer ((/-1_4,2146435071_4/), 1d0)) call abort ()
|
if (d1mach_little (2) .ne. transfer ((/-1_4,2146435071_4/), 1d0)) call abort ()
|
else
|
else
|
if (d1mach_big (1) .ne. transfer ((/1048576_4, 0_4/), 1d0)) call abort ()
|
if (d1mach_big (1) .ne. transfer ((/1048576_4, 0_4/), 1d0)) call abort ()
|
if (d1mach_big (2) .ne. transfer ((/2146435071_4,-1_4/), 1d0)) call abort ()
|
if (d1mach_big (2) .ne. transfer ((/2146435071_4,-1_4/), 1d0)) call abort ()
|
end if
|
end if
|
!
|
!
|
contains
|
contains
|
subroutine int4_int4
|
subroutine int4_int4
|
integer(4) a(4)
|
integer(4) a(4)
|
integer(4) b
|
integer(4) b
|
equivalence (b,a(3))
|
equivalence (b,a(3))
|
data b/3/
|
data b/3/
|
data (a(i), i=1,2) /1,2/, a(4) /4/
|
data (a(i), i=1,2) /1,2/, a(4) /4/
|
if (any (a .ne. (/1, 2, 3, 4/))) call abort ()
|
if (any (a .ne. (/1, 2, 3, 4/))) call abort ()
|
end subroutine int4_int4
|
end subroutine int4_int4
|
subroutine real4_real4
|
subroutine real4_real4
|
real(4) a(4)
|
real(4) a(4)
|
real(4) b
|
real(4) b
|
equivalence (b,a(3))
|
equivalence (b,a(3))
|
data b/3.0_4/
|
data b/3.0_4/
|
data (a(i), i=1,2) /1.0_4, 2.0_4/, &
|
data (a(i), i=1,2) /1.0_4, 2.0_4/, &
|
a(4) /4.0_4/
|
a(4) /4.0_4/
|
if (sum (abs (a - &
|
if (sum (abs (a - &
|
(/1.0_4, 2.0_4, 3.0_4, 4.0_4/))) > 1.0e-6) call abort ()
|
(/1.0_4, 2.0_4, 3.0_4, 4.0_4/))) > 1.0e-6) call abort ()
|
end subroutine real4_real4
|
end subroutine real4_real4
|
subroutine complex_real
|
subroutine complex_real
|
complex(4) a(4)
|
complex(4) a(4)
|
real(4) b(2)
|
real(4) b(2)
|
equivalence (b,a(3))
|
equivalence (b,a(3))
|
data b(1)/3.0_4/, b(2)/4.0_4/
|
data b(1)/3.0_4/, b(2)/4.0_4/
|
data (a(i), i=1,2) /(0.0_4, 1.0_4),(2.0_4,0.0_4)/, &
|
data (a(i), i=1,2) /(0.0_4, 1.0_4),(2.0_4,0.0_4)/, &
|
a(4) /(0.0_4,5.0_4)/
|
a(4) /(0.0_4,5.0_4)/
|
if (sum (abs (a - (/(0.0_4, 1.0_4),(2.0_4, 0.0_4), &
|
if (sum (abs (a - (/(0.0_4, 1.0_4),(2.0_4, 0.0_4), &
|
(3.0_4, 4.0_4),(0.0_4, 5.0_4)/))) > 1.0e-6) call abort ()
|
(3.0_4, 4.0_4),(0.0_4, 5.0_4)/))) > 1.0e-6) call abort ()
|
end subroutine complex_real
|
end subroutine complex_real
|
subroutine check_block_data
|
subroutine check_block_data
|
common /global/ ca (4)
|
common /global/ ca (4)
|
equivalence (ca(3), cb)
|
equivalence (ca(3), cb)
|
integer(4) ca
|
integer(4) ca
|
if (any (ca .ne. (/42, 43, 99, 44/))) call abort ()
|
if (any (ca .ne. (/42, 43, 99, 44/))) call abort ()
|
end subroutine check_block_data
|
end subroutine check_block_data
|
function d1mach_little(i) result(d1mach)
|
function d1mach_little(i) result(d1mach)
|
implicit none
|
implicit none
|
double precision d1mach,dmach(5)
|
double precision d1mach,dmach(5)
|
integer i
|
integer i
|
integer*4 large(4),small(4)
|
integer*4 large(4),small(4)
|
equivalence ( dmach(1), small(1) )
|
equivalence ( dmach(1), small(1) )
|
equivalence ( dmach(2), large(1) )
|
equivalence ( dmach(2), large(1) )
|
data small(1),small(2) / 0, 1048576/
|
data small(1),small(2) / 0, 1048576/
|
data large(1),large(2) /-1,2146435071/
|
data large(1),large(2) /-1,2146435071/
|
d1mach = dmach(i)
|
d1mach = dmach(i)
|
end function d1mach_little
|
end function d1mach_little
|
function d1mach_big(i) result(d1mach)
|
function d1mach_big(i) result(d1mach)
|
implicit none
|
implicit none
|
double precision d1mach,dmach(5)
|
double precision d1mach,dmach(5)
|
integer i
|
integer i
|
integer*4 large(4),small(4)
|
integer*4 large(4),small(4)
|
equivalence ( dmach(1), small(1) )
|
equivalence ( dmach(1), small(1) )
|
equivalence ( dmach(2), large(1) )
|
equivalence ( dmach(2), large(1) )
|
data small(1),small(2) /1048576, 0/
|
data small(1),small(2) /1048576, 0/
|
data large(1),large(2) /2146435071,-1/
|
data large(1),large(2) /2146435071,-1/
|
d1mach = dmach(i)
|
d1mach = dmach(i)
|
end function d1mach_big
|
end function d1mach_big
|
subroutine derived_types
|
subroutine derived_types
|
TYPE T1
|
TYPE T1
|
sequence
|
sequence
|
character (3) :: chr
|
character (3) :: chr
|
integer :: i = 1
|
integer :: i = 1
|
integer :: j
|
integer :: j
|
END TYPE T1
|
END TYPE T1
|
TYPE T2
|
TYPE T2
|
sequence
|
sequence
|
character (3) :: chr = "wxy"
|
character (3) :: chr = "wxy"
|
integer :: i = 1
|
integer :: i = 1
|
integer :: j = 4
|
integer :: j = 4
|
END TYPE T2
|
END TYPE T2
|
TYPE(T1) :: a1
|
TYPE(T1) :: a1
|
TYPE(T2) :: a2
|
TYPE(T2) :: a2
|
EQUIVALENCE(a1,a2) ! { dg-warning="mixed|components" }
|
EQUIVALENCE(a1,a2) ! { dg-warning="mixed|components" }
|
if (a1%chr .ne. "wxy") call abort ()
|
if (a1%chr .ne. "wxy") call abort ()
|
if (a1%i .ne. 1) call abort ()
|
if (a1%i .ne. 1) call abort ()
|
if (a1%j .ne. 4) call abort ()
|
if (a1%j .ne. 4) call abort ()
|
end subroutine derived_types
|
end subroutine derived_types
|
end
|
end
|
|
|