diff mbox

[Fortran] PR 47260: Fix DLLEXPORT

Message ID 4D2F275E.1040108@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Jan. 13, 2011, 4:25 p.m. UTC
Thank to Kai for debugging this - and for creating the patch, which I 
only slightly cleaned up.

The issue is quite interesting - if one calls decl_attributes before 
setting the TREE_PUBLIC attribute, the TREE seems to be inconsistent: 
For some parts of the ME the procedure is properly regarded as public - 
for other it is regarded as local (private/static) function.

The solution is simple: Moving the setting of TREE_PUBLIC/TREE_EXTERNAL 
before the call to decl_attributes.

I think Kai has tested the patch on MinGW64 for the example of the PR. I 
have build and regtested it on x86-64-linux.
OK for the trunk?

Tobias

PS: I assume that this patch also fixes the issue with the .def file, 
but I have not tested it - and I believe Kai has neither.

Comments

Tobias Burnus Jan. 13, 2011, 6:05 p.m. UTC | #1
On 01/13/2011 05:25 PM, Tobias Burnus wrote:
> I think Kai has tested the patch on MinGW64 for the example of the PR. 
> I have build and regtested it on x86-64-linux. OK for the trunk?

Approved by Daniel Kraft in IRC. Committed as Rev. 168757.

Tobias
diff mbox

Patch

2011-01-13  Kai Tietz  <kai.tietz@onevision.com>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/47260
	* trans-decl.c (gfc_get_extern_function_decl,
	build_function_decl): Set TREE_PUBLIC/TREE_EXTERNAL before
	calling decl_attributes.

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 829548c..9e7f2f2 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1575,6 +1575,12 @@  gfc_get_extern_function_decl (gfc_symbol * sym)
   fndecl = build_decl (input_location,
 		       FUNCTION_DECL, name, type);
 
+  /* Initialize DECL_EXTERNAL and TREE_PUBLIC before calling decl_attributes;
+     TREE_PUBLIC specifies whether a function is globally addressable (i.e.
+     the the opposite of declaring a function as static in C.  */
+  DECL_EXTERNAL (fndecl) = 1;
+  TREE_PUBLIC (fndecl) = 1;
+
   attributes = add_attributes_to_decl (sym->attr, NULL_TREE);
   decl_attributes (&fndecl, attributes, 0);
 
@@ -1592,12 +1598,6 @@  gfc_get_extern_function_decl (gfc_symbol * sym)
       DECL_CONTEXT (fndecl) = NULL_TREE;
     }
 
-  DECL_EXTERNAL (fndecl) = 1;
-
-  /* This specifies if a function is globally addressable, i.e. it is
-     the opposite of declaring static in C.  */
-  TREE_PUBLIC (fndecl) = 1;
-
   /* Set attributes for PURE functions. A call to PURE function in the
      Fortran 95 sense is both pure and without side effects in the C
      sense.  */
@@ -1658,6 +1658,15 @@  build_function_decl (gfc_symbol * sym, bool global)
 
   attr = sym->attr;
 
+  /* Initialize DECL_EXTERNAL and TREE_PUBLIC before calling decl_attributes;
+     TREE_PUBLIC specifies whether a function is globally addressable (i.e.
+     the the opposite of declaring a function as static in C.  */
+  DECL_EXTERNAL (fndecl) = 0;
+
+  if (!current_function_decl
+      && !sym->attr.entry_master && !sym->attr.is_main_program)
+    TREE_PUBLIC (fndecl) = 1;
+
   attributes = add_attributes_to_decl (attr, NULL_TREE);
   decl_attributes (&fndecl, attributes, 0);
 
@@ -1707,15 +1716,6 @@  build_function_decl (gfc_symbol * sym, bool global)
   /* Don't call layout_decl for a RESULT_DECL.
      layout_decl (result_decl, 0);  */
 
-  /* Set up all attributes for the function.  */
-  DECL_EXTERNAL (fndecl) = 0;
-
-  /* This specifies if a function is globally visible, i.e. it is
-     the opposite of declaring static in C.  */
-  if (!current_function_decl
-      && !sym->attr.entry_master && !sym->attr.is_main_program)
-    TREE_PUBLIC (fndecl) = 1;
-
   /* TREE_STATIC means the function body is defined here.  */
   TREE_STATIC (fndecl) = 1;