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]

Re: [Patch, Fortran] PR20888 using NULL() pointer as operand


For those whose crystal ball is broken, I now attached the patch.

Tobias

Tobias Burnus schrieb:
> :ADDPATCH fortran:
>
> Reject the following invalid code:
>
>
>    IF (TEST .EQ. NULL(TEST)) TEST=>NULL() ! { dg-error "Invalid context
> for NULL
>      1
> Error: Invalid context for NULL() pointer at (1)
>   IF (NULL(TEST) .EQ. TEST) TEST=>NULL() ! { dg-error "Invalid context
> for NULL
>      1
> Error: Invalid context for NULL() pointer at (1)
>
>
> Any suggestions for a better error message?
>
> Ok for the trunk? Build & regression tested on x86_64-unknown-linux-gnu
> with no failures but PR32432.
>
> Tobias
>
>   

2007-06-22  Tobias Burnus  <burnus@net-b.de>

	PR fortran/20888
	* resolve.c (resolve_operator): Check for NULL as operand.

2007-06-22  Tobias Burnus  <burnus@net-b.de>

	PR fortran/20888
	* gfortran.dg/null_2.f90: New.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 125950)
+++ gcc/fortran/resolve.c	(working copy)
@@ -2128,6 +2128,13 @@ resolve_operator (gfc_expr *e)
   op2 = e->value.op.op2;
   dual_locus_error = false;
 
+  if ((op1 && op1->expr_type == EXPR_NULL)
+      || (op2 && op2->expr_type == EXPR_NULL))
+    {
+      sprintf (msg, _("Invalid context for NULL() pointer at %%L"));
+      goto bad_op;
+    }
+
   switch (e->value.op.operator)
     {
     case INTRINSIC_UPLUS:
Index: gcc/testsuite/gfortran.dg/null_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/null_2.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/null_2.f90	(revision 0)
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! NULL(...) pointer is not allowed as operand
+! PR fortran/20888
+!
+! Contributed by Joost VandeVondele
+!
+PROGRAM main
+  IMPLICIT NONE
+  REAL, POINTER :: TEST
+  NULLIFY(TEST)
+  TEST => -NULL(TEST) ! { dg-error "Invalid context for NULL" }
+  IF (TEST .EQ. NULL(TEST)) TEST=>NULL() ! { dg-error "Invalid context for NULL" }
+  IF (NULL(TEST) .EQ. TEST) TEST=>NULL() ! { dg-error "Invalid context for NULL" }
+END PROGRAM main

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