public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch/cfgexpand]: also consider assembler_name to call expand_main_function
@ 2012-03-14 16:04 Tristan Gingold
  2012-03-14 16:09 ` Richard Guenther
  0 siblings, 1 reply; 15+ messages in thread
From: Tristan Gingold @ 2012-03-14 16:04 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Guenther, Eric Botcazou

Hi,

the code to call expand_main_function currently only checks DECL_NAME.  This leads
to a hack in ada/gcc-interface/utils.c to handle the gnatbind generated file that could
declare:

package ada_main is
…
   function my_main
     (argc : Integer;
      argv : System.Address;
      envp : System.Address)
      return Integer;
   pragma Export (C, my_main, "main");
…
end ada_main;

But expand_main_function is also called for function whose name is main but assembly name isn't.  Eg:

package pkg is
   procedure main;
end pkg;

So I think we should consider the assembler name is set, otherwise the decl name.

Manually tested on ia64-hp-openvms (where this issue was discovered).
No C regressions for x86_64-darwin.

Ok for trunk ?

Tristan.

gcc/
2012-03-14  Tristan Gingold  <gingold@adacore.com>

	* cfgexpand.c (gimple_expand_cfg): Consider the assembly name
	to call expand_main_function.

gcc/ada/
2012-03-14  Tristan Gingold  <gingold@adacore.com>

	* gcc-interface/utils.c (create_subprog_decl): Do not override
	DECL_NAME if asm_name is set.


diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 2f38bb4..8693876 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -4501,8 +4501,12 @@ gimple_expand_cfg (void)
   /* If this function is `main', emit a call to `__main'
      to run global initializers, etc.  */
   if (DECL_NAME (current_function_decl)
-      && MAIN_NAME_P (DECL_NAME (current_function_decl))
-      && DECL_FILE_SCOPE_P (current_function_decl))
+      && DECL_FILE_SCOPE_P (current_function_decl)
+      && main_identifier_node != NULL_TREE
+      && ((!DECL_ASSEMBLER_NAME_SET_P (current_function_decl)
+	   && MAIN_NAME_P (DECL_NAME (current_function_decl)))
+	  || decl_assembler_name_equal (current_function_decl,
+					main_identifier_node)))
     expand_main_function ();
 
   /* Initialize the stack_protect_guard field.  This must happen after the

diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index 7383358..81a1a0a 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -1899,18 +1899,7 @@ create_subprog_decl (tree subprog_name, tree asm_name, tree subprog_type,
   DECL_RESULT (subprog_decl) = result_decl;
 
   if (asm_name)
-    {
-      SET_DECL_ASSEMBLER_NAME (subprog_decl, asm_name);
-
-      /* The expand_main_function circuitry expects "main_identifier_node" to
-	 designate the DECL_NAME of the 'main' entry point, in turn expected
-	 to be declared as the "main" function literally by default.  Ada
-	 program entry points are typically declared with a different name
-	 within the binder generated file, exported as 'main' to satisfy the
-	 system expectations.  Force main_identifier_node in this case.  */
-      if (asm_name == main_identifier_node)
-	DECL_NAME (subprog_decl) = main_identifier_node;
-    }
+    SET_DECL_ASSEMBLER_NAME (subprog_decl, asm_name);
 
   /* Add this decl to the current binding level.  */
   gnat_pushdecl (subprog_decl, gnat_node);


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-03-21  8:40 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-14 16:04 [Patch/cfgexpand]: also consider assembler_name to call expand_main_function Tristan Gingold
2012-03-14 16:09 ` Richard Guenther
2012-03-14 16:25   ` Tristan Gingold
2012-03-15  9:38     ` Richard Guenther
2012-03-15 12:51       ` Tristan Gingold
2012-03-20 12:07       ` Tristan Gingold
2012-03-20 12:22         ` Richard Guenther
2012-03-20 14:12           ` Tristan Gingold
2012-03-20 14:20             ` Richard Guenther
2012-03-20 16:00               ` Tristan Gingold
2012-03-20 16:02                 ` Richard Guenther
2012-03-20 16:06                   ` Tristan Gingold
2012-03-21  7:44                     ` Richard Guenther
2012-03-20 17:18           ` Jan Hubicka
2012-03-21  8:40             ` Tristan Gingold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).