[Patch, Fortran] PR57697 - Fix an issue with defined assignment

Tobias Burnus burnus@net-b.de
Tue Sep 10 06:11:00 GMT 2013


Dear all,

in Fortran 2003, it can happen that for an intrinisic assignment of a 
derived type, the component fits to a defined assignment; in that case, 
the latter is invoked. gfortran implements this since GCC 4.8 (December).

However, it turned out that the current algorithm doesn't work if the 
LHS is allocatable and unallocated as it generated the following code:

       if (_F.DA0 != 0B) goto L.1;
       _F.DA0 = (struct parent *) __builtin_malloc (4);
       L.1:;
       *_F.DA0 = *left;
       if (left != 0B) goto L.3;
       left = (struct parent *) __builtin_malloc (4);
       L.3:;
       *left = right;

The line "*_F.DA0 = *left;" will fail due to the NULL-pointer deref.


With the attached patch, one generates the code:

       if (left != 0B)
         {
           if (_F.DA0 != 0B) goto L.2;
           _F.DA0 = (struct parent *) __builtin_malloc (4);
           L.2:;
           *_F.DA0 = *left;
         }
       L.1:;
       if (left != 0B) goto L.4;
       left = (struct parent *) __builtin_malloc (4);
       L.4:;
       *left = right;
       if (_F.DA0 == 0B)
           _F.DA0 = left;  // Note: That's a pointer assignment


Built and regtested on x86-64-gnu-linux. OK for the trunk? What about 
GCC 4.8? It's not a true regression (as defined assignments are new), 
but it causes segfaults with code which worked before GCC 4.8 [Dec 2012] 
(albeit with intrinsic instead of defined assignment).

Tobias

PS: One code which exposes the problem is a test case shipping with 
ForTrilinos.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: defined-asgn-fix.diff
Type: text/x-patch
Size: 3421 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20130910/5449d73a/attachment.bin>


More information about the Fortran mailing list