[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-11 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

Paul Thomas  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #10 from Paul Thomas  ---
Fixed on trunk and 9-branch.

Thanks for the report

Paul

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-11 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #9 from Paul Thomas  ---
Author: pault
Date: Sat May 11 07:49:52 2019
New Revision: 271090

URL: https://gcc.gnu.org/viewcvs?rev=271090=gcc=rev
Log:
2019-05-11  Paul Thomas  

PR fortran/90093
* gfortran.dg/ISO_Fortran_binding_12.f90: New test.
* gfortran.dg/ISO_Fortran_binding_12.c: Supplementary code.

PR fortran/90352
* gfortran.dg/iso_c_binding_char_1.f90: New test.

PR fortran/90355
* gfortran.dg/ISO_Fortran_binding_4.f90: Add 'substr' to test
the direct passing of substrings as descriptors to bind(C).
* gfortran.dg/assign_10.f90: Increase the tree_dump count of
'atmp' to account for the setting of the 'span' field.
* gfortran.dg/transpose_optimization_2.f90: Ditto.

Added:
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.f90
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/iso_c_binding_char_1.f90

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-11 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #8 from Paul Thomas  ---
Author: pault
Date: Sat May 11 07:47:32 2019
New Revision: 271089

URL: https://gcc.gnu.org/viewcvs?rev=271089=gcc=rev
Log:
2019-05-11  Paul Thomas  

PR fortran/90093
* trans-decl.c (convert_CFI_desc): Test that the dummy is
present before doing any of the conversions.

PR fortran/90352
* decl.c (gfc_verify_c_interop_param): Restore the error for
charlen > 1 actual arguments passed to bind(C) procs.
Clean up trailing white space.

PR fortran/90355
* trans-array.c (gfc_trans_create_temp_array): Set the 'span'
field to the element length for all types.
(gfc_conv_expr_descriptor): The force_no_tmp flag is used to
prevent temporary creation, especially for substrings.
* trans-decl.c (gfc_trans_deferred_vars): Rather than assert
that the backend decl for the string length is non-null, use it
as a condition before calling gfc_trans_vla_type_sizes.
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): 'force_no_tmp'
is set before calling gfc_conv_expr_descriptor.
* trans.c (get_array_span): Move the code for extracting 'span'
from gfc_build_array_ref to this function. This is specific to
descriptors that are component and indirect references.
* trans.h : Add the force_no_tmp flag bitfield to gfc_se.

2019-05-11  Paul Thomas  

PR fortran/90093
* gfortran.dg/ISO_Fortran_binding_12.f90: New test.
* gfortran.dg/ISO_Fortran_binding_12.c: Supplementary code.

PR fortran/90352
* gfortran.dg/iso_c_binding_char_1.f90: New test.

PR fortran/90355
* gfortran.dg/ISO_Fortran_binding_4.f90: Add 'substr' to test
the direct passing of substrings as descriptors to bind(C).
* gfortran.dg/assign_10.f90: Increase the tree_dump count of
'atmp' to account for the setting of the 'span' field.
* gfortran.dg/transpose_optimization_2.f90: Ditto.

Modified:
branches/gcc-9-branch/gcc/fortran/ChangeLog
branches/gcc-9-branch/gcc/fortran/decl.c
branches/gcc-9-branch/gcc/fortran/trans-array.c
branches/gcc-9-branch/gcc/fortran/trans-decl.c
branches/gcc-9-branch/gcc/fortran/trans-expr.c
branches/gcc-9-branch/gcc/fortran/trans.c
branches/gcc-9-branch/gcc/fortran/trans.h
branches/gcc-9-branch/gcc/testsuite/ChangeLog
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_4.f90
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/assign_10.f90
   
branches/gcc-9-branch/gcc/testsuite/gfortran.dg/transpose_optimization_2.f90

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-10 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #7 from Paul Thomas  ---
Author: pault
Date: Fri May 10 07:59:42 2019
New Revision: 271057

URL: https://gcc.gnu.org/viewcvs?rev=271057=gcc=rev
Log:
2019-05-10  Paul Thomas  

PR fortran/90093
* trans-decl.c (convert_CFI_desc): Test that the dummy is
present before doing any of the conversions.

PR fortran/90352
* decl.c (gfc_verify_c_interop_param): Restore the error for
charlen > 1 actual arguments passed to bind(C) procs.
Clean up trailing white space.

PR fortran/90355
* trans-array.c (gfc_trans_create_temp_array): Set the 'span'
field to the element length for all types.
(gfc_conv_expr_descriptor): The force_no_tmp flag is used to
prevent temporary creation, especially for substrings.
* trans-decl.c (gfc_trans_deferred_vars): Rather than assert
that the backend decl for the string length is non-null, use it
as a condition before calling gfc_trans_vla_type_sizes.
* trans-expr.c (gfc_conv_gfc_desc_to_cfi_desc): 'force_no_tmp'
is set before calling gfc_conv_expr_descriptor.
* trans.c (get_array_span): Move the code for extracting 'span'
from gfc_build_array_ref to this function. This is specific to
descriptors that are component and indirect references.
* trans.h : Add the force_no_tmp flag bitfield to gfc_se.

2019-05-10  Paul Thomas  

PR fortran/90093
* gfortran.dg/ISO_Fortran_binding_12.f90: New test.
* gfortran.dg/ISO_Fortran_binding_12.c: Supplementary code.

PR fortran/90352
* gfortran.dg/iso_c_binding_char_1.f90: New test.

PR fortran/90355
* gfortran.dg/ISO_Fortran_binding_4.f90: Add 'substr' to test
the direct passing of substrings as descriptors to bind(C).
* gfortran.dg/assign_10.f90: Increase the tree_dump count of
'atmp' to account for the setting of the 'span' field.
* gfortran.dg/transpose_optimization_2.f90: Ditto.

Added:
trunk/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.c
trunk/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_12.f90
trunk/gcc/testsuite/gfortran.dg/iso_c_binding_char_1.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/decl.c
trunk/gcc/fortran/trans-array.c
trunk/gcc/fortran/trans-decl.c
trunk/gcc/fortran/trans-expr.c
trunk/gcc/fortran/trans.c
trunk/gcc/fortran/trans.h
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gfortran.dg/ISO_Fortran_binding_4.f90
trunk/gcc/testsuite/gfortran.dg/assign_10.f90
trunk/gcc/testsuite/gfortran.dg/transpose_optimization_2.f90

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #6 from Paul Thomas  ---
(In reply to Thomas Koenig from comment #5)
> Hi Paul,
> 
> > I am sure that the array part is OK. Otherwise, why have a type code for
> > strings?
> 
> It 
> 
>  18.5  The source file ISO_Fortran_binding.h
> 18.5.1 Summary of contents
> 
>  The source file ISO_Fortran_binding.h shall contain the C structure
> definitions, typedef declarations, macro
> definitions, and function prototypes specified in 18.5.2 to 18.5.5. The
> definitions and declarations in ISO_-
> Fortran_binding.h can be used by a C function to interpret and manipulate a
> C descriptor. These provide a
> means to specify a C prototype that interoperates with a Fortran interface
> that has a non-interoperable dummy
> variable (18.3.6).
> 
> And the length of the character should be passed as element_len in
> the various CFI_* functions.
> 
> > I guess scalars can be handled by passing to an assumed rank array.
> 
> An array of character*1 is interoperable, yes.
> 
> Regards
> 
> Thomas

Concerning CFI descriptors:

NOTE 18.24
The value of elem_len for a Fortran CHARACTER object is equal to the character
length times the number of bytes of a single character of that kind. If the
kind is C_CHAR, this value will be equal to the character length.

This what I have implemented.

I have been trying and so far failing to pick up substrings directly as CFI
descriptors rather than using copy-in and copy out. For some reason the saved
descriptor is inaccessible.

I will investigate a wee while longer before committing. What I have works and
clears all the problems, except for the missing optional issue - I'll sort out
the latter before submission.

Cheers

Paul


Cheers

Paul

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #5 from Thomas Koenig  ---
Hi Paul,

> I am sure that the array part is OK. Otherwise, why have a type code for
> strings?

It 

 18.5  The source file ISO_Fortran_binding.h
18.5.1 Summary of contents

 The source file ISO_Fortran_binding.h shall contain the C structure
definitions, typedef declarations, macro
definitions, and function prototypes specified in 18.5.2 to 18.5.5. The
definitions and declarations in ISO_-
Fortran_binding.h can be used by a C function to interpret and manipulate a C
descriptor. These provide a
means to specify a C prototype that interoperates with a Fortran interface that
has a non-interoperable dummy
variable (18.3.6).

And the length of the character should be passed as element_len in
the various CFI_* functions.

> I guess scalars can be handled by passing to an assumed rank array.

An array of character*1 is interoperable, yes.

Regards

Thomas

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #4 from Paul Thomas  ---
Hi Thomas,

>  if the type is character, interoperability also requires that the length
> type parameter be omitted or be specified by an initialization
> expression whose value is one. 
> 
> F2008, 15.3.2 has the same language, as does F2018, 18.3.1.

I found this as well - thanks. I will restore the error by will restrict it to
scalar entities.

> 
> While no diagnostic is required (not a constraint), it is an error,
> and it would be good to flag it as such.
> 
> [I'll look up the array part later]

I am sure that the array part is OK. Otherwise, why have a type code for
strings?

I guess scalars can be handled by passing to an assumed rank array.

Cheers

Paul

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

--- Comment #3 from Thomas Koenig  ---
(In reply to Paul Thomas from comment #2)
> This is already fixed on my working branch.
> 
> This used to be the error message:
> 
> Character argument ‘c’ at (1) must be length 1 because procedure ‘bar’ is
> BIND(C)
> 
> Is this required by the standard?

F2003 has

 15.2.1  Interoperability of intrinsic types

[...]

 if the type is character, interoperability also requires that the length type
parameter be omitted or be specified by an initialization
expression whose value is one. 

F2008, 15.3.2 has the same language, as does F2018, 18.3.1.

While no diagnostic is required (not a constraint), it is an error,
and it would be good to flag it as such.

[I'll look up the array part later]

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

Paul Thomas  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |pault at gcc dot gnu.org

--- Comment #2 from Paul Thomas  ---
This is already fixed on my working branch.

This used to be the error message:

Character argument ‘c’ at (1) must be length 1 because procedure ‘bar’ is
BIND(C)

Is this required by the standard?

What about?

subroutine bar(c,d) BIND(C)
  character (len=*) c(:)
  character (len=2) d(:)
end

I have been working on passing CFI descriptors to such a procedure. I guess
that the old error only pertains to scalars?

Cheers

Paul

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

Dominique d'Humieres  changed:

   What|Removed |Added

   Priority|P3  |P4
 Status|UNCONFIRMED |NEW
  Known to work||8.3.0
Version|unknown |9.1.0
   Keywords||ice-on-invalid-code
   Last reconfirmed||2019-05-05
 CC||pault at gcc dot gnu.org
 Ever confirmed|0   |1
  Known to fail||10.0, 9.1.0

--- Comment #1 from Dominique d'Humieres  ---
Likely a fall out of r269156: no ICE with -std=f2008.

[Bug fortran/90352] [9/10 Regression] ICE on BIND(C) subroutine with characters with len /= 1

2019-05-05 Thread tkoenig at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90352

Thomas Koenig  changed:

   What|Removed |Added

   Target Milestone|--- |9.2