trans-array.c (gfc_alloc_allocatable_for_assignment): Allocate at least one byte.
authorTobias Burnus <burnus@net-b.de>
Fri, 21 Jun 2013 21:24:59 +0000 (23:24 +0200)
committerTobias Burnus <burnus@gcc.gnu.org>
Fri, 21 Jun 2013 21:24:59 +0000 (23:24 +0200)
2013-06-21  Tobias Burnus  <burnus@net-b.de>

        * trans-array.c (gfc_alloc_allocatable_for_assignment): Allocate
        at least one byte.
        * trans-expr.c (alloc_scalar_allocatable_for_assignment): Ditto.

2013-06-21  Tobias Burnus  <burnus@net-b.de>

        * gfortran.dg/realloc_on_assign_18.f90: New.

From-SVN: r200320

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/realloc_on_assign_18.f90 [new file with mode: 0644]

index 0ae3f37..8e4b7a1 100644 (file)
@@ -1,3 +1,9 @@
+2013-06-21  Tobias Burnus  <burnus@net-b.de>
+
+       * trans-array.c (gfc_alloc_allocatable_for_assignment): Allocate
+       at least one byte.
+       * trans-expr.c (alloc_scalar_allocatable_for_assignment): Ditto.
+
 2013-06-20  Tobias Burnus  <burnus@net-b.de>
 
        * resolve.c (get_temp_from_expr): Don't set FL_VARIABLE twice.
index a4321cc..dc9637a 100644 (file)
@@ -8209,6 +8209,8 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop,
                           gfc_array_index_type,
                           tmp, size2);
   size2 = fold_convert (size_type_node, size2);
+  size2 = fold_build2_loc (input_location, MAX_EXPR, size_type_node,
+                          size2, size_one_node);
   size2 = gfc_evaluate_now (size2, &fblock);
 
   /* Realloc expression.  Note that the scalarizer uses desc.data
index bd8886c..56dc766 100644 (file)
@@ -7574,6 +7574,9 @@ alloc_scalar_allocatable_for_assignment (stmtblock_t *block,
       size_in_bytes = size;
     }
 
+  size_in_bytes = fold_build2_loc (input_location, MAX_EXPR, size_type_node,
+                                  size_in_bytes, size_one_node);
+
   if (expr1->ts.type == BT_DERIVED && expr1->ts.u.derived->attr.alloc_comp)
     {
       tmp = build_call_expr_loc (input_location,
index 9c3fe0e..aca4074 100644 (file)
@@ -1,3 +1,7 @@
+2013-06-21  Tobias Burnus  <burnus@net-b.de>
+
+       * gfortran.dg/realloc_on_assign_18.f90: New.
+
 2013-06-21  Balaji V. Iyer  <balaji.v.iyer@intel.com>
 
        * c-c++-common/cilk-plus/AN/array_test1.c: Make this an execution test.
diff --git a/gcc/testsuite/gfortran.dg/realloc_on_assign_18.f90 b/gcc/testsuite/gfortran.dg/realloc_on_assign_18.f90
new file mode 100644 (file)
index 0000000..d174355
--- /dev/null
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+!
+! Ensure that for zero-sized array, nonzero memory is allocated
+!
+type t
+end type t
+
+type(t), allocatable :: x, y(:)
+
+x = t()
+y = [ t :: ]
+
+if (.not. allocated (x)) call abort ()
+if (.not. allocated (y)) call abort ()
+end
+
+! { dg-final { scan-tree-dump "x = \\(struct t .\\) __builtin_malloc \\(1\\);" "original" } }
+! { dg-final { scan-tree-dump "y.data = \\(void . restrict\\) __builtin_malloc \\(1\\);" "original" } }
+! { dg-final { cleanup-tree-dump "original" } }