2007-10-17 Christopher D. Rickett <crickett@lanl.gov>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Oct 2007 06:57:06 +0000 (06:57 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Oct 2007 06:57:06 +0000 (06:57 +0000)
        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-17 Christopher D. Rickett <crickett@lanl.gov>

        PR fortran/33760
        * gfortran.dg/c_ptr_tests_13.f03: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@129402 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/fortran/resolve.c
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03 [new file with mode: 0644]

index d9885ae..7b05fb5 100644 (file)
@@ -1,3 +1,14 @@
+2007-10-17 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/32600
index 447263a..2edf7ad 100644 (file)
@@ -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 65e479f..f16fe28 100644 (file)
@@ -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)
index ae97a65..b0c2825 100644 (file)
@@ -3354,10 +3354,10 @@ gen_special_c_interop_ptr (int ptr_id, const char *ptr_name,
   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 35adc95..32e22f2 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-17  Christopher D. Rickett <crickett@lanl.gov>
+
+       PR fortran/33760
+       * gfortran.dg/c_ptr_tests_13.f03: New test case.
+
 2007-10-16  Paolo Carlini  <pcarlini@suse.de>
 
        PR c++/28639
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03 b/gcc/testsuite/gfortran.dg/c_ptr_tests_13.f03
new file mode 100644 (file)
index 0000000..c7a603b
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! Ensure that the user cannot call the structure constructor for one of 
+! the iso_c_binding derived types.
+!
+! PR fortran/33760
+!
+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