public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pault at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/98534] New: Intrinsic functions failing with unlimited polymorphic actual arguments
Date: Tue, 05 Jan 2021 15:11:22 +0000	[thread overview]
Message-ID: <bug-98534-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 98534
           Summary: Intrinsic functions failing with unlimited polymorphic
                    actual arguments
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: pault at gcc dot gnu.org
          Reporter: pault at gcc dot gnu.org
  Target Milestone: ---

Created attachment 49891
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49891&action=edit
Provisional patch

Unlimited polymorphic actual arguments to 'storage_size' and 'transfer' fail,
when the dynamic type is character. This comes about because the '_len' field
is not used. The attached is a partial, provisional patch. I have not checked
other intrinsics yet.

It should also be noted that 'same_type_as' still uses the '_hash' field of the
vptr, rather than its address. This is known to fail in some cases.

A testcase can be found below.

Paul

! No errors with 
  character(*), parameter :: string = "abcdefgh"
  class(*), allocatable :: star
  character(len=:), allocatable :: chr
  integer :: sz, sum1, sum2

! Part 1: works correctly
  star = 1.0
  sz = storage_size (star)/8
  allocate (character(len=sz) :: chr)
  chr = transfer (star, chr)
  sum1 = sum ([(ichar(chr(i:i)), i = 1, sz)])
  chr = transfer(1.0, chr)
  sum2 = sum ([(ichar(chr(i:i)), i = 1, sz)])

  if (sz /= kind (1.0)) stop 1
  if (sum1 /= sum2) stop 2

  deallocate (star) ! The automatic reallocation causes invalid writes
                    ! and memory leaks. Even with this deallocation
                    ! The invalid writes still occur.
  deallocate (chr)

! Part 2: gets everything from because '_len' field of 'star' not used
  star = string
  sz = storage_size (star)/8
  if (sz /= len (string)) print *, "stop 3" ! storage_size fails

  sz = len (string) ! Ignore previous error in storage_size
  allocate (character(len=sz) :: chr)
  chr = transfer (star, chr)
  sum1 = sum ([(ichar(chr(i:i)), i = 1, sz)])
  chr = transfer(string, chr)
  sum2 = sum ([(ichar(chr(i:i)), i = 1, sz)])
  if (sum1 /= sum2) print *, "stop 4"       ! transfer fails

  deallocate (star, chr)
end

             reply	other threads:[~2021-01-05 15:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-05 15:11 pault at gcc dot gnu.org [this message]
2021-01-17 10:06 ` [Bug fortran/98534] " shmal_i at mail dot ru
2021-01-17 14:17 ` dominiq at lps dot ens.fr
2021-01-17 19:25 ` shmal_i at mail dot ru
2021-04-17 10:21 ` pault at gcc dot gnu.org
2021-04-18 13:26 ` pault at gcc dot gnu.org
2024-05-12  6:00 ` cvs-commit at gcc dot gnu.org
2024-05-12  6:07 ` pault at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98534-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).