[PATCH, committed] PR fortran/101349 - ICE in gfc_get_descriptor_field, at fortran/trans-array.c:140
The check of arguments to ALLOCATE did not properly implement F2008:C628 / F2018:C932, as it excluded unlimited polymophics, in contrast to the standard text. Fix this. Committed Steve's patch as obvious after regtesting on x86_64-pc-linux-gnu. Thanks, Harald Fortran - correct check for constraint F2008:C628 / F2018:C932 gcc/fortran/ChangeLog: PR fortran/101349 * resolve.c (resolve_allocate_expr): An unlimited polymorphic argument to ALLOCATE must be ALLOCATABLE or a POINTER. Fix the corresponding check. gcc/testsuite/ChangeLog: PR fortran/101349 * gfortran.dg/unlimited_polymorphic_33.f90: New test. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index f641d0d4dae..d7aa2868cef 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -7829,8 +7829,9 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec) } } - /* Check for F08:C628. */ - if (allocatable == 0 && pointer == 0 && !unlimited) + /* Check for F08:C628 (F2018:C932). Each allocate-object shall be a data + pointer or an allocatable variable. */ + if (allocatable == 0 && pointer == 0) { gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER", &e->where); diff --git a/gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90 b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90 new file mode 100644 index 000..8bb8864cb26 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90 @@ -0,0 +1,18 @@ +! { dg-do compile } +! PR fortran/101349 - ICE in gfc_get_descriptor_field +! Check constraint F2008:C628 / F2018:C932 + +subroutine s(x) + class(*) :: x(:) + allocate (x, source=['abc']) ! { dg-error "must be ALLOCATABLE or a POINTER" } +end + +subroutine t(x) + class(*), allocatable :: x(:) + allocate (x, source=['abc']) +end + +subroutine u(x) + class(*), pointer :: x(:) + allocate (x, source=['abc']) +end
[PATCH, committed] PR fortran/102113 - parsing error in assigned goto
A whitespace issue during parsing. Committed Steve's patch as obvious after regtesting on x86_64-pc-linux-gnu. Thanks, Harald Fortran - fix whitespace issue during parsing of assigned goto gcc/fortran/ChangeLog: PR fortran/102113 * match.c (gfc_match_goto): Allow for whitespace in parsing list of labels. gcc/testsuite/ChangeLog: PR fortran/102113 * gfortran.dg/goto_9.f90: New test.
[PATCH] PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355
There was an issue when trying to use an element from an array constructor which was a broken in a way probably only Gerhard could conceive. We hit an assert that can be replaced by more robust code. Patch is basically Steve's. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald Fortran - improve error recovery determining array element from constructor gcc/fortran/ChangeLog: PR fortran/101327 * expr.c (find_array_element): When bounds cannot be determined as constant, return error instead of aborting. gcc/testsuite/ChangeLog: PR fortran/101327 * gfortran.dg/pr101327.f90: New test. diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 35563a78697..dfecc3012e1 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1337,7 +1337,9 @@ find_array_element (gfc_constructor_base base, gfc_array_ref *ar, for (i = 0; i < ar->dimen; i++) { if (!gfc_reduce_init_expr (ar->as->lower[i]) - || !gfc_reduce_init_expr (ar->as->upper[i])) + || !gfc_reduce_init_expr (ar->as->upper[i]) + || ar->as->upper[i]->expr_type != EXPR_CONSTANT + || ar->as->lower[i]->expr_type != EXPR_CONSTANT) { t = false; cons = NULL; @@ -1351,9 +1353,6 @@ find_array_element (gfc_constructor_base base, gfc_array_ref *ar, goto depart; } - gcc_assert (ar->as->upper[i]->expr_type == EXPR_CONSTANT - && ar->as->lower[i]->expr_type == EXPR_CONSTANT); - /* Check the bounds. */ if ((ar->as->upper[i] && mpz_cmp (e->value.integer, diff --git a/gcc/testsuite/gfortran.dg/pr101327.f90 b/gcc/testsuite/gfortran.dg/pr101327.f90 new file mode 100644 index 000..f4377aabe7a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr101327.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355 + +subroutine s + integer, parameter :: n([2]) = [1, 2] ! { dg-error "must be scalar" } + type t + integer :: a(n(1):n(2)) + end type +end + +! { dg-error "cannot be automatic or of deferred shape" " " { target *-*-* } 5 }
Re: *PING**2 – Re: [Patch] Fortran: Fix Bind(C) char-len check, add ptr-contiguous check
Hi Tobias, s/However, as argument they are also iteroperable/However, as an argument they are also interoperable/ s/ /* else: valid only sind F2018 - and an assumed-shape/rank array; however, gfc_notify_std is already called when those array type are used. Thus, silently accept F200x. */ / /* else: valid only since F2018 - and an assumed-shape/rank array; however, gfc_notify_std is already called when those array types are used. Thus, silently accept F200x. */ Apart from those nits, it looks good to me. It even regtests OK :-) Thanks for sorting out the standard-ese. OK for mainline and, I would suggest 11-branch. Cheers Paul On Sun, 29 Aug 2021 at 08:35, Tobias Burnus wrote: > PING**2 > > On 25.08.21 20:58, Tobias Burnus wrote: > > Early *PING*. > > (I also should still review several Fortan patches... There are lots of > > patches waiting for review :-/) > > > > On 20.08.21 19:24, Tobias Burnus wrote: > >> The following is about interoperability (BIND(C)) only. > >> > >> > >> * The patch adds a missing check for pointer + contiguous. > >> (Rejected to avoid copy-in issues? Or checking issues?) > >> > >> > >> * And it corrects an issue regarding len > 1 characters. While > >> > >> subroutine foo(x) > >> character(len=2) :: x(*) > >> > >> is valid Fortran code (the argument can be "abce" or ['a','b','c','d'] > >> or ...) > >> – and would work also with bind(C) as the len=2 does not need to be > >> passed > >> as hidden argument as len is a constant. > >> However, it is not valid nonetheless. > >> > >> > >> OK? Comments? > >> > >> Tobias > >> > >> > >> PS: Referenced locations in the standard (F2018): > >> > >> C1554 If proc-language-binding-spec is specified for a procedure, > >> each of its dummy arguments shall be an interoperable procedure (18.3.6) > >> or a variable that is interoperable (18.3.4, 18.3.5), assumed-shape, > >> assumed-rank, assumed-type, of type CHARACTER with assumed length, > >> or that has the ALLOCATABLE or POINTER attribute. > >> > >> 18.3.1: "... If the type is character, the length type parameter is > >> interoperable if and only if its value is one. ..." > >> > >> "18.3.4 Interoperability of scalar variables": > >> "... A named scalar Fortran variable is interoperable ... if it > >> is of type character12its length is not assumed or declared by > >> an expression that is not a constant expression." > >> > >> 18.3.5: Likewise but for arrays. > >> > >> 18.3.6 "... Fortran procedure interface is interoperable with a C > >> function prototype ..." > >> "(5) any dummy argument without the VALUE attribute corresponds > >> to a formal parameter of the prototype that is of a pointer type, > >> and either > >> • the dummy argument is interoperable with an entity of the > >> referenced type ..." > >> (Remark: those are passed as byte stream) > >> "• the dummy argument is a nonallocatable nonpointer variable of > >> type > >> CHARACTER with assumed character length and the formal > >> parameter is > >> a pointer to CFI_cdesc_t, > >> • the dummy argument is allocatable, assumed-shape, > >> assumed-rank, or > >> a pointer without the CONTIGUOUS attribute, and the formal > >> parameter > >> is a pointer to CFI_cdesc_t, or > >> (Remark: those two use an array descriptor, also for > >> explicit-size/assumed-size > >> arrays or for scalars.) > >> • the dummy argument is assumed-type ..." > >> > > - > > Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße > > 201, 80634 München; Gesellschaft mit beschränkter Haftung; > > Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: > > München; Registergericht München, HRB 106955 > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein