This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] More type-safety issues was
Tobias Schlüter wrote:
> There remains a type-safety issue which is that
> I = NULL()
> where I is _not_ a pointer will not compile without the call to fold_const.
> Actually, this statement doesn't give the expected segfault because the result
> from NULL() isn't dereferenced. While it would be easy to introduce the
> dereference, and while I couldn't convince myself that this is illegal, I'd
> vote for removing this, as I also couldn't convince myself that this is legal.
> The table in 7.1.4.1 of the draft F95 standard seems to indicate quite
> strongly that this is not allowed. I'd vote for removing this 'feature'
> (which was introduced as resolution to PR 15754 BTW).
Here's the patch that does just that and removes the call to fold_convert,
bubblestrapped and tested with no regressions.
- Tobi
2004-03-05 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/15754
fortran/
* expr.c (gfc_check_assign): Give error instead of warning for
non-pointer-assignment of NULL().
* trans-expr.c (gfc_trans_scalar_assign): Don't fold_convert
the RHS to the type of the LHS.
testsuite/
* gfortran.dg/pr15754.f90: Update annotations.
Index: fortran/expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/expr.c,v
retrieving revision 1.24
diff -u -p -r1.24 expr.c
--- fortran/expr.c 4 Mar 2005 17:09:18 -0000 1.24
+++ fortran/expr.c 5 Mar 2005 21:32:08 -0000
@@ -1789,11 +1789,12 @@ gfc_check_assign (gfc_expr * lvalue, gfc
return FAILURE;
}
- /* This is a guaranteed segfault and possibly a typo: p = NULL()
- instead of p => NULL() */
if (rvalue->expr_type == EXPR_NULL)
- gfc_warning ("NULL appears on right-hand side in assignment at %L",
+ {
+ gfc_error ("NULL appears on right-hand side in assignment at %L",
&rvalue->where);
+ return FAILURE;
+ }
/* This is possibly a typo: x = f() instead of x => f() */
if (gfc_option.warn_surprising
Index: fortran/trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.39
diff -u -p -r1.39 trans-expr.c
--- fortran/trans-expr.c 4 Mar 2005 21:03:29 -0000 1.39
+++ fortran/trans-expr.c 5 Mar 2005 21:32:09 -0000
@@ -2018,8 +2018,7 @@ gfc_trans_scalar_assign (gfc_se * lse, g
gfc_add_block_to_block (&block, &lse->pre);
gfc_add_block_to_block (&block, &rse->pre);
- gfc_add_modify_expr (&block, lse->expr,
- fold_convert (TREE_TYPE (lse->expr), rse->expr));
+ gfc_add_modify_expr (&block, lse->expr, rse->expr);
}
gfc_add_block_to_block (&block, &lse->post);
Index: testsuite/gfortran.dg/pr15754.f90
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gfortran.dg/pr15754.f90,v
retrieving revision 1.1
diff -u -p -r1.1 pr15754.f90
--- testsuite/gfortran.dg/pr15754.f90 11 Jul 2004 16:58:48 -0000 1.1
+++ testsuite/gfortran.dg/pr15754.f90 5 Mar 2005 21:45:53 -0000
@@ -1,7 +1,7 @@
! we didn't give a warning if the RHS of an assignment was NULL
! { dg-do-compile }
INTEGER, POINTER :: P
-I = NULL() ! { dg-warning "NULL appears" "Assignment non-pointer = NULL" }
-P = NULL() ! { dg-warning "NULL appears" "Assignment pointer = NULL" }
+I = NULL() ! { dg-error "NULL appears" "Assignment non-pointer = NULL" }
+P = NULL() ! { dg-error "NULL appears" "Assignment pointer = NULL" }
P => NULL()
END