This is the mail archive of the
mailing list for the GCC project.
Re: [fortran] Different FUNC_DECLS with the same DECL_NAME - MAIN__ and named PROGRAM main functions [was Re: gcc-4.5-20090528 is now available]
Dave Korn wrote:
> Dave Korn wrote:
>> Dave Korn wrote:
>>> Tobias Burnus wrote:
>>>> I agree that for "main" the call to "__main()" should happend and thus
>>>> expand_main_function should be called. I'm not sure in about the exact
>>>> assumptions of the middle end. In principle, it would be OK if the
>>>> MAIN__ function would show up as MAIN__ in gimple/-fdump-tree-original.
>>>> The only potential inconvenience I see, is the mentioned reference to
>>>> MAIN__ instead of <program name> in middle-end warnings, which can
>>>> confuse users.
> Is it legitimate to have a space in an IDENTIFIER_NODE? I have a cheeky idea:
> - gfc_get_symbol (name, ns, &main_program);
> + identifier = gfc_get_string ("PROGRAM %s", name);
> That should give reasonable warnings from the middle end, no? I don't know
> what it might do to debugging though.
Currently one can use "b MAIN__" and "b helloworld" in the debugger:
(gdb) b helloworld
Breakpoint 1 at 0x400737: file test.f90, line 3.
(gdb) b MAIN__
Note: breakpoint 1 also set at pc 0x400737.
Breakpoint 2 at 0x400737: file test.f90, line 3.
(gdb) b main
Breakpoint 3 at 0x4007b9: file test.f90, line 9.
I have another idea: Just handle "PROGRAM main" specially by using the
name "MAIN__". It should be still quite readable in the middle-end
diagnostics. Furthermore, it matches the assembler name and using "b
main" one still get something useful - and it is less confusing for
everyone (middle end, users of -fdump-tree-original etc.) if there is
only a single "main".
--- gcc/fortran/trans-decl.c (Revision 148004)
+++ gcc/fortran/trans-decl.c (Arbeitskopie)
@@ -289,7 +289,10 @@ gfc_get_label_decl (gfc_st_label * lp)
gfc_sym_identifier (gfc_symbol * sym)
- return (get_identifier (sym->name));
+ if (sym->attr.is_main_program && strcmp (sym->name, "main") == 0)
+ return (get_identifier ("MAIN__"));
+ return (get_identifier (sym->name));
@@ -3874,6 +3877,8 @@ create_main_function (tree fndecl)
tmp = build_function_type_list (integer_type_node, integer_type_node,
+ main_identifier_node = get_identifier ("main");
+ ftn_main = build_decl (FUNCTION_DECL, main_identifier_node, tmp);
ftn_main = build_decl (FUNCTION_DECL, get_identifier ("main"), tmp);
DECL_EXTERNAL (ftn_main) = 0;
TREE_PUBLIC (ftn_main) = 1;