public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [Patch, Fortran, OOP] PR 44912: Segmentation fault on TBP
@ 2010-07-31 13:56 Dominique Dhumieres
  2010-07-31 14:19 ` Janus Weil
  0 siblings, 1 reply; 12+ messages in thread
From: Dominique Dhumieres @ 2010-07-31 13:56 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, janus

Janus,

Compiling gcc/fortran/module.c with the patch fails with:

...
/opt/gcc/build_w/./prev-gcc/xgcc -B/opt/gcc/build_w/./prev-gcc/ -B/opt/gcc/gcc4.6w/x86_64-apple-darwin10.4.0/bin/ -B/opt/gcc/gcc4.6w/x86_64-apple-darwin10.4.0/bin/ -B/opt/gcc/gcc4.6w/x86_64-apple-darwin10.4.0/lib/ -isystem /opt/gcc/gcc4.6w/x86_64-apple-darwin10.4.0/include -isystem /opt/gcc/gcc4.6w/x86_64-apple-darwin10.4.0/sys-include    -c  -DIN_GCC_FRONTEND -g -O2 -gtoggle -DIN_GCC   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -Wold-style-definition -Wc++-compat -fno-common  -DHAVE_CONFIG_H -I. -Ifortran -I../../work/gcc -I../../work/gcc/fortran -I../../work/gcc/../include -I../../work/gcc/../libcpp/include -I/opt/sw64/include  -I../../work/gcc/../libdecnumber -I../../work/gcc/../libdecnumber/dpd -I../libdecnumber  -I/opt/sw64/include -DCLOOG_PPL_BACKEND   -I/opt/sw64/include ../../work/gcc/fortran/module.c -o fortran/module.o
../../work/gcc/fortran/module.c: In function 'read_module':
../../work/gcc/fortran/module.c:4374:4: error: implicit declaration of function 'strndup' [-Werror=implicit-function-declaration]
../../work/gcc/fortran/module.c:4374:30: error: incompatible implicit declaration of built-in function 'strndup' [-Werror]
cc1: all warnings being treated as errors

make[3]: *** [fortran/module.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [all-stage2-gcc] Error 2
make[1]: *** [stage2-bubble] Error 2
make: *** [all] Error 2

TIA

Dominique

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [Patch, Fortran, OOP] PR 44912: Segmentation fault on TBP
@ 2010-07-31 11:45 Janus Weil
  0 siblings, 0 replies; 12+ messages in thread
From: Janus Weil @ 2010-07-31 11:45 UTC (permalink / raw)
  To: gfortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 958 bytes --]

Hi all,

this patch fixes a problem with type-bound procedure calls segfaulting
at runtime. It is fixed by making the vtabs & vtypes public inside a
module, plus making sure that they are imported upon module loading,
even with "use, only" clauses.

[The patch also contains one hunk which makes the '$vptr' component of
the class container private. This had been done for the '$data'
component already, but has been forgotten for '$vptr'. This is not
actually connected to this PR.]

The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk?

Cheers,
Janus



2010-07-31  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44912
	* class.c (gfc_build_class_symbol): Make '$vptr' component private.
	(gfc_find_derived_vtab): Make vtabs and vtypes public.
	* module.c (read_module): When reading module files, always import
	vtab and vtype symbols.

2010-07-31  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44912
	* gfortran.dg/typebound_call_17.f03: New.

[-- Attachment #2: pr44912.diff --]
[-- Type: application/octet-stream, Size: 1603 bytes --]

Index: gcc/fortran/class.c
===================================================================
--- gcc/fortran/class.c	(revision 162774)
+++ gcc/fortran/class.c	(working copy)
@@ -178,6 +178,7 @@ gfc_build_class_symbol (gfc_typespec *ts, symbol_a
 	  gcc_assert (vtab);
 	  c->ts.u.derived = vtab->ts.u.derived;
 	}
+      c->attr.access = ACCESS_PRIVATE;
       c->attr.pointer = 1;
     }
 
@@ -343,6 +344,7 @@ gfc_find_derived_vtab (gfc_symbol *derived)
 	  vtab->attr.target = 1;
 	  vtab->attr.save = SAVE_EXPLICIT;
 	  vtab->attr.vtab = 1;
+	  vtab->attr.access = ACCESS_PUBLIC;
 	  vtab->refs++;
 	  gfc_set_sym_referenced (vtab);
 	  sprintf (name, "vtype$%s", derived->name);
@@ -357,6 +359,7 @@ gfc_find_derived_vtab (gfc_symbol *derived)
 	      if (gfc_add_flavor (&vtype->attr, FL_DERIVED,
 				  NULL, &gfc_current_locus) == FAILURE)
 		goto cleanup;
+	      vtype->attr.access = ACCESS_PUBLIC;
 	      vtype->refs++;
 	      gfc_set_sym_referenced (vtype);
 
Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c	(revision 162774)
+++ gcc/fortran/module.c	(working copy)
@@ -4370,6 +4370,11 @@ read_module (void)
 	  if (p == NULL && strcmp (name, module_name) == 0)
 	    p = name;
 
+	  /* Exception: Always import vtabs & vtypes.  */
+	  if (p == NULL && (strcmp (strndup (name,5), "vtab$") == 0
+			    || strcmp (strndup (name,6), "vtype$") == 0))
+	    p = name;
+
 	  /* Skip symtree nodes not in an ONLY clause, unless there
 	     is an existing symtree loaded from another USE statement.  */
 	  if (p == NULL)

[-- Attachment #3: typebound_call_17.f03 --]
[-- Type: application/octet-stream, Size: 1196 bytes --]

! { dg-do run }
!
! PR 44912: [OOP] Segmentation fault on TBP
!
! Contributed by Satish.BD <bdsatish@gmail.com>

module polynomial
implicit none

private

type, public :: polynom
   complex, allocatable, dimension(:) :: a
   integer :: n
 contains
   procedure :: init_from_coeff
   procedure :: get_degree
   procedure :: add_poly
end type polynom

contains
  subroutine init_from_coeff(self, coeff)
    class(polynom), intent(inout) :: self
    complex, dimension(:), intent(in) :: coeff
    self%n = size(coeff) - 1
    allocate(self%a(self%n + 1))
    self%a = coeff
    print *,"ifc:",self%a
  end subroutine init_from_coeff

  function get_degree(self)   result(n)
    class(polynom), intent(in) :: self
    integer :: n
    print *,"gd"
    n = self%n
  end function get_degree

  subroutine add_poly(self)
    class(polynom), intent(in) :: self
    integer :: s
    print *,"ap"
    s = self%get_degree()         !!!! fails here
  end subroutine

end module polynomial

program test_poly
   use polynomial, only: polynom

   type(polynom) :: p1

   call p1%init_from_coeff([(1,0),(2,0),(3,0)])
   call p1%add_poly()

end program test_poly

! { dg-final { cleanup-modules "polynomial" } }

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-08-01 19:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-31 13:56 [Patch, Fortran, OOP] PR 44912: Segmentation fault on TBP Dominique Dhumieres
2010-07-31 14:19 ` Janus Weil
2010-07-31 14:21   ` Dominique Dhumieres
2010-07-31 14:28     ` Janus Weil
2010-07-31 14:46       ` Dominique Dhumieres
2010-07-31 16:55       ` Dominique Dhumieres
2010-08-01  9:44         ` Janus Weil
2010-08-01 14:13           ` Jerry DeLisle
2010-08-01 19:25             ` Janus Weil
2010-07-31 22:41       ` Dominique Dhumieres
2010-07-31 14:28   ` Dominique Dhumieres
  -- strict thread matches above, loose matches on Subject: below --
2010-07-31 11:45 Janus Weil

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).