User account creation filtered due to spam.

Bug 23060 - %VAL, %REF and %DESCR constructs not implemented
Summary: %VAL, %REF and %DESCR constructs not implemented
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.2.0
Assignee: Paul Thomas
URL:
Keywords:
: 23062 (view as bug list)
Depends on:
Blocks: 19292
  Show dependency treegraph
 
Reported: 2005-07-25 15:26 UTC by Peter W. Draper
Modified: 2014-02-16 13:15 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-11-14 10:16:44


Attachments
Testcase. Fortran source (488 bytes, text/plain)
2005-07-25 16:10 UTC, Peter W. Draper
Details
Part of simple testcase. (175 bytes, text/plain)
2005-07-25 16:11 UTC, Peter W. Draper
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter W. Draper 2005-07-25 15:26:16 UTC
The %VAL construct is used for passing arguments by value, rather than the 
usual by reference or descriptor. It is vital for interoperability with other
languages such as C.

This feature is available in g77:

http://gcc.gnu.org/onlinedocs/gcc-3.4.4/g77/_0025VAL_0028_0029.html#_0025VAL_0028_0029

My interest in this feature comes from the world of astronomy where we have
a large legacy code base (~1 Million SLOC) written in Fortran 77, (see
http://cvsweb.starlink.ac.uk) where this feature is used for efficiently
accessing large data arrays using mmap, complex data structures, and for
accessing dynamic memory.
Comment 1 Andrew Pinski 2005-07-25 15:34:50 UTC
Confirmed.
Comment 2 Andrew Pinski 2005-07-25 15:54:11 UTC
*** Bug 23062 has been marked as a duplicate of this bug. ***
Comment 3 Peter W. Draper 2005-07-25 16:10:31 UTC
Created attachment 9360 [details]
Testcase. Fortran source

Simple test case that calls C malloc from Fortran. Also need file
malloc_wrapper.c.
Comment 4 Peter W. Draper 2005-07-25 16:11:10 UTC
Created attachment 9361 [details]
Part of simple testcase.
Comment 5 Andrew Pinski 2005-07-25 16:37:29 UTC
*** Bug 23063 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2005-07-25 16:56:29 UTC
*** Bug 23064 has been marked as a duplicate of this bug. ***
Comment 7 Paul Martinolich 2005-12-07 15:28:43 UTC
Since g77 supported this construct, should this not be a regression rather than an enhancement.
Comment 8 Francois-Xavier Coudert 2006-09-28 07:58:22 UTC
Changing this into a bug, since it was implemented in g77. It might be working soon, since we will soon have ISO_C_BINDING val attribute, which does the same thing, so adding the %val construct will probably be very easy.
Comment 9 Francois-Xavier Coudert 2006-10-12 13:19:01 UTC
[Paul changed this bug into enhancement]

I'm changing this back (again) into a bug, not an enhancement, because it was supported by g77, and we're trying to make a drop-in replacement for g77 in most cases.
Comment 10 Francois-Xavier Coudert 2006-11-03 14:11:48 UTC
Adding %REF and %DESCR to the summary. Documentation available here:
http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Functions-and-Subroutines.html
Comment 11 Paul Thomas 2006-11-14 10:16:44 UTC
A long overdue patch for this will be submitted in the next 24hours.

Paul
Comment 12 patchapp@dberlin.org 2006-12-29 17:25:27 UTC
Subject: Bug number PR23060

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-12/msg01834.html
Comment 13 Paul Thomas 2006-12-31 06:55:31 UTC
Subject: Bug 23060

Author: pault
Date: Sun Dec 31 06:55:16 2006
New Revision: 120295

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120295
Log:
2006-12-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/23060
	* intrinsic.c (compare_actual_formal ): Distinguish argument
	list functions from keywords.
	* intrinsic.c (sort_actual): If formal is NULL, the presence of
	an argument list function actual is an error.
	* trans-expr.c (conv_arglist_function) : New function to
	implement argument list functions %VAL, %REF and %LOC.
	(gfc_conv_function_call): Call it.
	* resolve.c (resolve_actual_arglist): Add arg ptype and check
	argument list functions.
	(resolve_function, resolve_call): Set value of ptype before
	calls to resolve_actual_arglist.
	* primary.c (match_arg_list_function): New function.
	(gfc_match_actual_arglist): Call it before trying for a
	keyword argument.

2006-12-31  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/23060
	* gfortran.dg/c_by_val.c: Called by c_by_val_1.f.
	* gfortran.dg/c_by_val_1.f: New test.
	* gfortran.dg/c_by_val_2.f: New test.
	* gfortran.dg/c_by_val_3.f: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/c_by_val.c
    trunk/gcc/testsuite/gfortran.dg/c_by_val_1.f
    trunk/gcc/testsuite/gfortran.dg/c_by_val_2.f90
    trunk/gcc/testsuite/gfortran.dg/c_by_val_3.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/primary.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Paul Thomas 2007-01-06 14:13:50 UTC
Subject: Bug 23060

Author: pault
Date: Sat Jan  6 14:13:20 2007
New Revision: 120525

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=120525
Log:
2007-01-06  Paul Thomas  <pault@gcc.gnu.org>

	Bug fixes from trunk

	PR fortran/30034
	* resolve.c (resolve_formal_arglist): Exclude the test for
	pointers and procedures for subroutine arguments as well as
	functions.

	PR fortran/30237
	* intrinsic.c (remove_nullargs): Do not pass up arguments with
	a label. If the actual has a label and the formal has a type
	then emit an error.

	PR fortran/25135
	* module.c (load_generic_interfaces): If the symbol is present
	and is not generic it is ambiguous.

	PR fortran/23060
	* intrinsic.c (compare_actual_formal ): Distinguish argument
	list functions from keywords.
	* intrinsic.c (sort_actual): If formal is NULL, the presence of
	an argument list function actual is an error.
	* trans-expr.c (conv_arglist_function) : New function to
	implement argument list functions %VAL, %REF and %LOC.
	(gfc_conv_function_call): Call it.
	* resolve.c (resolve_actual_arglist): Add arg ptype and check
	argument list functions.
	(resolve_function, resolve_call): Set value of ptype before
	calls to resolve_actual_arglist.
	* primary.c (match_arg_list_function): New function.
	(gfc_match_actual_arglist): Call it before trying for a
	keyword argument.

	PR fortran/27900
	* resolve.c (resolve_actual_arglist): If all else fails and a
	procedure actual argument has no type, see if a specific
	intrinsic matches.

	PR fortran/24325
	* resolve.c (resolve_function): If the function reference is
	FL_VARIABLE this is an error.

2007-01-06  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30034
	* gfortran.dg/pure_formal_proc_1.f90: New test.

	PR fortran/30237
	* gfortran.dg/intrinsic_actual_3.f90: New test.

	PR fortran/25135
	* gfortran.dg/generic_11.f90: New test.
	* gfortran.dg/interface_7.f90: Remove name clash between module
	name and procedure 'x' referenced in the interface.

	PR fortran/23060
	* gfortran.dg/c_by_val.c: Called by c_by_val_1.f.
	* gfortran.dg/c_by_val_1.f: New test.
	* gfortran.dg/c_by_val_2.f: New test.
	* gfortran.dg/c_by_val_3.f: New test.

	PR fortran/27900
	* gfortran.dg/intrinsic_actual_4.f90: New test.

	PR fortran/24325
	* gfortran.dg/func_decl_3.f90: New test.


Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/c_by_val.c
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/c_by_val_1.f
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/c_by_val_2.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/c_by_val_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/func_decl_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/generic_11.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/intrinsic_actual_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/intrinsic_actual_4.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/pure_formal_proc_1.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/interface.c
    branches/gcc-4_2-branch/gcc/fortran/intrinsic.c
    branches/gcc-4_2-branch/gcc/fortran/module.c
    branches/gcc-4_2-branch/gcc/fortran/primary.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/dummy_procedure_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/interface_7.f90

Comment 15 Paul Thomas 2007-01-06 14:17:51 UTC
Fixed on trunk and 4.2

Paul
Comment 16 Dmitry Markman 2007-01-26 01:05:04 UTC
it looks like that suggested code doesn't work for x86_64 platform. I changed ADDR declaration to
INTEGER *8 and gfortran -m64 percentval.f returns the following errors:
CALL SUB1( %VAL( ADDR ), SIZE )                                   
                     1
Error: Kind of by-value argument at (1) is larger than default kind
I did it on Mac OS X 10.4.8 and with gcc 4.2
but I guess it could work on Leopard 10.5 but I didn't check it
Comment 17 Dmitry Markman 2007-01-26 01:45:00 UTC
after looking at the gcc/fortran/trans_types.c I tried to use
-fdefault-integer-8 switch
and everything was fine
Comment 18 Jackie Rosen 2014-02-16 13:15:28 UTC Comment hidden (spam)