]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/33760 (Bind(C): Using C_PTR as structure constructor gives an ICE)
authorChristopher D. Rickett <crickett@lanl.gov>
Wed, 17 Oct 2007 06:57:06 +0000 (06:57 +0000)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 17 Oct 2007 06:57:06 +0000 (08:57 +0200)
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-17 Christopher D. Rickett <crickett@lanl.gov>

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

From-SVN: r129402

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 d9885ae7dd0be5cb87acadeb95f251245b674d92..7b05fb53eebdbb8bc8dd85e33e6cef5a83282e24 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 447263a263516a71c320346673ebd8ba2bee337b..2edf7ad322f1033abf86e7542042bcfcd6862e30 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 65e479fe65fe53249fa7391a0ac5e181dd913df4..f16fe281772b085c7153a296e1b374f493691ea2 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 ae97a656759435b5e7af886af9c6d8c06910fbb8..b0c2825a76dd9d844eb15da67dd765eee1d9c8f4 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 35adc95c321f937a166f18955516b4ae22eef8fa..32e22f2d561ef87e033330b99ff7720054e64534 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