Commit 785abfd3 by Fritz Reese Committed by Steven G. Kargl

dec_union_4.f90: Fix endian issue.

2016-05-14  Fritz Reese  <fritzoreese@gmail.com>

	* gfortran.dg/dec_union_4.f90: Fix endian issue.

2016-05-14  Fritz Reese  <fritzoreese@gmail.com>

	* gfortran.texi: Update example of DEC UNION extension.

From-SVN: r236242
parent e75eb64f
2016-05-14 Fritz Reese <fritzoreese@gmail.com> 2016-05-14 Fritz Reese <fritzoreese@gmail.com>
* gfortran.texi: Update example of DEC UNION extension.
2016-05-14 Fritz Reese <fritzoreese@gmail.com>
PR fortran/71047 PR fortran/71047
* expr.c (gfc_default_initializer): Avoid extra component refs in * expr.c (gfc_default_initializer): Avoid extra component refs in
constructors for derived types and classes. constructors for derived types and classes.
......
...@@ -2281,28 +2281,25 @@ Here is a small example: ...@@ -2281,28 +2281,25 @@ Here is a small example:
structure /myunion/ structure /myunion/
union union
map map
integer(2) w, x, y, z character(2) w0, w1, w2
end map end map
map map
integer(4) wx, yz character(6) long
end map end map
end union end union
end structure end structure
record /myunion/ rec record /myunion/ rec
! After these assignments... ! After this assignment...
rec.wx = z'0DEDBEEF' rec.long = 'hello!'
rec.y = z'0BAD'
rec.z = z'0FAD'
! The following is true: ! The following is true:
! rec.w === z'0DED' ! rec.w0 === 'he'
! rec.x === z'BEEF' ! rec.w1 === 'll'
! rec.yz === z'0BAD0FAD' ! rec.w2 === 'o!'
@end smallexample @end smallexample
The two maps share memory, and the size of the union is ultimately six bytes The two maps share memory, and the size of the union is ultimately six bytes:
(subject to alignment):
@example @example
0 1 2 3 4 5 6 Byte offset 0 1 2 3 4 5 6 Byte offset
...@@ -2313,65 +2310,61 @@ The two maps share memory, and the size of the union is ultimately six bytes ...@@ -2313,65 +2310,61 @@ The two maps share memory, and the size of the union is ultimately six bytes
^ W0 ^ W1 ^ W2 ^ ^ W0 ^ W1 ^ W2 ^
\-------/ \-------/ \-------/ \-------/ \-------/ \-------/
^ LONG ^ unused ^ ^ LONG ^
\-----------------/ \-------/ \---------------------------/
@end example @end example
Following is an example mirroring the layout of an Intel x86_64 register: Following is an example mirroring the layout of an Intel x86_64 register:
@example @example
structure /reg/ structure /reg/
union ! rax union ! U0 ! rax
map map
integer*8 rx ! rax character(16) rx
end map end map
map map
integer*4 rh ! rah character(8) rh ! rah
union ! eax union ! U1
map map
integer*4 rl ! ral character(8) rl ! ral
end map end map
map map
integer*4 ex ! eax character(8) ex ! eax
end map end map
map map
integer*2 eh ! eah character(4) eh ! eah
union ! ax union ! U2
map map
integer*2 el ! eal character(4) el ! eal
end map end map
map map
integer*2 x ! ax character(4) x ! ax
end map end map
map map
integer*1 h ! ah character(2) h ! ah
integer*1 l ! al character(2) l ! al
end map end map
end union ! ax end union
end map end map
end union ! eax end union
end map end map
end union ! rax end union
end structure end structure
record /reg/ a record /reg/ a
! After this assignment... ! After this assignment...
a.rx = z'AABBCCCCFFFFFFFF' a.rx = 'AAAAAAAA.BBB.C.D'
! The following is true: ! The following is true:
! a.rx === 'AAAAAAAA.BBB.C.D'
! a.rx == z'AABBCCCCFFFFFFFF' a.rh === 'AAAAAAAA'
! a.rh == z'FFFFFFFF' a.rl === '.BBB.C.D'
! a.rl == z'AABBCCCC' a.ex === '.BBB.C.D'
! a.eh === '.BBB'
! a.ex == z'AABBCCCC' a.el === '.C.D'
! a.eh == z'CCCC' a.x === '.C.D'
! a.el == z'AABB' a.h === '.C'
! a.l === '.D'
! a.x == z'AABB'
! a.h == z'BB'
! a.l == z'AA'
@end example @end example
......
2016-05-14 Fritz Reese <fritzoreese@gmail.com> 2016-05-14 Fritz Reese <fritzoreese@gmail.com>
* gfortran.dg/dec_union_4.f90: Fix endian issue.
2016-05-14 Fritz Reese <fritzoreese@gmail.com>
PR fortran/71047 PR fortran/71047
* gfortran.dg/pr71047.f08: New test. * gfortran.dg/pr71047.f08: New test.
......
...@@ -14,29 +14,29 @@ end subroutine ...@@ -14,29 +14,29 @@ end subroutine
structure /s4/ structure /s4/
union ! U0 ! rax union ! U0 ! rax
map map
integer(8) rx character(16) rx
end map end map
map map
integer(4) rh ! rah character(8) rh ! rah
union ! U1 union ! U1
map map
integer(4) rl ! ral character(8) rl ! ral
end map end map
map map
integer(4) ex ! eax character(8) ex ! eax
end map end map
map map
integer(2) eh ! eah character(4) eh ! eah
union ! U2 union ! U2
map map
integer(2) el ! eal character(4) el ! eal
end map end map
map map
integer(2) x ! ax character(4) x ! ax
end map end map
map map
integer(1) h ! ah character(2) h ! ah
integer(1) l ! al character(2) l ! al
end map end map
end union end union
end map end map
...@@ -48,15 +48,16 @@ record /s4/ r4 ...@@ -48,15 +48,16 @@ record /s4/ r4
! Nested unions ! Nested unions
r4.rx = z'7A7B7CCC7FFFFFFF' r4.rx = 'AAAAAAAA.BBB.C.D'
if ( r4.rx .ne. z'7A7B7CCC7FFFFFFF' ) call aborts ("rax")
if ( r4.rh .ne. z'7FFFFFFF' ) call aborts ("rah") if ( r4.rx .ne. 'AAAAAAAA.BBB.C.D' ) call aborts ("rax")
if ( r4.rl .ne. z'7A7B7CCC' ) call aborts ("ral") if ( r4.rh .ne. 'AAAAAAAA' ) call aborts ("rah")
if ( r4.ex .ne. z'7A7B7CCC' ) call aborts ("eax") if ( r4.rl .ne. '.BBB.C.D' ) call aborts ("ral")
if ( r4.eh .ne. z'7CCC' ) call aborts ("eah") if ( r4.ex .ne. '.BBB.C.D' ) call aborts ("eax")
if ( r4.el .ne. z'7A7B' ) call aborts ("eal") if ( r4.eh .ne. '.BBB' ) call aborts ("eah")
if ( r4.x .ne. z'7A7B' ) call aborts ("ax") if ( r4.el .ne. '.C.D' ) call aborts ("eal")
if ( r4.h .ne. z'7B' ) call aborts ("ah") if ( r4.x .ne. '.C.D' ) call aborts ("ax")
if ( r4.l .ne. z'7A' ) call aborts ("al") if ( r4.h .ne. '.C' ) call aborts ("ah")
if ( r4.l .ne. '.D' ) call aborts ("al")
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment