On Wed, 14 Mar 2012, Tristan Gingold wrote: > 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 ?
There are more checks for MAIN_NAME_P, so this certainly isn't enough. And if it is a good idea then the whole check, whether a FUNCTION_DECL is considered 'main' should be put into a function in tree.[ch] and used everywhere. Note that what is 'main' is controlled by main_identifier_node, controlled by frontends. So - why is that not enough to control for Ada? Richard. > Tristan. > > gcc/ > 2012-03-14 Tristan Gingold <ging...@adacore.com> > > * cfgexpand.c (gimple_expand_cfg): Consider the assembly name > to call expand_main_function. > > gcc/ada/ > 2012-03-14 Tristan Gingold <ging...@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); > > > -- Richard Guenther <rguent...@suse.de> SUSE / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer