https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93091

            Bug ID: 93091
           Summary: Apparent bugs in "sizeof" and "transfer" intrinsic
                    functions
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thfanning at gmail dot com
  Target Milestone: ---

Created attachment 47557
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47557&action=edit
Code to demonstrate incorrect results.

When actual arguments are passed to a subroutine that accepts polymorphic dummy
arguments, the "sizeof" and "transfer" intrinsic functions can return strange
results. For example:

character(80) :: msg
print *, sizeof(msg) ! prints "80"
print *, size(transfer(msg,[0_c_int8_t]),kind=c_size_t) ! prints "80"
call poly(msg) ! prints "1" and "1"

where

subroutine poly(obj)
class(*) :: obj
print *, sizeof(obj)
print *, size(transfer(obj,[0_c_int8_t]),kind=c_size_t)
end

Also,

integer :: iary(10)
print *, sizeof(iary) ! prints "40"
print *, size(transfer(iary,[0_c_int8_t]),kind=c_size_t) ! prints "40"
call poly1(iary) ! prints "40" and "80"

where

subroutine poly1(obj)
class(*) :: obj(:)
print *, sizeof(obj)
print *, size(transfer(obj,[0_c_int8_t]),kind=c_size_t)
end

See attached file for complete code that demonstrates these problems.

The documentation for "sizeof" states that "The argument shall be of any type,
rank or shape" and further, that "If the argument is polymorphic, the size
according to the dynamic type is returned." Similar statements apply to the
"transfer" intrinsic.

The size for assumed-shape dummy arguments should be known, but inconsistent
results occur as described above. Admittedly, the size for assumed-size dummy
arguments may not be known.

Reply via email to