Bug 90093 - Extended C interop: optional argument incorrectly identified as PRESENT
Summary: Extended C interop: optional argument incorrectly identified as PRESENT
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2019-04-15 09:25 UTC by Bader@lrz.de
Modified: 2019-05-11 07:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-05-03 00:00:00


Attachments
UNIX archive with test case (740 bytes, application/x-tar)
2019-04-15 09:25 UTC, Bader@lrz.de
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bader@lrz.de 2019-04-15 09:25:55 UTC
Created attachment 46166 [details]
UNIX archive with test case

The attached test code can be compiled with
gcc -c optional_02_pos.c
gfortran optional_02_pos.f90 optional_02_pos.o
and produces the output

FAIL 2 T T T

The cause of this is that the call of the procedure from C with NULL as
first argument is incorrectly treated.

This appears to be a regression of the most recent fixes for the C descriptor.
Comment 1 Dominique d'Humieres 2019-05-03 15:07:17 UTC
Confirmed.
Comment 2 Paul Thomas 2019-05-04 08:28:49 UTC
I'll take it. I do not think that it is a regression but I will backport the fix, when it exists :-)

Cheers

Paul
Comment 3 Paul Thomas 2019-05-10 08:00:19 UTC
Author: pault
Date: Fri May 10 07:59:42 2019
New Revision: 271057

URL: https://gcc.gnu.org/viewcvs?rev=271057&root=gcc&view=rev
Log:
2019-05-10  Paul Thomas  <pault@gcc.gnu.org>

	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  <pault@gcc.gnu.org>

	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
Comment 4 Paul Thomas 2019-05-11 07:48:04 UTC
Author: pault
Date: Sat May 11 07:47:32 2019
New Revision: 271089

URL: https://gcc.gnu.org/viewcvs?rev=271089&root=gcc&view=rev
Log:
2019-05-11  Paul Thomas  <pault@gcc.gnu.org>

	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  <pault@gcc.gnu.org>

	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
Comment 5 Paul Thomas 2019-05-11 07:50:24 UTC
Author: pault
Date: Sat May 11 07:49:52 2019
New Revision: 271090

URL: https://gcc.gnu.org/viewcvs?rev=271090&root=gcc&view=rev
Log:
2019-05-11  Paul Thomas  <pault@gcc.gnu.org>

	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
Comment 6 Paul Thomas 2019-05-11 07:51:13 UTC
Fixed on trunk and 9-branch.

Thanks for the report

Paul