OSDN Git Service

2009-05-27 Tobias Burnus <burnus@net-b.de>
authorburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 May 2009 19:49:22 +0000 (19:49 +0000)
committerburnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 27 May 2009 19:49:22 +0000 (19:49 +0000)
        PR fortran/40270
        * trans-decl.c (create_main_function): Mark MAIN__ and
        argc/argv as TREE_USED and push/pop function_decl context
        if needed.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147926 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c

index 8055962..18f355c 100644 (file)
@@ -1,3 +1,10 @@
+2009-05-27  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/40270
+       * trans-decl.c (create_main_function): Mark MAIN__ and
+       argc/argv as TREE_USED and push/pop function_decl context
+       if needed.
+
 2009-05-26  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/39178
index 3695555..ba85edd 100644 (file)
@@ -3838,11 +3838,20 @@ add_argument_checking (stmtblock_t *block, gfc_symbol *sym)
 static void
 create_main_function (tree fndecl)
 {
-
+  tree old_context;
   tree ftn_main;
   tree tmp, decl, result_decl, argc, argv, typelist, arglist;
   stmtblock_t body;
 
+  old_context = current_function_decl;
+
+  if (old_context)
+    {
+      push_function_context ();
+      saved_parent_function_decls = saved_function_decls;
+      saved_function_decls = NULL_TREE;
+    }
+
   /* main() function must be declared with global scope.  */
   gcc_assert (current_function_decl == NULL_TREE);
 
@@ -3903,6 +3912,8 @@ create_main_function (tree fndecl)
   /* Call some libgfortran initialization routines, call then MAIN__(). */
 
   /* Call _gfortran_set_args (argc, argv).  */
+  TREE_USED (argc) = 1;
+  TREE_USED (argv) = 1;
   tmp = build_call_expr (gfor_fndecl_set_args, 2, argc, argv);
   gfc_add_expr_to_block (&body, tmp);
 
@@ -4000,6 +4011,9 @@ create_main_function (tree fndecl)
   tmp = build_call_expr (fndecl, 0);
   gfc_add_expr_to_block (&body, tmp);
 
+  /* Mark MAIN__ as used.  */
+  TREE_USED (fndecl) = 1;
+
   /* "return 0".  */
   tmp = fold_build2 (MODIFY_EXPR, integer_type_node, DECL_RESULT (ftn_main),
                     build_int_cst (integer_type_node, 0));
@@ -4023,6 +4037,13 @@ create_main_function (tree fndecl)
 
   gfc_gimplify_function (ftn_main);
   cgraph_finalize_function (ftn_main, false);
+
+  if (old_context)
+    {
+      pop_function_context ();
+      saved_function_decls = saved_parent_function_decls;
+    }
+  current_function_decl = old_context;
 }