public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable
@ 2020-08-15  7:41 shenpo.dong@compiler-dev.com
  2020-08-15 16:11 ` [Bug fortran/96624] A segment fault " kargl at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: shenpo.dong@compiler-dev.com @ 2020-08-15  7:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96624
           Summary: A segment error occurred when using the reshape
                    function result to assign a variable
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shenpo.dong@compiler-dev.com
  Target Milestone: ---

program test
  integer :: a(2,0)
  a = reshape([1,2,3,4], [2,0])
  print *,a
end

with gcc version 10.1.0 (Ubuntu 10.1.0-2ubuntu1~18.04)
Target: aarch64-linux-gnu
i get this message:
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0xffff81755e5f
#1  0xffff81754ea7
#2  0xffff818dd687
#3  0xaaaad5c199cc
#4  0xaaaad5c19b1f
#5  0xffff816006df
#6  0xaaaad5c19883
Segmentation fault (core dumped)

But if assign values when declare them,it is correct

  integer :: a(2,0) = reshape([1,2,3,4], [2,0])
  print *,a
end

the result is a blank line

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

* [Bug fortran/96624] A segment fault occurred when using the reshape function result to assign a variable
  2020-08-15  7:41 [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable shenpo.dong@compiler-dev.com
@ 2020-08-15 16:11 ` kargl at gcc dot gnu.org
  2020-08-27 11:50 ` pault at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2020-08-15 16:11 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-08-15
             Status|UNCONFIRMED                 |NEW
           Priority|P3                          |P4

--- Comment #1 from kargl at gcc dot gnu.org ---
Why?

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c      (revision 280157)
+++ gcc/fortran/simplify.c      (working copy)
@@ -6650,6 +6650,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shap
   unsigned long j;
   size_t nsource;
   gfc_expr *e, *result;
+  bool zerosize = false;

   /* Check that argument expression types are OK.  */
   if (!is_constant_array_expr (source)
@@ -6772,8 +6773,15 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shap
   result->rank = rank;
   result->shape = gfc_get_shape (rank);
   for (i = 0; i < rank; i++)
-    mpz_init_set_ui (result->shape[i], shape[i]);
+    {
+      mpz_init_set_ui (result->shape[i], shape[i]);
+      if (shape[i] == 0)
+        zerosize = true;
+    }

+  if (zerosize)
+    goto sizezero;
+
   while (nsource > 0 || npad > 0)
     {
       /* Figure out which element to extract.  */
@@ -6821,6 +6829,8 @@ inc:

       break;
     }
+
+sizezero:

   mpz_clear (index);

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

* [Bug fortran/96624] A segment fault occurred when using the reshape function result to assign a variable
  2020-08-15  7:41 [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable shenpo.dong@compiler-dev.com
  2020-08-15 16:11 ` [Bug fortran/96624] A segment fault " kargl at gcc dot gnu.org
@ 2020-08-27 11:50 ` pault at gcc dot gnu.org
  2020-08-28  8:03 ` cvs-commit at gcc dot gnu.org
  2020-08-28  8:05 ` pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pault at gcc dot gnu.org @ 2020-08-27 11:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
Steve's patch has been OK'd here. I will commit tonight.

https://gcc.gnu.org/pipermail/fortran/2020-August/054941.html

Paul

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

* [Bug fortran/96624] A segment fault occurred when using the reshape function result to assign a variable
  2020-08-15  7:41 [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable shenpo.dong@compiler-dev.com
  2020-08-15 16:11 ` [Bug fortran/96624] A segment fault " kargl at gcc dot gnu.org
  2020-08-27 11:50 ` pault at gcc dot gnu.org
@ 2020-08-28  8:03 ` cvs-commit at gcc dot gnu.org
  2020-08-28  8:05 ` pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-28  8:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 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:9d463ce7f983f03f0d65da03cfa430e29a0840c2

commit r11-2919-g9d463ce7f983f03f0d65da03cfa430e29a0840c2
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Fri Aug 28 09:02:58 2020 +0100

    This patch fixes PR96624.

    2020-08-28  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/96624
            * simplify.c (gfc_simplify_reshape): Detect zero shape and
            clear index if found.

    gcc/testsuite/
            PR fortran/96624
            * gfortran.dg/reshape_8.f90 : New test.

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

* [Bug fortran/96624] A segment fault occurred when using the reshape function result to assign a variable
  2020-08-15  7:41 [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable shenpo.dong@compiler-dev.com
                   ` (2 preceding siblings ...)
  2020-08-28  8:03 ` cvs-commit at gcc dot gnu.org
@ 2020-08-28  8:05 ` pault at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pault at gcc dot gnu.org @ 2020-08-28  8:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Thanks for the patch, Steve.

Closing.

Paul

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-15  7:41 [Bug fortran/96624] New: A segment error occurred when using the reshape function result to assign a variable shenpo.dong@compiler-dev.com
2020-08-15 16:11 ` [Bug fortran/96624] A segment fault " kargl at gcc dot gnu.org
2020-08-27 11:50 ` pault at gcc dot gnu.org
2020-08-28  8:03 ` cvs-commit at gcc dot gnu.org
2020-08-28  8:05 ` 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).