public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/46641] New: Specification-expr checks and results with C_SIZEOF and SIZEOF
@ 2010-11-24 14:45 burnus at gcc dot gnu.org
  2010-11-24 15:13 ` [Bug fortran/46641] " burnus at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: burnus at gcc dot gnu.org @ 2010-11-24 14:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46641

           Summary: Specification-expr checks and results with C_SIZEOF
                    and SIZEOF
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Kind of follow up to PR 46638; based on
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1b907e3b7b6f3461


There is something fishy about the following program. In terms of validity, the
question is whether
   C_SIZEOF (structure-constructor ())
is a valid initialization expression -- gfortran accepts it.

Besides the validity issue, there is something fishy. The "string" has a length
of 16 -- using either C_SIZEOF or the literal 16 in the declaration. However,
if one uses the literal, it works while using C_SIZEOF the TRANSFER seems to
override some memory it shouldn't - causing a segfault.

Using "sizeof()" instead of "c_sizeof()", the either version is rejected by the
Cray compiler - but both version work with ifort. Neither compiler likes the
C_sizeof version (not implemented in Cray, not sure about ifort).

gfortran prints for sizeof the error "must have constant character length" for
both versions.


module utils
   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
   end type CPUID_type
   type(CPUID_type) :: test_type
end module utils

program mxcsr_test
   use ISO_C_BINDING
   use utils
   implicit none
   integer(C_INT32_T) reg
   integer(C_INT64_T) ts1, ts2
   integer(C_INT16_T) sw, cw
   integer(C_INT32_T) eax, ecx
   type(CPUID_type) result
!  Works:
!    character(16) string
!  Compiles but fails:
     character(SIZEOF(CPUID_type(0,0,0,0))) string
!  Rejected with: must have constant character length
!    character(SIZEOF(test_type)) string

   result = CPUID_TYPE(int(Z'0000000A'),int(Z'756E6547'), &
      int(Z'49656E69'),int(Z'6C65746E'))
   print *, len(string) ! OK: 16
   string = transfer(result,string)
   write(*,'(a,a)') 'Brand name: ',string(5:16)
  write(*,'(4(z8.8:1x))') result
end program mxcsr_test


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-12-14 20:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-24 14:45 [Bug fortran/46641] New: Specification-expr checks and results with C_SIZEOF and SIZEOF burnus at gcc dot gnu.org
2010-11-24 15:13 ` [Bug fortran/46641] " burnus at gcc dot gnu.org
2010-11-24 18:23 ` kargl at gcc dot gnu.org
2010-11-27 22:20 ` burnus at gcc dot gnu.org
2013-06-20 22:04 ` dominiq at lps dot ens.fr
2013-06-20 22:07 ` dominiq at lps dot ens.fr
2013-12-14 20:13 ` dominiq at lps dot ens.fr
2013-12-14 20:25 ` dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).