diff mbox

Don't use create_tmp_var for static vars

Message ID 53AD2E5A.30509@codesourcery.com
State New
Headers show

Commit Message

Bernd Schmidt June 27, 2014, 8:42 a.m. UTC
I discovered that create_tmp_var is used in the gfortran frontend to 
create static variables. IMO the function is not intended to do this, 
and it causes problems for a modification I need to make to it which 
assumes that it only creates local variables. So I've made a patch to 
make fortran directly use build_decl instead in these cases.

The following was bootstrapped and tested on x86_64-linux. Ok?


Bernd
diff mbox

Patch

Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(revision 435407)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -2046,11 +2046,15 @@  gfc_build_constant_array_constructor (gf
   TREE_CONSTANT (init) = 1;
   TREE_STATIC (init) = 1;
 
-  tmp = gfc_create_var (tmptype, "A");
+  tmp = build_decl (input_location, VAR_DECL, create_tmp_var_name ("A"),
+		    tmptype);
+  DECL_ARTIFICIAL (tmp) = 1;
+  DECL_IGNORED_P (tmp) = 1;
   TREE_STATIC (tmp) = 1;
   TREE_CONSTANT (tmp) = 1;
   TREE_READONLY (tmp) = 1;
   DECL_INITIAL (tmp) = init;
+  pushdecl (tmp);
 
   return tmp;
 }
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 435407)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -5345,11 +5345,16 @@  create_main_function (tree fndecl)
     TREE_STATIC (array) = 1;
 
     /* Create a static variable to hold the jump table.  */
-    var = gfc_create_var (array_type, "options");
+    var = build_decl (input_location, VAR_DECL,
+		      create_tmp_var_name ("options"),
+		      array_type);
+    DECL_ARTIFICIAL (var) = 1;
+    DECL_IGNORED_P (var) = 1;
     TREE_CONSTANT (var) = 1;
     TREE_STATIC (var) = 1;
     TREE_READONLY (var) = 1;
     DECL_INITIAL (var) = array;
+    pushdecl (var);
     var = gfc_build_addr_expr (build_pointer_type (integer_type_node), var);
 
     tmp = build_call_expr_loc (input_location,