public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
@ 2024-02-16  8:20 dcb314 at hotmail dot com
  2024-03-29  9:53 ` [Bug fortran/113956] [14 Regression] " dcb314 at hotmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: dcb314 at hotmail dot com @ 2024-02-16  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113956
           Summary: ice in gfc_trans_pointer_assignment, at
                    fortran/trans-expr.cc:10524
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Created attachment 57435
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57435&action=edit
F90 source code

From the flang test suite at

https://github.com/llvm/llvm-project/tree/main/flang/test,

the file ./Lower/pointer-assignments.f90 does this:

test $ ~/gcc/results/bin/gfortran -c -w ./Lower/dummy-procedure-character.f90
./Lower/dummy-procedure-character.f90:183:4:

  183 |     function bar10(n)
      |    1
internal compiler error: in gfc_get_symbol_decl, at fortran/trans-decl.cc:1629
0x861f00 gfc_get_symbol_decl(gfc_symbol*)
       
/home/dcb38/gcc/working/gcc/../../trunk.20210101/gcc/fortran/trans-decl.cc:1629
0x8911b5 gfc_conv_variable(gfc_se*, gfc_expr*)
       
/home/dcb38/gcc/working/gcc/../../trunk.20210101/gcc/fortran/trans-expr.cc:3049

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

* [Bug fortran/113956] [14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
@ 2024-03-29  9:53 ` dcb314 at hotmail dot com
  2024-03-29 12:03 ` [Bug fortran/113956] [13/14 " anlauf at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dcb314 at hotmail dot com @ 2024-03-29  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

David Binderman <dcb314 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ice in                      |[14 Regression] ice in
                   |gfc_trans_pointer_assignmen |gfc_trans_pointer_assignmen
                   |t, at                       |t, at
                   |fortran/trans-expr.cc:10524 |fortran/trans-expr.cc:10524

--- Comment #1 from David Binderman <dcb314 at hotmail dot com> ---
It looks like a regression from gcc-13.2:

test $ ~/gcc/results.13.2.asan.ubsan/bin/gfortran -c -w
./Lower/pointer-assignments.f90
test $ ~/gcc/results.20240327.asan.ubsan/bin/gfortran -c -w
./Lower/pointer-assignments.f90
./Lower/pointer-assignments.f90:54:8:

   54 |   p => x
      |        1
internal compiler error: in gfc_trans_pointer_assignment, at
fortran/trans-expr.cc:10539

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
  2024-03-29  9:53 ` [Bug fortran/113956] [14 Regression] " dcb314 at hotmail dot com
@ 2024-03-29 12:03 ` anlauf at gcc dot gnu.org
  2024-03-29 15:35 ` pault at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-03-29 12:03 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.3
                 CC|                            |anlauf at gcc dot gnu.org,
                   |                            |pault at gcc dot gnu.org
           Keywords|                            |ice-on-valid-code
   Last reconfirmed|                            |2024-03-29
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|[14 Regression] ice in      |[13/14 Regression] ice in
                   |gfc_trans_pointer_assignmen |gfc_trans_pointer_assignmen
                   |t, at                       |t, at
                   |fortran/trans-expr.cc:10524 |fortran/trans-expr.cc:10524

--- Comment #2 from anlauf at gcc dot gnu.org ---
Reduced testcase:

subroutine test_array_char(p, x)
  character(*), target  :: x(100)
  character(:), pointer :: p(:)
  p => x
end subroutine


We hit an assert that can be worked around with the following patch:

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index d21e3956d6e..fa31f950363 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -10534,12 +10535,9 @@ gfc_trans_pointer_assignment (gfc_expr * expr1,
gfc_expr * expr2)
        {
          gfc_symbol *psym = expr1->symtree->n.sym;
          tmp = NULL_TREE;
-         if (psym->ts.type == BT_CHARACTER)
-           {
-             gcc_assert (psym->ts.u.cl->backend_decl
-                         && VAR_P (psym->ts.u.cl->backend_decl));
-             tmp = psym->ts.u.cl->backend_decl;
-           }
+         if (psym->ts.type == BT_CHARACTER
+             && psym->ts.u.cl->backend_decl)
+           tmp = psym->ts.u.cl->backend_decl;
          else if (expr1->ts.u.cl->backend_decl
                   && VAR_P (expr1->ts.u.cl->backend_decl))
            tmp = expr1->ts.u.cl->backend_decl;


This fragment was touched by Paul's fix for pr67740 (r14-4583), so adding
him.

@Paul: can you please have a look?

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
  2024-03-29  9:53 ` [Bug fortran/113956] [14 Regression] " dcb314 at hotmail dot com
  2024-03-29 12:03 ` [Bug fortran/113956] [13/14 " anlauf at gcc dot gnu.org
@ 2024-03-29 15:35 ` pault at gcc dot gnu.org
  2024-03-29 16:37 ` anlauf at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-03-29 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #2)
> Reduced testcase:
> 
> subroutine test_array_char(p, x)
>   character(*), target  :: x(100)
>   character(:), pointer :: p(:)
>   p => x
> end subroutine
> 
> 
> We hit an assert that can be worked around with the following patch:
> 
> diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
> index d21e3956d6e..fa31f950363 100644
> --- a/gcc/fortran/trans-expr.cc
> +++ b/gcc/fortran/trans-expr.cc
> @@ -10534,12 +10535,9 @@ gfc_trans_pointer_assignment (gfc_expr * expr1,
> gfc_expr * expr2)
>  	{
>  	  gfc_symbol *psym = expr1->symtree->n.sym;
>  	  tmp = NULL_TREE;
> -	  if (psym->ts.type == BT_CHARACTER)
> -	    {
> -	      gcc_assert (psym->ts.u.cl->backend_decl
> -			  && VAR_P (psym->ts.u.cl->backend_decl));
> -	      tmp = psym->ts.u.cl->backend_decl;
> -	    }
> +	  if (psym->ts.type == BT_CHARACTER
> +	      && psym->ts.u.cl->backend_decl)
> +	    tmp = psym->ts.u.cl->backend_decl;
>  	  else if (expr1->ts.u.cl->backend_decl
>  		   && VAR_P (expr1->ts.u.cl->backend_decl))
>  	    tmp = expr1->ts.u.cl->backend_decl;
> 
> 
> This fragment was touched by Paul's fix for pr67740 (r14-4583), so adding
> him.
> 
> @Paul: can you please have a look?

I can see why the assert is there but it is manifestly wrong for both the
assumed length target and a constant length. I was thrown a bit by the distros
nulling out the asserts so that it compiled just fine with the system gfortran.

Your patch is perfect :- This compiles and runs correctly:
module m
contains
  subroutine test_array_char(p, x)
    character(*), target  :: x(:)
    character(:), pointer :: p(:)
    p => x
  end subroutine
end module

  use m
  character(:), allocatable, target :: chr(:)
  character(:), pointer :: p(:)
  chr = ["ab","cd"]
  call test_array_char (p, chr)
  print '(l2,i4,2a4)', loc(chr) == loc(p), len(p), p
end

Cheers

Paul

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2024-03-29 15:35 ` pault at gcc dot gnu.org
@ 2024-03-29 16:37 ` anlauf at gcc dot gnu.org
  2024-04-02 19:19 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-03-29 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to Paul Thomas from comment #3)
> I can see why the assert is there but it is manifestly wrong for both the
> assumed length target and a constant length.

That's why I wanted to pass this on to you.  I am not sure what the precise
logic should be.

> I was thrown a bit by the
> distros nulling out the asserts so that it compiled just fine with the
> system gfortran.

If the system gfortran is based on 13.2 *release* then the bug is not yet
there ;-)  It entered 13-branch through backport r13-7986.

> Your patch is perfect :- This compiles and runs correctly:
> module m
> contains
>   subroutine test_array_char(p, x)
>     character(*), target  :: x(:)
>     character(:), pointer :: p(:)
>     p => x
>   end subroutine
> end module
> 
>   use m
>   character(:), allocatable, target :: chr(:)
>   character(:), pointer :: p(:)
>   chr = ["ab","cd"]
>   call test_array_char (p, chr)
>   print '(l2,i4,2a4)', loc(chr) == loc(p), len(p), p
> end

The original testcase attached here has a second subroutine that ICEd:

subroutine test_array_char_remap(p, x)
  character(*), target  :: x(100)
  character(:), pointer :: p(:, :)
  p(2:11, 3:12) => x
end subroutine

It is also fixed by the patch, and checking the bounds etc. in the caller
shows that it works correct too :-)

program main
  implicit none
  character(3) :: x(100) = "* #"
  character(:), pointer :: p(:), q(:,:)
  call test_array_char (p, x)
  print *, associated (p)
  print *, size (p)
  print *, len (p)
  print *, p(5)(1:1)
  call test_array_char_remap (q, x)
  print *, associated (q)
  print *, size (q)
  print *, len (q)
  print *, lbound(q), ubound(q)
  print *, q(5,5)(3:3)
contains

subroutine test_array_char(p, x)
  character(*), target  :: x(100)
  character(:), pointer :: p(:)
  p => x
end subroutine

subroutine test_array_char_remap(p, x)
  character(*), target  :: x(100)
  character(:), pointer :: p(:, :)
  p(2:11, 3:12) => x
end subroutine

end

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (3 preceding siblings ...)
  2024-03-29 16:37 ` anlauf at gcc dot gnu.org
@ 2024-04-02 19:19 ` anlauf at gcc dot gnu.org
  2024-04-03 13:06 ` pault at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-02 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #4)
> (In reply to Paul Thomas from comment #3)
> > I can see why the assert is there but it is manifestly wrong for both the
> > assumed length target and a constant length.
> 
> That's why I wanted to pass this on to you.  I am not sure what the precise
> logic should be.
> 
> > I was thrown a bit by the
> > distros nulling out the asserts so that it compiled just fine with the
> > system gfortran.
> 
> If the system gfortran is based on 13.2 *release* then the bug is not yet
> there ;-)  It entered 13-branch through backport r13-7986.
> 
> > Your patch is perfect :- This compiles and runs correctly:

Paul, if you want to commit the patch, consider it preapproved  :-)

Otherwise I would take it, but I fear possible subtleties in the logic
involved that I do not see...

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (4 preceding siblings ...)
  2024-04-02 19:19 ` anlauf at gcc dot gnu.org
@ 2024-04-03 13:06 ` pault at gcc dot gnu.org
  2024-04-09 14:23 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-04-03 13:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
I'll take it.

Paul

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (5 preceding siblings ...)
  2024-04-03 13:06 ` pault at gcc dot gnu.org
@ 2024-04-09 14:23 ` cvs-commit at gcc dot gnu.org
  2024-04-17 13:34 ` law at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-09 14:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC 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:88aea122a7ee639230bf17a9eda4bf8a5eb7e282

commit r14-9873-g88aea122a7ee639230bf17a9eda4bf8a5eb7e282
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Apr 9 15:23:46 2024 +0100

    Fortran: Fix ICE in gfc_trans_pointer_assignment [PR113956]

    2024-04-09  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/113956
            * trans-expr.cc (gfc_trans_pointer_assignment): Remove assert
            causing the ICE since it was unnecesary.

    gcc/testsuite/
            PR fortran/113956
            * gfortran.dg/pr113956.f90: New test.

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

* [Bug fortran/113956] [13/14 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (6 preceding siblings ...)
  2024-04-09 14:23 ` cvs-commit at gcc dot gnu.org
@ 2024-04-17 13:34 ` law at gcc dot gnu.org
  2024-05-08  8:06 ` [Bug fortran/113956] [13 " cvs-commit at gcc dot gnu.org
  2024-05-08  8:08 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: law at gcc dot gnu.org @ 2024-04-17 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P4

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

* [Bug fortran/113956] [13 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (7 preceding siblings ...)
  2024-04-17 13:34 ` law at gcc dot gnu.org
@ 2024-05-08  8:06 ` cvs-commit at gcc dot gnu.org
  2024-05-08  8:08 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-08  8:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from GCC 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:102d52967bde164d6b99037465688b62d57ae560

commit r13-8715-g102d52967bde164d6b99037465688b62d57ae560
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue Apr 9 15:23:46 2024 +0100

    Fortran: Fix ICE in gfc_trans_pointer_assignment [PR113956]

    2024-04-09  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/113956
            * trans-expr.cc (gfc_trans_pointer_assignment): Remove assert
            causing the ICE since it was unnecesary.

    gcc/testsuite/
            PR fortran/113956
            * gfortran.dg/pr113956.f90: New test.

    (cherry picked from commit 88aea122a7ee639230bf17a9eda4bf8a5eb7e282)

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

* [Bug fortran/113956] [13 Regression] ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524
  2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
                   ` (8 preceding siblings ...)
  2024-05-08  8:06 ` [Bug fortran/113956] [13 " cvs-commit at gcc dot gnu.org
@ 2024-05-08  8:08 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2024-05-08  8:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on 13- through 15-branches. Thanks for the report.

Paul

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

end of thread, other threads:[~2024-05-08  8:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16  8:20 [Bug fortran/113956] New: ice in gfc_trans_pointer_assignment, at fortran/trans-expr.cc:10524 dcb314 at hotmail dot com
2024-03-29  9:53 ` [Bug fortran/113956] [14 Regression] " dcb314 at hotmail dot com
2024-03-29 12:03 ` [Bug fortran/113956] [13/14 " anlauf at gcc dot gnu.org
2024-03-29 15:35 ` pault at gcc dot gnu.org
2024-03-29 16:37 ` anlauf at gcc dot gnu.org
2024-04-02 19:19 ` anlauf at gcc dot gnu.org
2024-04-03 13:06 ` pault at gcc dot gnu.org
2024-04-09 14:23 ` cvs-commit at gcc dot gnu.org
2024-04-17 13:34 ` law at gcc dot gnu.org
2024-05-08  8:06 ` [Bug fortran/113956] [13 " cvs-commit at gcc dot gnu.org
2024-05-08  8:08 ` pault at gcc dot gnu.org

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