public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types
@ 2015-09-28  6:59 baradi09 at gmail dot com
  2015-10-10 10:05 ` [Bug fortran/67740] " dominiq at lps dot ens.fr
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: baradi09 at gmail dot com @ 2015-09-28  6:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67740
           Summary: Wrong association status of allocatable character
                    pointer in derived types
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: baradi09 at gmail dot com
  Target Milestone: ---

Created attachment 36405
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36405&action=edit
Self containing example demonstrating the issue.

Dear all,

I've found the following problem with gfortran 5.2.0: Let's take a derived type
(Base) with a pointer component (string) of the type deferred length character,
one instance of this derived type and two pointers (p1 and p2) pointing to this
one instance. While 'associated(p1, p2)' correctly detects the equivalence of
the two pointers, 'associated(p1%string, p2%string)' wrongly indicates an
inequivalence of the pointer components.

Best,

Bálint
>From gcc-bugs-return-498166-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Sep 28 07:11:16 2015
Return-Path: <gcc-bugs-return-498166-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 115229 invoked by alias); 28 Sep 2015 07:11:16 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 115202 invoked by uid 48); 28 Sep 2015 07:11:12 -0000
From: "trippels at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67739] name clash between builtin functions and local variables when optimization is on
Date: Mon, 28 Sep 2015 07:11:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.3
X-Bugzilla-Keywords:
X-Bugzilla-Severity: major
X-Bugzilla-Who: trippels at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-67739-4-zRgLhiVoFW@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-67739-4@http.gcc.gnu.org/bugzilla/>
References: <bug-67739-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-09/txt/msg02144.txt.bz2
Content-length: 516

https://gcc.gnu.org/bugzilla/show_bug.cgi?idg739

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |trippels at gcc dot gnu.org

--- Comment #1 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
Well just don't name the array sincosf. Or use -fno-builtin-sin.
I can only reproduce the issue with 4.9.3 and -Ofast.


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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
@ 2015-10-10 10:05 ` dominiq at lps dot ens.fr
  2021-05-03 12:51 ` bardeau at iram dot fr
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-10-10 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-10-10
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed with 5.2 and 6.0. I get the following ICE with 4.9

pr67740.f90:20:0: internal compiler error: in gimplify_expr, at gimplify.c:8538
   allocate(character(4) :: myBase%string)

the change occurred between revisions r221423 (2015-03-13, ICE) and
r2214164+patches (2015-03-16, compiles).


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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
  2015-10-10 10:05 ` [Bug fortran/67740] " dominiq at lps dot ens.fr
@ 2021-05-03 12:51 ` bardeau at iram dot fr
  2023-09-26 19:57 ` anlauf at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bardeau at iram dot fr @ 2021-05-03 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

Sebastien Bardeau <bardeau at iram dot fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bardeau at iram dot fr

--- Comment #4 from Sebastien Bardeau <bardeau at iram dot fr> ---
I have pretty much the same kind of issue with gfortran 10.2.0 and 11.0.1
(20210426). The following code shows invalid results (printed lengths are 0).
Sometimes I even get a program crash. If the 'data1' component is a standalone
pointer (i.e. out of the derived type), I have no issue then.

program test2
  character(len=10), target, allocatable :: s(:)
  type :: pointer_typec0_t
    character(len=:), pointer :: data1(:)
  end type pointer_typec0_t
  type(pointer_typec0_t) :: co
  !
  allocate(s(3))
  s(1) = '1234567890'
  s(2) = 'qwertyuio '
  s(3) = 'asdfghjk  '
  !
  co%data1 => s
  !
  print *,len(co%data1(1)),len_trim(co%data1(1)),co%data1(1)
  print *,len(co%data1(2)),len_trim(co%data1(2)),co%data1(2)
  print *,len(co%data1(3)),len_trim(co%data1(3)),co%data1(3)
end program test2

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
  2015-10-10 10:05 ` [Bug fortran/67740] " dominiq at lps dot ens.fr
  2021-05-03 12:51 ` bardeau at iram dot fr
@ 2023-09-26 19:57 ` anlauf at gcc dot gnu.org
  2023-09-26 20:28 ` anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-26 19:57 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #5 from anlauf at gcc dot gnu.org ---
Created attachment 55998
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55998&action=edit
Testcase for scalar pointer

The original testcase from comment#0 failed with 9.5.0, but works with 10.5.0
and newer.  An extended deja-gnuified testcase for this is attached.

The variant with array-valued pointers in comment#4 still fails.

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-09-26 19:57 ` anlauf at gcc dot gnu.org
@ 2023-09-26 20:28 ` anlauf at gcc dot gnu.org
  2023-09-27 20:07 ` anlauf at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-26 20:28 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #6 from anlauf at gcc dot gnu.org ---
Extending the testcase in comment#4:

program test2
  implicit none
  character(len=10), allocatable, target :: s(:)
  character(len=:),  pointer             :: sptr(:)
  type :: pointer_typec0_t
    character(len=:), pointer :: data1(:)
  end type pointer_typec0_t
  type(pointer_typec0_t) :: co
  !
  allocate(s(3))
  s(1) = '1234567890'
  s(2) = 'qwertyuio '
  s(3) = 'asdfghjk  '
  !
  sptr => s
  print *, sptr     ! OK
  co%data1 => s
  print *, co%data1 ! not OK
  !
  print *,len(co%data1(1)),len_trim(co%data1(1)),co%data1(1)
  print *,len(co%data1(2)),len_trim(co%data1(2)),co%data1(2)
  print *,len(co%data1(3)),len_trim(co%data1(3)),co%data1(3)
end program test2

The tree-dump has:

    .sptr = 10;
    sptr = s;
    sptr.span = s.span;

but

    co.data1 = s;
    co.data1.span = s.span;

so we don't set the character length in the association.

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-09-26 20:28 ` anlauf at gcc dot gnu.org
@ 2023-09-27 20:07 ` anlauf at gcc dot gnu.org
  2023-10-08  8:44 ` pault at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-27 20:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from anlauf at gcc dot gnu.org ---
The following snippet in gfc_trans_pointer_assignment looks suspicious:

      if (expr1->ts.type == BT_CHARACTER
          && expr1->symtree->n.sym->ts.deferred
          && expr1->symtree->n.sym->ts.u.cl->backend_decl
          && VAR_P (expr1->symtree->n.sym->ts.u.cl->backend_decl))
        {
          tmp = expr1->symtree->n.sym->ts.u.cl->backend_decl;
          if (expr2->expr_type != EXPR_NULL)
            gfc_add_modify (&block, tmp,
                            fold_convert (TREE_TYPE (tmp), strlen_rhs));
          else
            gfc_add_modify (&block, tmp, build_zero_cst (TREE_TYPE (tmp)));
        }

I wonder whether it should read:

      if (expr1->ts.type == BT_CHARACTER
          && expr1->ts.deferred
...

Furthermore, expr1->ts.u.cl->backend_decl appears not set properly,
and I fail to see why.

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-09-27 20:07 ` anlauf at gcc dot gnu.org
@ 2023-10-08  8:44 ` pault at gcc dot gnu.org
  2023-10-08 20:43 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2023-10-08  8:44 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu.org

--- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 56073
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56073&action=edit
"Fix" for this PR

Hi Harald,

You are touching the right place. However, this should be happening in
gfc_conv_expr_descriptor I would have thought so that strlen_lhs comes back
with the correct value.

Cheers

Paul

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-10-08  8:44 ` pault at gcc dot gnu.org
@ 2023-10-08 20:43 ` anlauf at gcc dot gnu.org
  2023-10-09 20:29 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-10-08 20:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from anlauf at gcc dot gnu.org ---
(In reply to Paul Thomas from comment #8)
> Created attachment 56073 [details]
> "Fix" for this PR
> 
> Hi Harald,
> 
> You are touching the right place. However, this should be happening in
> gfc_conv_expr_descriptor I would have thought so that strlen_lhs comes back
> with the correct value.

Yes, this might be a latent issue still showing up elsewhere for deferred
length, although your patch seems to fix cases immediately related to
those in this PR.

I was suspecting gfc_conv_variable as a possibly further place for a fix:
it has a loop over ref's that looks incomplete for REF_COMPONENT.

Nevertheless, your patch works for me.

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-10-08 20:43 ` anlauf at gcc dot gnu.org
@ 2023-10-09 20:29 ` anlauf at gcc dot gnu.org
  2023-10-12  6:27 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-10-09 20:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #9)

Addendum:

> I was suspecting gfc_conv_variable as a possibly further place for a fix:
> it has a loop over ref's that looks incomplete for REF_COMPONENT.

I tried my version of a patch in that place, which worked for the testcases
here but gave wrong code already for slightly more complex pointer assignments,
like

  type(pointer_typec0_t) :: co, xo
...
  xo%data1 => co%data1

so let's go with your patch.

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-10-09 20:29 ` anlauf at gcc dot gnu.org
@ 2023-10-12  6:27 ` cvs-commit at gcc dot gnu.org
  2023-10-26  9:36 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-12  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:701363d827d45d3e3601735fa42f95644fda8b64

commit r14-4583-g701363d827d45d3e3601735fa42f95644fda8b64
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Thu Oct 12 07:26:59 2023 +0100

    Fortran: Set hidden string length for pointer components [PR67740].

    2023-10-11  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/67740
            * trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
            string length component for pointer assignment to character
            pointer components.

    gcc/testsuite/
            PR fortran/67740
            * gfortran.dg/pr67740.f90: New test

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-10-12  6:27 ` cvs-commit at gcc dot gnu.org
@ 2023-10-26  9:36 ` cvs-commit at gcc dot gnu.org
  2023-10-26  9:39 ` pault at gcc dot gnu.org
  2023-10-26 12:08 ` baradi09 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-26  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:6fb12d3a0456a3503a670d95803aef10549f0134

commit r13-7986-g6fb12d3a0456a3503a670d95803aef10549f0134
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Thu Oct 12 07:26:59 2023 +0100

    Fortran: Set hidden string length for pointer components [PR67740].

    2023-10-11  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/67740
            * trans-expr.cc (gfc_trans_pointer_assignment): Set the hidden
            string length component for pointer assignment to character
            pointer components.

    gcc/testsuite/
            PR fortran/67740
            * gfortran.dg/pr67740.f90: New test

    (cherry picked from commit 701363d827d45d3e3601735fa42f95644fda8b64)

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (9 preceding siblings ...)
  2023-10-26  9:36 ` cvs-commit at gcc dot gnu.org
@ 2023-10-26  9:39 ` pault at gcc dot gnu.org
  2023-10-26 12:08 ` baradi09 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: pault at gcc dot gnu.org @ 2023-10-26  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #13 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on 13-branch and trunk.

Thanks for the report

Paul

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

* [Bug fortran/67740] Wrong association status of allocatable character pointer in derived types
  2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
                   ` (10 preceding siblings ...)
  2023-10-26  9:39 ` pault at gcc dot gnu.org
@ 2023-10-26 12:08 ` baradi09 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: baradi09 at gmail dot com @ 2023-10-26 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Bálint Aradi <baradi09 at gmail dot com> ---
Thanks a lot for fixing it!

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

end of thread, other threads:[~2023-10-26 12:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-28  6:59 [Bug fortran/67740] New: Wrong association status of allocatable character pointer in derived types baradi09 at gmail dot com
2015-10-10 10:05 ` [Bug fortran/67740] " dominiq at lps dot ens.fr
2021-05-03 12:51 ` bardeau at iram dot fr
2023-09-26 19:57 ` anlauf at gcc dot gnu.org
2023-09-26 20:28 ` anlauf at gcc dot gnu.org
2023-09-27 20:07 ` anlauf at gcc dot gnu.org
2023-10-08  8:44 ` pault at gcc dot gnu.org
2023-10-08 20:43 ` anlauf at gcc dot gnu.org
2023-10-09 20:29 ` anlauf at gcc dot gnu.org
2023-10-12  6:27 ` cvs-commit at gcc dot gnu.org
2023-10-26  9:36 ` cvs-commit at gcc dot gnu.org
2023-10-26  9:39 ` pault at gcc dot gnu.org
2023-10-26 12:08 ` baradi09 at gmail dot com

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).