public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/101871] Array of strings of different length passed as an argument produces invalid result.
Date: Sat, 14 Aug 2021 00:59:46 +0000	[thread overview]
Message-ID: <bug-101871-4-l5ImkTu9Jb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101871-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from kargl at gcc dot gnu.org ---
With this testcase,

program tao_program

   implicit none

   integer i
   character(80) abc(9)
   character(1) n

   n = 'H'
   abc = [character(80) :: &
   &  'a'//n, 'ab', 'abc', 'd', 'def', 'g', 'ghi', 'z', 'zyxwvut']

   call io([character(80) :: &
   &  'a'//n, 'ab', 'abc', 'd', 'def', 'g', 'ghi', 'z', 'zyxwvut'])

   contains

      subroutine io (lines)
         character(*) lines(:)
         integer i
         do i = 1, size(lines)
            write(*,'(I0,A)') i, ' ' // trim(abc(i)) // ' ' // trim(lines(i))
         end do
      end subroutine io

end program

I find that the actual argument is correctly parsed.

(gdb) p *tail->expr
$12 = {expr_type = EXPR_ARRAY, ts = {type = BT_CHARACTER, kind = 1, u = {
      derived = 0x803422870, cl = 0x803422870, pad = 54667376}, interface =
0x0, 
    is_c_interop = 0, is_iso_c = 0, f90_type = BT_UNKNOWN, deferred = false, 
    interop_kind = 0x7fffffffd950}, rank = 1, shape = 0x0, symtree = 0x0, ref =
0x0, where = {
    nextc = 0x803431c2c, lb = 0x803431be0}, base_expr = 0x0, is_snan = 0, error
= 0, 
  user_operator = 0, mold = 0, must_finalize = 0, no_bounds_check = 0,
external_blas = 0, 
  do_not_resolve_again = 0, do_not_warn = 0, from_constructor = 0,
representation = {
    length = 0, string = 0x0}, boz = {len = 0, rdx = 0, str = 0x0}, value = {
    logical = 54623680, iokind = 54623680, integer = {{_mp_alloc = 54623680,
_mp_size = 8, 
        _mp_d = 0x0}}, real = {{_mpfr_prec = 34414362048, _mpfr_sign = 0,
_mpfr_exp = 0, 
        _mpfr_d = 0x0}}, complex = {{re = {{_mpfr_prec = 34414362048,
_mpfr_sign = 0, 
            _mpfr_exp = 0, _mpfr_d = 0x0}}, im = {{_mpfr_prec = 0, _mpfr_sign =
0, 
            _mpfr_exp = 0, _mpfr_d = 0x0}}}}, op = {op = 54623680, uop = 0x0,
op1 = 0x0, 
      op2 = 0x0}, function = {actual = 0x803417dc0, name = 0x0, isym = 0x0,
esym = 0x0}, 
    compcall = {actual = 0x803417dc0, name = 0x0, base_object = 0x0, tbp = 0x0, 
      ignore_pass = 0, assign = 0}, character = {length = 34414362048, string =
0x0}, 
    constructor = 0x803417dc0}, param_list = 0x0}
(gdb) call debug(tail->expr)
(/ (// 'a' tao_program:n) , 'ab' , 'abc' , 'd' , 'def' , 'g' , 'ghi' , 'z' ,
'zyxwvut' /) (CHARACTER 80 1)
(gdb) call debug(tail->expr->ts)
(CHARACTER 80 1)

Both the elements and the typespec are set correctly.  So, when the
actual argument is evaluate the first element is (// 'a' tao_program:n)
which will have length of 2.  This is then used for all other elements.
Whoops.

  parent reply	other threads:[~2021-08-14  0:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12  3:28 [Bug fortran/101871] New: " david.sagan at gmail dot com
2021-08-12 16:05 ` [Bug fortran/101871] " kargl at gcc dot gnu.org
2021-08-12 18:43 ` anlauf at gcc dot gnu.org
2021-08-12 19:21 ` kargl at gcc dot gnu.org
2021-08-14  0:59 ` kargl at gcc dot gnu.org [this message]
2021-08-15 19:21 ` anlauf at gcc dot gnu.org
2021-08-16  0:30 ` sgk at troutmask dot apl.washington.edu

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-101871-4-l5ImkTu9Jb@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).