aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2020-08-28 09:02:58 +0100
committerPaul Thomas <pault@gcc.gnu.org>2020-08-28 09:02:58 +0100
commit9d463ce7f983f03f0d65da03cfa430e29a0840c2 (patch)
tree41ec23c59b00c5ee782babaea371f2d1fe85700f
parent3ba43155d2b27978589b2c1b0c4fdbaf8d4bba4d (diff)
downloadgcc-9d463ce7f983f03f0d65da03cfa430e29a0840c2.zip
gcc-9d463ce7f983f03f0d65da03cfa430e29a0840c2.tar.gz
gcc-9d463ce7f983f03f0d65da03cfa430e29a0840c2.tar.bz2
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.
-rw-r--r--gcc/fortran/simplify.c14
-rw-r--r--gcc/testsuite/gfortran.dg/reshape_8.f9014
2 files changed, 26 insertions, 2 deletions
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 074b50c..8e0d2f9 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -6398,7 +6398,7 @@ gfc_simplify_is_contiguous (gfc_expr *array)
if (gfc_is_not_contiguous (array))
return gfc_get_logical_expr (gfc_default_logical_kind, &array->where, 0);
-
+
return NULL;
}
@@ -6725,6 +6725,7 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
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)
@@ -6847,7 +6848,14 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp,
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)
{
@@ -6897,6 +6905,8 @@ inc:
break;
}
+sizezero:
+
mpz_clear (index);
return result;
diff --git a/gcc/testsuite/gfortran.dg/reshape_8.f90 b/gcc/testsuite/gfortran.dg/reshape_8.f90
new file mode 100644
index 0000000..01799ac
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/reshape_8.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Test the fix for PR96624 in which an attempt was made to assign
+! to the zero length temporary created by reshape, resulting in a segfault.
+!
+! Contributed by Dong Shenpo <shenpo.dong@compiler-dev.com>
+!
+program test
+ integer :: a(2,0)
+ a = reshape([1,2,3,4], [2,0])
+ print *, a
+end
+! { dg-final { scan-tree-dump-times "data" 4 "original" } }
e-tables'>users/ccoutant/two-level-line-tables Unnamed repository; edit this file 'description' to name the repository.root
aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/pass-by-ref.cc
blob: 6314108baa21b33743c4c9ad946f33ec7484ff2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* This testcase is part of GDB, the GNU debugger.

   Copyright 2007-2015 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

class Obj {
public:
  Obj ();
  Obj (const Obj &);
  ~Obj ();
  int var[2];
};

int foo (Obj arg)
{
  return arg.var[0] + arg.var[1];
}

Obj::Obj ()
{
  var[0] = 1;
  var[1] = 2;
}

Obj::Obj (const Obj &obj)
{
  var[0] = obj.var[0];
  var[1] = obj.var[1];
}

Obj::~Obj ()
{

}

struct Derived : public Obj
{
  int other;
};

int blap (Derived arg)
{
  return foo (arg);
}

struct Container
{
  Obj obj;
};

int blip (Container arg)
{
  return foo (arg.obj);
}

Obj global_obj;
Derived global_derived;
Container global_container;

int
main ()
{
  int bar = foo (global_obj);
  blap (global_derived);
  blip (global_container);
  return bar;
}