]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/43362 (ICE with structure constuctor with DT component)
authorTobias Burnus <burnus@net-b.de>
Sun, 14 Mar 2010 13:18:28 +0000 (14:18 +0100)
committerTobias Burnus <burnus@gcc.gnu.org>
Sun, 14 Mar 2010 13:18:28 +0000 (14:18 +0100)
2010-03-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/43362
        * resolve.c (resolve_structure_cons): Add missing PURE
        * constraint.
        (resolve_ordinary_assign): Add check to avoid segfault.

2010-03-14  Tobias Burnus  <burnus@net-b.de>

        PR fortran/43362
        * gfortran.dg/impure_constructor_1.f90: New test.

From-SVN: r157447

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/impure_constructor_1.f90 [new file with mode: 0644]

index 9fd831dbd7c42235fb99b5e919002e5b143a7917..dd809d9c23d7909b638fc03e3099e145942c9cfe 100644 (file)
@@ -1,3 +1,9 @@
+2010-03-14  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/43362
+       * resolve.c (resolve_structure_cons): Add missing PURE constraint.
+       (resolve_ordinary_assign): Add check to avoid segfault.
+
 2010-03-12  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/43291
index 9a95d3405a08d1f7a8eb39295c7e635d7c0612b9..774dfe4f2ea466bb4ef8818f98db8ff5d86b8ee7 100644 (file)
@@ -921,6 +921,16 @@ resolve_structure_cons (gfc_expr *expr)
                     "for pointer component '%s' should be a POINTER or "
                     "a TARGET", &cons->expr->where, comp->name);
        }
+
+      /* F2003, C1272 (3).  */
+      if (gfc_pure (NULL) && cons->expr->expr_type == EXPR_VARIABLE
+         && gfc_impure_variable (cons->expr->symtree->n.sym))
+       {
+         t = FAILURE;
+         gfc_error ("Invalid expression in the derived type constructor for pointer "
+                    "component '%s' at %L in PURE procedure", comp->name,
+                    &cons->expr->where);
+       }
     }
 
   return t;
@@ -7947,6 +7957,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns)
       if (lhs->ts.type == BT_DERIVED
            && lhs->expr_type == EXPR_VARIABLE
            && lhs->ts.u.derived->attr.pointer_comp
+           && rhs->expr_type == EXPR_VARIABLE
            && gfc_impure_variable (rhs->symtree->n.sym))
        {
          gfc_error ("The impure variable at %L is assigned to "
index 336e2e39e78225dbad58ea020201453d3b433a5e..47a80da34ff110fa0c5498ad1688742b5dae6a0d 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-14  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/43362
+       * gfortran.dg/impure_constructor_1.f90: New test.
+
 2010-03-13  Sebastian Pop  <sebastian.pop@amd.com>
 
        PR middle-end/43354
diff --git a/gcc/testsuite/gfortran.dg/impure_constructor_1.f90 b/gcc/testsuite/gfortran.dg/impure_constructor_1.f90
new file mode 100644 (file)
index 0000000..6657213
--- /dev/null
@@ -0,0 +1,30 @@
+! { dg-do compile }
+!
+! PR fortran/43362
+!
+module m
+  implicit none
+  type t
+    integer, pointer :: a
+  end type t
+  type t2
+    type(t) :: b
+  end type t2
+  type t3
+    type(t), pointer :: b
+  end type t3
+contains
+ pure subroutine foo(x)
+   type(t), target, intent(in) :: x
+   type(t2) :: y
+   type(t3) :: z
+
+   ! The following gave an ICE but is valid:
+   y = t2(x) ! Note: F2003, C1272 (3) and (4) do not apply
+   
+   ! Variant which is invalid as C1272 (3) applies
+   z = t3(x) ! { dg-error "Invalid expression in the derived type constructor" }
+ end subroutine foo
+end module m
+
+