This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Fortran,Patch] PR40955 - Save ext_attr such as STDCALL to .MOD file
- From: Tobias Burnus <burnus at net-b dot de>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 5 Aug 2009 14:31:58 +0200
- Subject: Re: [Fortran,Patch] PR40955 - Save ext_attr such as STDCALL to .MOD file
- References: <20090804082319.GA7941@net-b.de>
On Tue, Aug 04, 2009 at 10:23:19AM +0200, Tobias Burnus wrote:
> Another STDCALL (and friends) omission: The extended attribute was not
> saved in the MOD file.
Attached patch supercedes that patch. New features:
- gfc_copy_attr now also copies the extended attributes
- Extended attributes now also work with procedure (pointers), inheriting
the attributes from the (abstract) interface (or-ed together with local
addition; if a combination does not make sense, I leave it to the middle
end to warn)
And I changed gfc_add_ext_attr to take an enum as argument instead of
an unsigned int. The reason is that I was tempted to use
gfc_add_ext_attr (sym, attr->ext_attr)
which does not work. (In gfc_add_ext_attr the argument a "1" is bit
shifted depending on the argument.) With enum there is at least the
chance that we get a compile-time warning (or via -Werror an error).
> I could have bumped the MOD file version; however, as it already was
> bumped for 4.5 and as the message is somewhat clear
> ("Fatal Error: Reading module ... Expected attribute bit name" ...
> and "... Expected integer"), I have not done it.
>
> I have bootstrapped and regtested (check gfortran & libgomp) it on
> x86-64-linux, but I cannot really test it - except that for a simple
> test case, there is now an additional
> test.f90:10:0: warning: 'stdcall' attribute ignored
> for the CALL, i.e. it seems to work correctly.
The procedure part was tested on x86-64-linux with the test case from
the PR. (GCC on x86-64 shows nice warnings that the options was ignored.)
> I do not know how to best create a test case, thus I have not added
> one. I think we badly need a test case for 32bit MinGW/Cygwin, which
> calls some STDCALL Windows ABI function.
Another option is to add a test for x86-64 and check for dg-warning.
I can add such a patch, if it is deemed to be useful.
> OK for the trunk?
Tobias
2009-08-05 Tobias Burnus <burnus@net-b.de>
PR fortran/40955
* gfortran.h (ext_attr_id_t): Add typedef for this enum.
(gfc_add_ext_attribute): Use it.
* decl.c (gfc_match_gcc_attributes): Ditto.
* expr.c (gfc_check_pointer_assign): Ditto.
* symbol.c (gfc_add_ext_attribute): Ditto.
(gfc_copy_attr): Copy also ext_attr.
* resolve.c (resolve_fl_derived,resolve_symbol): Ditto.
* module.c (mio_symbol_attribute): Save ext_attr in the mod file.
2009-08-05 Tobias Burnus <burnus@net-b.de>
PR fortran/40955
* gfortran.dg/module_md5_1.f90: Update MD5 check sum.
Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c (revision 150482)
+++ gcc/fortran/symbol.c (working copy)
@@ -810,7 +810,7 @@ duplicate_attr (const char *attr, locus
gfc_try
-gfc_add_ext_attribute (symbol_attribute *attr, unsigned ext_attr,
+gfc_add_ext_attribute (symbol_attribute *attr, ext_attr_id_t ext_attr,
locus *where ATTRIBUTE_UNUSED)
{
attr->ext_attr |= 1 << ext_attr;
@@ -1641,6 +1641,8 @@ gfc_copy_attr (symbol_attribute *dest, s
{
int is_proc_lang_bind_spec;
+ dest->ext_attr = src->ext_attr;
+
if (src->allocatable && gfc_add_allocatable (dest, where) == FAILURE)
goto fail;
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 150482)
+++ gcc/fortran/decl.c (working copy)
@@ -7678,7 +7678,7 @@ gfc_match_gcc_attributes (void)
return MATCH_ERROR;
}
- if (gfc_add_ext_attribute (&attr, id, &gfc_current_locus)
+ if (gfc_add_ext_attribute (&attr, (ext_attr_id_t) id, &gfc_current_locus)
== FAILURE)
return MATCH_ERROR;
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (revision 150482)
+++ gcc/fortran/gfortran.h (working copy)
@@ -621,7 +621,7 @@ extern CInteropKind_t c_interop_kinds_ta
/* Structure and list of supported extension attributes. */
-enum
+typedef enum
{
EXT_ATTR_DLLIMPORT = 0,
EXT_ATTR_DLLEXPORT,
@@ -629,7 +629,8 @@ enum
EXT_ATTR_CDECL,
EXT_ATTR_FASTCALL,
EXT_ATTR_LAST, EXT_ATTR_NUM = EXT_ATTR_LAST
-};
+}
+ext_attr_id_t;
typedef struct
{
@@ -2334,7 +2335,7 @@ gfc_try gfc_set_default_type (gfc_symbol
void gfc_set_sym_referenced (gfc_symbol *);
gfc_try gfc_add_attribute (symbol_attribute *, locus *);
-gfc_try gfc_add_ext_attribute (symbol_attribute *, unsigned, locus *);
+gfc_try gfc_add_ext_attribute (symbol_attribute *, ext_attr_id_t, locus *);
gfc_try gfc_add_allocatable (symbol_attribute *, locus *);
gfc_try gfc_add_dimension (symbol_attribute *, const char *, locus *);
gfc_try gfc_add_external (symbol_attribute *, locus *);
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c (revision 150482)
+++ gcc/fortran/expr.c (working copy)
@@ -3195,9 +3195,9 @@ gfc_check_pointer_assign (gfc_expr *lval
symbol_attribute cdecl, stdcall, fastcall;
unsigned calls;
- gfc_add_ext_attribute (&cdecl, (unsigned) EXT_ATTR_CDECL, NULL);
- gfc_add_ext_attribute (&stdcall, (unsigned) EXT_ATTR_STDCALL, NULL);
- gfc_add_ext_attribute (&fastcall, (unsigned) EXT_ATTR_FASTCALL, NULL);
+ gfc_add_ext_attribute (&cdecl, EXT_ATTR_CDECL, NULL);
+ gfc_add_ext_attribute (&stdcall, EXT_ATTR_STDCALL, NULL);
+ gfc_add_ext_attribute (&fastcall, EXT_ATTR_FASTCALL, NULL);
calls = cdecl.ext_attr | stdcall.ext_attr | fastcall.ext_attr;
if ((calls & lvalue->symtree->n.sym->attr.ext_attr)
Index: gcc/fortran/module.c
===================================================================
--- gcc/fortran/module.c (revision 150482)
+++ gcc/fortran/module.c (working copy)
@@ -1752,6 +1752,7 @@ static void
mio_symbol_attribute (symbol_attribute *attr)
{
atom_type t;
+ unsigned ext_attr;
mio_lparen ();
@@ -1760,6 +1761,9 @@ mio_symbol_attribute (symbol_attribute *
attr->proc = MIO_NAME (procedure_type) (attr->proc, procedures);
attr->if_source = MIO_NAME (ifsrc) (attr->if_source, ifsrc_types);
attr->save = MIO_NAME (save_state) (attr->save, save_status);
+ ext_attr = attr->ext_attr;
+ mio_integer ((int *) &ext_attr);
+ attr->ext_attr = ext_attr;
if (iomode == IO_OUTPUT)
{
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 150482)
+++ gcc/fortran/resolve.c (working copy)
@@ -9217,6 +9217,7 @@ resolve_fl_derived (gfc_symbol *sym)
c->attr.elemental = ifc->attr.elemental;
c->attr.recursive = ifc->attr.recursive;
c->attr.always_explicit = ifc->attr.always_explicit;
+ c->attr.ext_attr |= ifc->attr.ext_attr;
/* Replace symbols in array spec. */
if (c->as)
{
@@ -9712,6 +9713,7 @@ resolve_symbol (gfc_symbol *sym)
sym->attr.dimension = ifc->attr.dimension;
sym->attr.recursive = ifc->attr.recursive;
sym->attr.always_explicit = ifc->attr.always_explicit;
+ sym->attr.ext_attr |= ifc->attr.ext_attr;
/* Copy array spec. */
sym->as = gfc_copy_array_spec (ifc->as);
if (sym->as)
Index: gcc/testsuite/gfortran.dg/module_md5_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/module_md5_1.f90 (revision 150482)
+++ gcc/testsuite/gfortran.dg/module_md5_1.f90 (working copy)
@@ -10,5 +10,5 @@
use foo
print *, pi
end program test
-! { dg-final { scan-module "foo" "MD5:596df8f39d3ddc0b847771cadcb26274" } }
+! { dg-final { scan-module "foo" "MD5:dc2fd1358dcaddc25e3c89dae859ef32" } }
! { dg-final { cleanup-modules "foo" } }