2010-11-24 Tobias Burnus <burnus@net-b.de>
PR fortran/46638
* target-memory.c (gfc_interpret_derived): Correctly handle
component offset.
2010-11-24 Tobias Burnus <burnus@net-b.de>
PR fortran/46638
* gfortran.dg/transfer_simplify_10.f90: New.
@@ -477,7 +477,16 @@ gfc_interpret_derived (unsigned char *buffer, size_t buffer_size, gfc_expr *resu
/* The constructor points to the component. */
c->n.component = cmp;
- ptr = TREE_INT_CST_LOW (DECL_FIELD_OFFSET (cmp->backend_decl));
+ /* Calculate the offset, which consists of the the FIELD_OFFSET in
+ bytes, which appears in multiples of DECL_OFFSET_ALIGN-bit-sized,
+ and additional bits of FIELD_BIT_OFFSET. The code assumes that all
+ sizes of the components are multiples of BITS_PER_UNIT,
+ i.e. there are, e.g., no bit fields. */
+
+ ptr = TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (cmp->backend_decl));
+ gcc_assert (ptr % 8 == 0);
+ ptr = ptr/8 + TREE_INT_CST_LOW (DECL_FIELD_OFFSET (cmp->backend_decl));
+
gfc_target_interpret_expr (&buffer[ptr], buffer_size - ptr, e);
}
new file mode 100644
@@ -0,0 +1,28 @@
+! { dg-do run }
+!
+! PR fortran/46638
+!
+! Contributed by James Van Buskirk
+!
+program test5
+ use ISO_C_BINDING
+ implicit none
+ type, bind(C) :: CPUID_type
+ integer(C_INT32_T) eax
+ integer(C_INT32_T) ebx
+ integer(C_INT32_T) edx
+ integer(C_INT32_T) ecx
+ integer(C_INT32_T) bbb
+ end type CPUID_type
+ type(CPUID_TYPE) result
+ result = transfer(achar(10)//achar(0)//achar(0)//achar(0)//'GenuineIntel'//'abcd',result)
+
+ if ( int(z'0000000A') /= result%eax &
+ .or. int(z'756E6547') /= result%ebx &
+ .or. int(z'49656E69') /= result%edx &
+ .or. int(z'6C65746E') /= result%ecx &
+ .or. int(z'64636261') /= result%bbb) then
+ write(*,'(5(z8.8:1x))') result
+ call abort()
+ end if
+end program test5