[PATCH,fortran]: fix for PR 33760
Christopher D. Rickett
crickett@lanl.gov
Mon Oct 15 21:31:00 GMT 2007
hi all,
the attached patch should fix the ICE illustrated by PR 33760.
bootstrapped and regtested on x86 linux with no new failures.
thanks.
Chris
:ADDPATCH fortran:
ChangeLog entry:
2007-10-15 Christopher D. Rickett <crickett@lanl.gov>
PR fortran/33760
* symbol.c (gen_special_c_interop_ptr): Remove code to create
constructor for c_null_ptr and c_null_funptr with value of 0.
* expr.c (check_init_expr): Prevent check on constructors for
iso_c_binding derived types.
* resolve.c (resolve_structure_cons): Verify that the user isn't
trying to invoke a structure constructor for one of the
iso_c_binding derived types.
2007-10-15 Christopher D. Rickett <crickett@lanl.gov>
PR fortran/33760
* gfortran.dg/c_ptr_tests_13.f03: New test case.
-------------- next part --------------
Index: gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03
===================================================================
--- gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03 (revision 0)
+++ gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03 (revision 0)
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! Ensure that the user cannot call the structure constructor for one of
+! the iso_c_binding derived types.
+program main
+ use ISO_C_BINDING
+ implicit none
+ integer(C_INTPTR_T) p
+ type(C_PTR) cptr
+ p = 0
+ cptr = C_PTR(p+1) ! { dg-error "Components of structure constructor" }
+ cptr = C_PTR(1) ! { dg-error "Components of structure constructor" }
+end program main
Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c (revision 129366)
+++ gcc/fortran/symbol.c (working copy)
@@ -3354,10 +3354,10 @@ gen_special_c_interop_ptr (int ptr_id, c
tmp_sym->value->expr_type = EXPR_STRUCTURE;
tmp_sym->value->ts.type = BT_DERIVED;
tmp_sym->value->ts.derived = tmp_sym->ts.derived;
+ /* Create a constructor with no expr, that way we can recognize if the user
+ tries to call the structure constructor for one of the iso_c_binding
+ derived types during resolution (resolve_structure_cons). */
tmp_sym->value->value.constructor = gfc_get_constructor ();
- /* This line will initialize the c_null_ptr/c_null_funptr
- c_address field to NULL. */
- tmp_sym->value->value.constructor->expr = gfc_int_expr (0);
/* Must declare c_null_ptr and c_null_funptr as having the
PARAMETER attribute so they can be used in init expressions. */
tmp_sym->attr.flavor = FL_PARAMETER;
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c (revision 129366)
+++ gcc/fortran/expr.c (working copy)
@@ -2249,7 +2249,10 @@ check_init_expr (gfc_expr *e)
break;
case EXPR_STRUCTURE:
- t = gfc_check_constructor (e, check_init_expr);
+ if (e->ts.is_iso_c)
+ t = SUCCESS;
+ else
+ t = gfc_check_constructor (e, check_init_expr);
break;
case EXPR_ARRAY:
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 129366)
+++ gcc/fortran/resolve.c (working copy)
@@ -728,6 +728,16 @@ resolve_structure_cons (gfc_expr *expr)
else
comp = expr->ts.derived->components;
+ /* See if the user is trying to invoke a structure constructor for one of
+ the iso_c_binding derived types. */
+ if (expr->ts.derived && expr->ts.derived->ts.is_iso_c && cons
+ && cons->expr != NULL)
+ {
+ gfc_error ("Components of structure constructor '%s' at %L are PRIVATE",
+ expr->ts.derived->name, &(expr->where));
+ return FAILURE;
+ }
+
for (; comp; comp = comp->next, cons = cons->next)
{
if (!cons->expr)
More information about the Fortran
mailing list