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]

[gfortran] Fix PR 15754: Make P = NULL() issue a warning


The statement
  P = NULL()
(as opposed to P => NULL()) will lead to a segfault if executed. There
seems to be no provision in the standard to forbid this, but a warning
is certainly in place. Fixed by the below patch. While I was working in
gfc_check_assign I spotted that the error message for differing ranks
could be enhanced to print out the ranks of the LHS and the RHS, and I
added this in turn.

Built and tested on i686-pc-linux. I will also add a testcase for the
new warning.

- Tobi

2004-07-11  Tobias Schlueter   <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/15754
	* expr.c (gfc_check_assign): Print ranks if incompatible. Issue
	warning if assigning NULL().

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/expr.c,v
retrieving revision 1.9
diff -u -p -r1.9 expr.c
--- expr.c      10 Jul 2004 12:45:33 -0000      1.9
+++ expr.c      11 Jul 2004 16:41:02 -0000
@@ -1736,7 +1736,8 @@ gfc_check_assign (gfc_expr * lvalue, gfc

   if (rvalue->rank != 0 && lvalue->rank != rvalue->rank)
     {
-      gfc_error ("Incompatible ranks in assignment at %L", &lvalue->where);
+      gfc_error ("Incompatible ranks %d and %d in assignment at %L",
+                lvalue->rank, rvalue->rank, &lvalue->where);
       return FAILURE;
     }

@@ -1747,6 +1748,10 @@ gfc_check_assign (gfc_expr * lvalue, gfc
       return FAILURE;
     }

+  if (rvalue->expr_type == EXPR_NULL)
+    gfc_warning ("NULL appears on right-hand side in assignment at %L",
+                &rvalue->where);
+
   /* Check size of array assignments.  */
   if (lvalue->rank != 0 && rvalue->rank != 0
       && gfc_check_conformance ("Array assignment", lvalue, rvalue) !=
SUCCESS)


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