Commit def66134 by Steven G. Kargl Committed by Steven G. Kargl

re PR fortran/20858 (NULL doesn't get its argument type (kind))

2006-02-05  Steven G. Kargl  <kargls@comcast.net>

PR fortran/20858
*decl.c (variable_decl): Improve error message.  Remove initialization
 typespec.  Wrap long line.
*expr.c (gfc_check_pointer_assign): Permit checking of type, kind type,
 and rank.
*simplify.c (gfc_simplify_null): Ensure type, kind type, and rank are set.

gfortran.dg/null_1.f90: New test.

From-SVN: r110845
parent 6f4d3d86
2006-02-10 Steven G. Kargl <kargls@comcast.net>
PR fortran/20858
*decl.c (variable_decl): Improve error message. Remove initialization
typespec. Wrap long line.
*expr.c (gfc_check_pointer_assign): Permit checking of type, kind type,
and rank.
*simplify.c (gfc_simplify_null): Ensure type, kind type, and rank
are set.
2006-02-10 Tobias Schlter <tobias.schlueter@physik.uni-muenchen.de> 2006-02-10 Tobias Schlter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/14771 PR fortran/14771
......
...@@ -1203,7 +1203,7 @@ variable_decl (int elem) ...@@ -1203,7 +1203,7 @@ variable_decl (int elem)
m = gfc_match_null (&initializer); m = gfc_match_null (&initializer);
if (m == MATCH_NO) if (m == MATCH_NO)
{ {
gfc_error ("Pointer initialization requires a NULL at %C"); gfc_error ("Pointer initialization requires a NULL() at %C");
m = MATCH_ERROR; m = MATCH_ERROR;
} }
...@@ -1218,8 +1218,6 @@ variable_decl (int elem) ...@@ -1218,8 +1218,6 @@ variable_decl (int elem)
if (m != MATCH_YES) if (m != MATCH_YES)
goto cleanup; goto cleanup;
initializer->ts = current_ts;
} }
else if (gfc_match_char ('=') == MATCH_YES) else if (gfc_match_char ('=') == MATCH_YES)
{ {
...@@ -1282,7 +1280,8 @@ variable_decl (int elem) ...@@ -1282,7 +1280,8 @@ variable_decl (int elem)
t = add_init_expr_to_sym (name, &initializer, &var_locus); t = add_init_expr_to_sym (name, &initializer, &var_locus);
else else
{ {
if (current_ts.type == BT_DERIVED && !current_attr.pointer && !initializer) if (current_ts.type == BT_DERIVED && !current_attr.pointer
&& !initializer)
initializer = gfc_default_initializer (&current_ts); initializer = gfc_default_initializer (&current_ts);
t = build_struct (name, cl, &initializer, &as); t = build_struct (name, cl, &initializer, &as);
} }
......
...@@ -1984,7 +1984,7 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue) ...@@ -1984,7 +1984,7 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
/* If rvalue is a NULL() or NULLIFY, we're done. Otherwise the type, /* If rvalue is a NULL() or NULLIFY, we're done. Otherwise the type,
kind, etc for lvalue and rvalue must match, and rvalue must be a kind, etc for lvalue and rvalue must match, and rvalue must be a
pure variable if we're in a pure function. */ pure variable if we're in a pure function. */
if (rvalue->expr_type == EXPR_NULL) if (rvalue->expr_type == EXPR_NULL && rvalue->ts.type == BT_UNKNOWN)
return SUCCESS; return SUCCESS;
if (!gfc_compare_types (&lvalue->ts, &rvalue->ts)) if (!gfc_compare_types (&lvalue->ts, &rvalue->ts))
...@@ -2001,6 +2001,17 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue) ...@@ -2001,6 +2001,17 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
return FAILURE; return FAILURE;
} }
if (lvalue->rank != rvalue->rank)
{
gfc_error ("Different ranks in pointer assignment at %L",
&lvalue->where);
return FAILURE;
}
/* Now punt if we are dealing with a NULLIFY(X) or X = NULL(X). */
if (rvalue->expr_type == EXPR_NULL)
return SUCCESS;
if (lvalue->ts.type == BT_CHARACTER if (lvalue->ts.type == BT_CHARACTER
&& lvalue->ts.cl->length && rvalue->ts.cl->length && lvalue->ts.cl->length && rvalue->ts.cl->length
&& abs (gfc_dep_compare_expr (lvalue->ts.cl->length, && abs (gfc_dep_compare_expr (lvalue->ts.cl->length,
...@@ -2025,13 +2036,6 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue) ...@@ -2025,13 +2036,6 @@ gfc_check_pointer_assign (gfc_expr * lvalue, gfc_expr * rvalue)
"procedure at %L", &rvalue->where); "procedure at %L", &rvalue->where);
} }
if (lvalue->rank != rvalue->rank)
{
gfc_error ("Unequal ranks %d and %d in pointer assignment at %L",
lvalue->rank, rvalue->rank, &rvalue->where);
return FAILURE;
}
if (gfc_has_vector_index (rvalue)) if (gfc_has_vector_index (rvalue))
{ {
gfc_error ("Pointer assignment with vector subscript " gfc_error ("Pointer assignment with vector subscript "
......
...@@ -2528,16 +2528,14 @@ gfc_simplify_null (gfc_expr * mold) ...@@ -2528,16 +2528,14 @@ gfc_simplify_null (gfc_expr * mold)
{ {
gfc_expr *result; gfc_expr *result;
result = gfc_get_expr ();
result->expr_type = EXPR_NULL;
if (mold == NULL) if (mold == NULL)
result->ts.type = BT_UNKNOWN;
else
{ {
result->ts = mold->ts; result = gfc_get_expr ();
result->where = mold->where; result->ts.type = BT_UNKNOWN;
} }
else
result = gfc_copy_expr (mold);
result->expr_type = EXPR_NULL;
return result; return result;
} }
......
2006-02-10 Steven G. Kargl <kargls@comcast.net>
gfortran.dg/null_1.f90: New test.
2006-02-10 Tobias Schlter <tobias.schlueter@physik.uni-muenchen.de> 2006-02-10 Tobias Schlter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/14771 PR fortran/14771
! { dg-do compile }
! PR fortran/20858
! If we have "x = null(i)", then "null()" acquires the type, kind type,
! and rank of i and these need to match those of x.
program null_1
integer, parameter :: sp = kind(1.e0), dp = kind(1.d0)
integer, pointer :: i => null()
real(sp), pointer :: x => null()
real(dp), pointer :: y => null()
real(sp), pointer :: z(:) => null()
x => null(i) ! { dg-error "types in pointer assignment" }
x => null(y) ! { dg-error "types in pointer assignment" }
z => null(i) ! { dg-error "types in pointer assignment" }
z => null(y) ! { dg-error "types in pointer assignment" }
x => null(z) ! { dg-error "ranks in pointer assignment" }
z => null(x) ! { dg-error "ranks in pointer assignment" }
z => null(z)
nullify(i, x, y, z)
end program null_1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment