https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60357
--- Comment #11 from Andre Vehreschild <vehre at gmx dot de> --- Hi Janus, before you invest too much time into that: My current patch level produces intermediate code as attached (for a slightly different program, also attached). I was solving the (re-)alloc on assign issue like in PR61275. I now run into the runtime error: At line 15 of file test_pr60357.f08: Attempting to allocate already allocated variable 'de'. Obviously I have over fullfilled the needed allocs: (1) a.5.y is allocated (2) a.4.y is allocated (3) a.0.y is allocated (4) de.y is allocated (5) a.2.y is allocated I am wondering which allocs should really be done, and which one are accidently added. I doubt that (1) and (2) should be there. (3) and (5) are ok imho. Now my client (the reporter of the bug, Antony) tells me, that (4) is valid Fortran ("valid" by ifort), but the allocate(De%y) is useless there, as it is freed before the constructor assign with implicit alloc is done. With my current patch level, your program would be running fine, because I would auto alloc y on the assignment. To summarize my questions: Which allocs should be done? Given the too allocs in (1) and (2) are removed, would the intermediate code be correct for the fortran? Can you help me on this. Regards, Andre On Mon, 29 Dec 2014 16:42:01 +0000 "janus at gcc dot gnu.org" <gcc-bugzi...@gcc.gnu.org> wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60357 > > --- Comment #10 from janus at gcc dot gnu.org --- > (In reply to Andre Vehreschild from comment #9) > > I just need to > > figure, if allocating the component explicitly is valid in Fortran. > > For sure. I think both the examples in comment 4 and 5 are actually valid > Fortran code. > > In order to make sure we're talking about the same thing, let's have a look at > the following code: > > Type A > integer :: X = 1 > integer, allocatable :: y > end type > Type(A) :: Me > allocate(Me%y) > print *,"A" > Me = A(X=1, y=2) > print *,"B" > print *, Me%y > end > > This is a variant of the example above that produced the segfault. I inserted > some print statements in order to debug it. It prints at runtime: > > A > B > > Program received signal SIGSEGV: Segmentation fault - invalid memory > reference. > > > This shows clearly that the segfault occurs when we try to access Me%y in the > last print statement, meaning that it is probably unallocated although it > clearly should be. > > -fdump-tree-original shows that the problem is in the translation of the > structure constructor assignment, which apparently leaves the y-component > unallocated. >