In tree_expand_cfg, we have:

  if (DECL_NAME (current_function_decl)
      && MAIN_NAME_P (DECL_NAME (current_function_decl))
      && DECL_FILE_SCOPE_P (current_function_decl))
    expand_main_function ();

This code should also check TREE_PUBLIC (c_f_d) (and the entire predicate
should probably be encapsulated in a macro or function).

Compiling this test case:

extern void f();

static int main () {
  f();
}

int g() {
  f();
}

on x86_64-unknown-linux-gnu with -m32 shows that the usual stack-alignment and
implicit return of zero code is generated for this "main" function, even though
it's not the real main function.


-- 
           Summary: Static function named "main" treated as the real main
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mmitchel at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24590

Reply via email to