This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] PR 38220 Mark c_loc as pure and having a prototype
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: fortran at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 06 Jan 2009 21:08:49 +0100
- Subject: [patch, fortran] PR 38220 Mark c_loc as pure and having a prototype
Hello world,
this little patch fixes PR 38220, building on Daniel F.'s analysis in
the PR.
c_loc and c_funloc are actually implemented somewhat strangely: They
are marked as external functions, so their first argument gets, via the
g77 calling convention, the address of the argument. This was done for
simplicity's sake, and having looked at the code, I can understand
why :-)
This patch does nothing about this, but it is minimally invasive, and
does work. As this is a rejects-valid, I think this could potentiall go
into current trunk.
Regression-tested on i686-pc-linux-gnu.
OK for trunk? Or should I wait for 4.5 to branch?
Thomas
2008-01-06 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/38220
* interface.c (gfc_procedure_use): Don't warn about functions
from ISO_C_BINDING.
* symbol.c (generate_isocbinding_symbol): Mark c_loc and
c_funloc as pure.
2008-01-06 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/38220
* gfortran.dg/c_loc_pure_1.f90: New test.
Index: interface.c
===================================================================
--- interface.c (revision 143076)
+++ interface.c (working copy)
@@ -2411,9 +2411,12 @@ void
gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
{
- /* Warn about calls with an implicit interface. */
+ /* Warn about calls with an implicit interface. Special case
+ for calling a ISO_C_BINDING becase c_loc and c_funloc
+ are pseudo-unknown. */
if (gfc_option.warn_implicit_interface
- && sym->attr.if_source == IFSRC_UNKNOWN)
+ && sym->attr.if_source == IFSRC_UNKNOWN
+ && ! sym->attr.is_iso_c)
gfc_warning ("Procedure '%s' called with an implicit interface at %L",
sym->name, where);
Index: symbol.c
===================================================================
--- symbol.c (revision 143076)
+++ symbol.c (working copy)
@@ -4169,6 +4169,7 @@ generate_isocbinding_symbol (const char
tmp_sym->result = tmp_sym;
tmp_sym->attr.external = 1;
tmp_sym->attr.use_assoc = 0;
+ tmp_sym->attr.pure = 1;
tmp_sym->attr.if_source = IFSRC_UNKNOWN;
tmp_sym->attr.proc = PROC_UNKNOWN;
}
! { dg-do compile }
! { dg-options "-Wimplicit-interface" }
! PR 38220 - c_loc is pure and has an explicit interface
USE ISO_C_BINDING, ONLY: C_PTR, C_LOC
CONTAINS
PURE SUBROUTINE F(x)
INTEGER, INTENT(in), TARGET :: x
TYPE(C_PTR) :: px
px = C_LOC(x)
END SUBROUTINE
END