This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR33664 - crash on invalid program


:ADDPATCH fortran:

This is a little embarrassing.  The testcase tells all - the symbol n
is interpreted to be an error.  Hozever, being referenced in a
specification expression, it should be pure, which it is not.  The fix
is self-explanatory - note the test for purity is redundant but
provides a belt and braces approach.  char_result_7.f90 was exposed by
this patch to have an illegal part, where the character langth was
determined by an impure function.  This has been eliminated.

Bootstrapped and regtested on x86_ia64/fc5 and certified tonto-2.3
proof.  OK for trunk?

Paul

2007-10-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33664
	* expr.c (gfc_specification_expr): If a function is not
	external, intrinsic or pure is an error.  Set the symbol pure
	to prevent repeat errors.

2007-10-07  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/33664
	* gfortran.dg/impure_spec_expr_1.f90: New test.
	* gfortran.dg/char_result_7.f90: Remove illegal test.



-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy
Index: /svn/trunk/gcc/fortran/expr.c
===================================================================
*** /svn/trunk/gcc/fortran/expr.c	(revision 129068)
--- /svn/trunk/gcc/fortran/expr.c	(working copy)
*************** gfc_specification_expr (gfc_expr *e)
*** 2513,2518 ****
--- 2513,2530 ----
        return FAILURE;
      }
  
+   if (e->expr_type == EXPR_FUNCTION
+ 	  && !e->value.function.isym
+ 	  && !e->value.function.esym
+ 	  && !gfc_pure (e->symtree->n.sym))
+     {
+       gfc_error ("Function '%s' at %L must be PURE",
+ 		 e->symtree->n.sym->name, &e->where);
+       /* Prevent repeat error messages.  */
+       e->symtree->n.sym->attr.pure = 1;
+       return FAILURE;
+     }
+ 
    if (e->rank != 0)
      {
        gfc_error ("Expression at %L must be scalar", &e->where);
Index: /svn/trunk/gcc/testsuite/gfortran.dg/impure_spec_expr_1.f90
===================================================================
*** /svn/trunk/gcc/testsuite/gfortran.dg/impure_spec_expr_1.f90	(revision 0)
--- /svn/trunk/gcc/testsuite/gfortran.dg/impure_spec_expr_1.f90	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ ! { dg-do compile }
+ ! Checks the fix for PR33664, in which the apparent function reference
+ ! n(1) caused a seg-fault.
+ !
+ ! Contributed by Henrik Holst <holst@matmech.com>
+ !
+ module test
+ contains
+   subroutine func_1(u,n)
+     integer :: n
+     integer :: u(n(1))  ! { dg-error "must be PURE" }
+   end subroutine
+ end module test
+ ! { dg-final { cleanup-modules "test" } }
+ 
Index: /svn/trunk/gcc/testsuite/gfortran.dg/char_result_7.f90
===================================================================
*** /svn/trunk/gcc/testsuite/gfortran.dg/char_result_7.f90	(revision 129068)
--- /svn/trunk/gcc/testsuite/gfortran.dg/char_result_7.f90	(working copy)
*************** program main
*** 16,22 ****
    end interface
  
    call test (f1 (double, 100), 200)
-   call test (f2 (double, 70), 140)
  
    call indirect (double)
  contains
--- 16,21 ----
*************** contains
*** 31,42 ****
      f1 = ''
    end function f1
  
-   function f2 (fn, i)
-     integer :: i, fn
-     character (len = fn (i)) :: f2
-     f2 = ''
-   end function f2
- 
    subroutine indirect (fn)
      interface
        integer pure function fn (x)
--- 30,35 ----
*************** contains
*** 44,50 ****
        end function fn
      end interface
      call test (f1 (fn, 100), 200)
-     call test (f2 (fn, 70), 140)
    end subroutine indirect
  
    subroutine test (string, length)
--- 37,42 ----

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]