public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/35824] New: Overloading problems with derived type with allocatable array
@ 2008-04-04 9:19 everyo at gmx dot net
2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: everyo at gmx dot net @ 2008-04-04 9:19 UTC (permalink / raw)
To: gcc-bugs
I have a derived type with an allocatable array and have overloaded some
operations. Unfortunately assignments like a=-a don't work.
Code in the Module, where I definde the type:
type alltype
double precision :: a
double precision,allocatable :: b(:)
end type
interface assignment(=)
module procedure at_from_at
end interface
interface operator(-)
module procedure neg_at
end interface
contains
subroutine at_from_at(b,a)
type(alltype), intent(in) :: a
type(alltype), intent(out) :: b
b%a=a%a
allocate(b%b(2))
b%b=a%b
end subroutine at_from_at
function neg_at(a) result(b)
type(alltype), intent(in) :: a
type(alltype) :: b
b%a=-a%a
allocate(b%b(2))
b%b=-a%b
end function neg_at
The allocatable array has an dimension of 2 in this example...
Now the code:
use typemodule
type(alltype) t1,t2,t3
allocate(t1%b(2))
t1%a=0.5d0
t1%b(1)=1d0
t1%b(2)=2d0
t2=-t1
write(*,*) t2%a, t2%b
t1=-t1
write(*,*) t1%a, t1%b
Prints:
-0.50000000000000000 -1.00000000000000000 -2.0000000000000000
Segmentation fault
It seems that in the Module, the allocatated array of t1 doesn't get passed
properly in the t1=-t1 part. I have also seg. faults in situations like a=a+b
(where + is overloaded simiarly)
The same code works correctly with ifort.
--
Summary: Overloading problems with derived type with allocatable
array
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: everyo at gmx dot net
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
@ 2008-04-04 10:10 ` dominiq at lps dot ens dot fr
2008-04-04 14:15 ` burnus at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: dominiq at lps dot ens dot fr @ 2008-04-04 10:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from dominiq at lps dot ens dot fr 2008-04-04 10:09 -------
Confirmed on powerpc-apple-darwin9 (but not on i686-apple-darwin9). The bus
error comes from the statement 'b%b=-a%b' in function 'neg_at'. If I insert
'print *, allocated(a%b)' in the function, I get .false. on powerpc (but .true.
for i686) for 't1=-t1'.
--
dominiq at lps dot ens dot fr changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Overloading problems with |Overloading problems with
|derived type with |derived type with
|allocatable array |allocatable array
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
@ 2008-04-04 14:15 ` burnus at gcc dot gnu dot org
2008-05-18 15:38 ` pault at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-04-04 14:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from burnus at gcc dot gnu dot org 2008-04-04 14:14 -------
> Confirmed on powerpc-apple-darwin9 (but not on i686-apple-darwin9). The bus
> error comes from the statement 'b%b=-a%b' in function 'neg_at'. If I insert
> 'print *, allocated(a%b)' in the function, I get .false. on powerpc (but .true.
> for i686) for 't1=-t1'.
Also confirmed on x86-64-linux. I always get non allocated before and allocated
after the allocation statement, which looks OK.
I have to admit, I did not quickly see in the dump (-fdump-tree-original) why
it is failing; at a glance, both calling "neg_at" in MAIN__ and the assignment
in "neg_at" itself look ok; and "t2 = -t1" also works.
Side question: Why do we initialize b.b.data with NULL 3 times?
b.b.data = 0B;
b.b.data = 0B;
{
struct alltype alltype.0;
alltype.0.b.data = 0B;
b = alltype.0;
}
--
burnus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2008-04-04 14:14:38
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
2008-04-04 14:15 ` burnus at gcc dot gnu dot org
@ 2008-05-18 15:38 ` pault at gcc dot gnu dot org
2008-05-18 16:01 ` pault at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-05-18 15:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pault at gcc dot gnu dot org 2008-05-18 15:37 -------
> I have to admit, I did not quickly see in the dump (-fdump-tree-original) why
> it is failing; at a glance, both calling "neg_at" in MAIN__ and the assignment
> in "neg_at" itself look ok; and "t2 = -t1" also works.
The reason is that the lhs is deallocated and nulled before the assignment:
if (t1.b.data != 0B)
{
__builtin_free (t1.b.data);
}
t1.b.data = 0B;
D.722 = neg_at (&t1);
at_from_at (&t1, &D.722);
if (D.722.b.data != 0B)
{
__builtin_free (D.722.b.data);
}
D.722.b.data = 0B;
}
Thus a data null is passed to the neg_at.
If the operator assignment is deleted, so that we rely on the intrinsic
assignment for derived types with allocatable components, the correct result is
obtained:
D.719 = t2;
t2 = neg_at (&t1);
if (D.719.b.data != 0B)
{
__builtin_free (D.719.b.data);
}
D.719.b.data = 0B;
I'll have to see how that can be emulated.
Paul
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
` (2 preceding siblings ...)
2008-05-18 15:38 ` pault at gcc dot gnu dot org
@ 2008-05-18 16:01 ` pault at gcc dot gnu dot org
2008-11-30 8:05 ` pault at gcc dot gnu dot org
2008-11-30 8:51 ` pault at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-05-18 16:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pault at gcc dot gnu dot org 2008-05-18 16:00 -------
(In reply to comment #3)
The patch that I have been working on, which is held up by memory leak
problems, actually cures this fellow too.
I am active again on all the allocatable component bugs.
Watch this space.
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pault at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2008-04-04 14:14:38 |2008-05-18 16:00:55
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
` (3 preceding siblings ...)
2008-05-18 16:01 ` pault at gcc dot gnu dot org
@ 2008-11-30 8:05 ` pault at gcc dot gnu dot org
2008-11-30 8:51 ` pault at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-30 8:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pault at gcc dot gnu dot org 2008-11-30 08:04 -------
This is fixed for trunk and 4.3.
I have prepared a testcase that will be committed tonight.
Thanks for the report.
Paul
--
pault at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/35824] Overloading problems with derived type with allocatable array
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
` (4 preceding siblings ...)
2008-11-30 8:05 ` pault at gcc dot gnu dot org
@ 2008-11-30 8:51 ` pault at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2008-11-30 8:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from pault at gcc dot gnu dot org 2008-11-30 08:50 -------
Subject: Bug 35824
Author: pault
Date: Sun Nov 30 08:48:51 2008
New Revision: 142292
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142292
Log:
2008-11-30 Paul Thomas <pault@gcc.gnu.org>
PR fortran/35824
* gfortran.dg/alloc_comp_assign_8.f90 : New test.
Added:
trunk/gcc/testsuite/gfortran.dg/alloc_comp_assign_8.f90
Modified:
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35824
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-11-30 8:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-04 9:19 [Bug fortran/35824] New: Overloading problems with derived type with allocatable array everyo at gmx dot net
2008-04-04 10:10 ` [Bug fortran/35824] " dominiq at lps dot ens dot fr
2008-04-04 14:15 ` burnus at gcc dot gnu dot org
2008-05-18 15:38 ` pault at gcc dot gnu dot org
2008-05-18 16:01 ` pault at gcc dot gnu dot org
2008-11-30 8:05 ` pault at gcc dot gnu dot org
2008-11-30 8:51 ` pault at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).