http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51218

--- Comment #8 from Harald Anlauf <anlauf at gmx dot de> 2011-11-19 10:18:46 
UTC ---
(In reply to comment #6)
> Aha.  Compiling just main.f90 with -fno-frontend-optimize solves
> the problem.

Comparing -fdump-tree-original for main.f90 at -O0  without
and with -fno-frontend-optimize shows:

--- noopt/main.f90.003t.original        2011-11-19 10:51:21.000000000 +0100
+++ opt/main.f90.003t.original  2011-11-19 10:52:10.000000000 +0100
@@ -7,6 +7,7 @@
   static struct t_vector xi = {.info=0B, .n=0, .n_s=0, .alloc_l=0,
.s={.data=0B
}};

   {
+    struct t_vector __var_1;
     integer(kind=4) overflow.2;
     logical(kind=4) D.1818;
     character(kind=4) size.1;
@@ -259,14 +260,9 @@
       _gfortran_transfer_character_write (&dt_parm.11, &"Before u:"[1]{lb: 1
sz
: 1}, 9);
       _gfortran_st_write_done (&dt_parm.11);
     }
-    {
-      struct t_vector D.1860;
-      struct t_vector D.1859;
-
-      D.1859 = vector_times_vector (&xi, &wi);
-      D.1860 = vector_times_vector (&xi, &wi);
-      u = sum_vector (&D.1859) + sum_vector (&D.1860);
-    }
+    __var_1 = vector_times_vector (&xi, &wi);
+    u = sum_vector (&__var_1) + sum_vector (&__var_1);
+    L.4:;
     {
       struct __st_parameter_dt dt_parm.12;


This won't work.  The implementation of the management
of temporaries does not allow that the same instance
is used more than once.

The other case with the commented lines exchanged:

+++ opt2/main.f90.003t.original 2011-11-19 10:59:23.000000000 +0100
@@ -7,6 +7,7 @@
   static struct t_vector xi = {.info=0B, .n=0, .n_s=0, .alloc_l=0,
.s={.data=0B
}};

   {
+    struct t_vector __var_1;
     integer(kind=4) overflow.2;
     logical(kind=4) D.1818;
     character(kind=4) size.1;
@@ -259,16 +260,14 @@
       _gfortran_transfer_character_write (&dt_parm.11, &"Before u:"[1]{lb: 1
sz
: 1}, 9);
       _gfortran_st_write_done (&dt_parm.11);
     }
+    __var_1 = vector_times_vector (&xi, &wi);
     {
       struct t_vector D.1862;
-      struct t_vector D.1860;
-      struct t_vector D.1859;

-      D.1859 = vector_times_vector (&xi, &wi);
-      D.1860 = vector_times_vector (&xi, &wi);
-      D.1862 = add_vectors (&D.1859, &D.1860);
+      D.1862 = add_vectors (&__var_1, &__var_1);
       u = sum_vector (&D.1862);
     }
+    L.4:;
     {
       struct __st_parameter_dt dt_parm.12;


Almost the same here, with aliasing of the arguments leading
to the slightly different crash.

Reply via email to