* [Patch, Fortran] PR 43362 - PURE contraint - fix ICE, add missing check
@ 2010-03-14 13:14 Tobias Burnus
2010-03-14 13:33 ` Jerry DeLisle
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2010-03-14 13:14 UTC (permalink / raw)
To: gfortran, gcc patches
[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]
Found when adding the equivalent check for coarrays. There are two
issues, one NULL pointer access for a valid case (item (4) does not
apply) as accessing "rhs->symtree->n.sym" causes a segfault if RHS is
not an EXPR_VARIABLE but, e.g., a structure constructor.
The other issue is that gfortran did not have a check for constraint (3).
Quoting Fortran 2003:
"C1272 In a pure subprogram any designator with a base object that is in
common or accessed by host or use association, is a dummy argument of a
pure function, is a dummy argument with INTENT (IN) of a pure
subroutine, or an object that is storage associated with any such
variable, shall not be used in the following contexts:
[...]
(3) As the expr corresponding to a component with the POINTER attribute
in a structure constructor.
(4) As the expr of an intrinsic assignment statement in which the
variable is of a derived type if the derived type has a pointer
component at any level of component selection; [...]"
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
[-- Attachment #2: impure.diff --]
[-- Type: text/x-patch, Size: 2285 bytes --]
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.
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (Revision 157445)
+++ gcc/fortran/resolve.c (Arbeitskopie)
@@ -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,
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: gcc/testsuite/gfortran.dg/impure_constructor_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/impure_constructor_1.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/impure_constructor_1.f90 (Revision 0)
@@ -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
+
+
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR 43362 - PURE contraint - fix ICE, add missing check
2010-03-14 13:14 [Patch, Fortran] PR 43362 - PURE contraint - fix ICE, add missing check Tobias Burnus
@ 2010-03-14 13:33 ` Jerry DeLisle
0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2010-03-14 13:33 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gfortran, gcc patches
Tobias Burnus wrote:
> Found when adding the equivalent check for coarrays. There are two
> issues, one NULL pointer access for a valid case (item (4) does not
> apply) as accessing "rhs->symtree->n.sym" causes a segfault if RHS is
> not an EXPR_VARIABLE but, e.g., a structure constructor.
>
> The other issue is that gfortran did not have a check for constraint (3).
>
> Quoting Fortran 2003:
>
> "C1272 In a pure subprogram any designator with a base object that is in
> common or accessed by host or use association, is a dummy argument of a
> pure function, is a dummy argument with INTENT (IN) of a pure
> subroutine, or an object that is storage associated with any such
> variable, shall not be used in the following contexts:
> [...]
> (3) As the expr corresponding to a component with the POINTER attribute
> in a structure constructor.
> (4) As the expr of an intrinsic assignment statement in which the
> variable is of a derived type if the derived type has a pointer
> component at any level of component selection; [...]"
>
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
> Tobias
>
OK, thanks
Jerry
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-14 13:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-14 13:14 [Patch, Fortran] PR 43362 - PURE contraint - fix ICE, add missing check Tobias Burnus
2010-03-14 13:33 ` Jerry DeLisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).