PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Dynamic type information lost? (PGI 13.7)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Sean Patrick Santos



Joined: 15 Sep 2013
Posts: 15

PostPosted: Sun Sep 15, 2013 10:45 pm    Post subject: Dynamic type information lost? (PGI 13.7) Reply with quote

The code at the end of this post shows a very specific case where PGI seems to have a bug causing a segfault. The "FooContainer" type has an allocatable component of abstract type (FooBase). If you use an init method to allocate that component based on some input, and then call a type-bound procedure on that component, you get a segfault.

When I was mucking about trying to find a workaround, I found three more things:

1) It seems to be impossible to use a "select type" construct to get information about the type of my_foo, since you instead get information about "self" (the FooContainer object).

2) If you copy my_foo, the copy doesn't seem to have any dynamic type information. If you put it in a select type construct, it will always fall through to the "class default" clause.

3) If you don't use the FooContainer_init function to set my_foo, and instead allocate my_foo directly, there didn't seem to be a problem. Using a type-bound "init" subroutine also seems to do the trick, which ended up being the workaround that I use. This suggests that the real problem here is the assignment from the output of the FooContainer_init function.

(One of my test cases found a different issue, which is that pgfortran doesn't allow you to allocate "empty" types with no components. I'm not sure why, since this seems explicitly allowed in Fortran; maybe just an unimplemented feature?)



Code:

module foo_mod

implicit none

type, abstract :: FooBase
   integer :: a
 contains
   procedure(do_proc), pass(self), deferred :: do_stuff
end type FooBase

abstract interface
   subroutine do_proc(self)
     import
     class(FooBase), intent(in) :: self
   end subroutine do_proc
end interface

type, extends(FooBase) :: Foo
   integer :: b
 contains
   procedure, pass(self) :: do_stuff => really_do_stuff
end type Foo

type :: FooContainer
   class(FooBase), allocatable :: my_foo
 contains
   procedure, pass(self) :: do_stuff_wrap
end type FooContainer

contains

subroutine really_do_stuff(self)
  class(Foo), intent(in) :: self

  print *, "Hi!"

end subroutine really_do_stuff

function FooContainer_init(foo_in) result(res)
  class(FooBase), intent(in) :: foo_in
  type(FooContainer) :: res
  allocate(res%my_foo, source=foo_in)
end function FooContainer_init

subroutine do_stuff_wrap(self)
  class(FooContainer), intent(in) :: self

  call self%my_foo%do_stuff()

end subroutine do_stuff_wrap

end module foo_mod

program test_poly

use foo_mod

implicit none

type(Foo) :: local_foo
type(FooContainer) :: foo_wrap

foo_wrap = FooContainer_init(local_foo)

call foo_wrap%do_stuff_wrap()

end program test_poly
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Mon Sep 16, 2013 1:58 pm    Post subject: Reply with quote

Hi Sean,

Thanks for the report. I filed a problem report (TPR#19589) and sent it to engineering for further investigation.

Best Regards,
Mat
Back to top
View user's profile
jtull



Joined: 30 Jun 2004
Posts: 445

PostPosted: Fri Nov 01, 2013 1:34 pm    Post subject: TPR 19589 - UF: Dynamic type information lost? (PGI 13.7) Reply with quote

TPR 19589 is fixed now in the 13.10 release.
thanks,
dave
Back to top
View user's profile
Sean Patrick Santos



Joined: 15 Sep 2013
Posts: 15

PostPosted: Tue Nov 19, 2013 11:22 am    Post subject: Reply with quote

Thanks for the update; the bugs fixed in versions 13.9 and 13.10 have been quite helpful!

Could you also file a TPR for the other issue I encountered? I specifically mean allocating an empty type:

Code:

type foo
end type foo

type(foo), allocatable :: x

allocate(x)

end


This causes the following compilation error:

Quote:

PGF90-S-0151-Empty TYPE, STRUCTURE, UNION, or MAP (test_empty_type.F90: 8)
0 inform, 0 warnings, 1 severes, 0 fatal for MAIN


The main case where you would want to allocate an empty type is to leverage polymorphism, in which case you would declare "class(foo)"; the error actually goes away in that case. But it seems a little inconsistent; I don't see a reason why the above shouldn't work.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Wed Nov 20, 2013 10:18 am    Post subject: Reply with quote

Hi Sean,

Not sure why but it looks like this one did not get in 13.10. The error does not occur in the pre-release 14.1 compiler, which will be available in January.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group