diff mbox series

[FORTRAN,13/29] Use stringpool for intrinsics and common

Message ID 20180905145732.404-14-rep.dot.nop@gmail.com
State New
Headers show
Series [FORTRAN,01/29] gdbinit: break on gfc_internal_error | expand

Commit Message

Bernhard Reutner-Fischer Sept. 5, 2018, 2:57 p.m. UTC
From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

gcc/fortran/ChangeLog:

2017-11-15  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	* gfortran.h (struct gfc_common_head, struct gfc_intrinsic_arg):
	Make name a pointer.
	* intrinsic.c (add_sym): Use stringpool for name.
	* match.c (gfc_get_common): Likewise.
	* symbol.c (set_symbol_common_block): Likewise.
	* trans-common.c (gfc_sym_mangled_common_id): Likewise.
	(finish_equivalences): Likewise.
	(gfc_trans_common): Likewise.
---
 gcc/fortran/gfortran.h     |  4 ++--
 gcc/fortran/intrinsic.c    | 11 +++--------
 gcc/fortran/match.c        |  2 +-
 gcc/fortran/symbol.c       |  2 +-
 gcc/fortran/trans-common.c | 10 +++++-----
 5 files changed, 12 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index cb9195d393e..039719644ea 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -1641,7 +1641,7 @@  typedef struct gfc_common_head
   char use_assoc, saved, threadprivate;
   unsigned char omp_declare_target : 1;
   unsigned char omp_declare_target_link : 1;
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  const char *name;
   struct gfc_symbol *head;
   const char* binding_label;
   int is_bind_c;
@@ -1978,7 +1978,7 @@  gfc_ref;
 /* Structures representing intrinsic symbols and their arguments lists.  */
 typedef struct gfc_intrinsic_arg
 {
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  const char *name;
 
   gfc_typespec ts;
   unsigned optional:1, value:1;
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 609668613a7..3a32a7824bf 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -317,7 +317,6 @@  add_sym (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type
 	 int standard, gfc_check_f check, gfc_simplify_f simplify,
 	 gfc_resolve_f resolve, ...)
 {
-  char buf[GFC_MAX_SYMBOL_LEN + 11]; /* 10 for '_gfortran_', 1 for '\0'  */
   int optional, first_flag;
   sym_intent intent;
   va_list argp;
@@ -334,11 +333,7 @@  add_sym (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type
 
     case SZ_NOTHING:
       next_sym->name = gfc_get_string ("%s", name);
-
-      strcpy (buf, "_gfortran_");
-      strcat (buf, name);
-      next_sym->lib_name = gfc_get_string ("%s", buf);
-
+      next_sym->lib_name = gfc_get_string ("_gfortran_%s", name);
       next_sym->pure = (cl != CLASS_IMPURE);
       next_sym->elemental = (cl == CLASS_ELEMENTAL);
       next_sym->inquiry = (cl == CLASS_INQUIRY);
@@ -388,7 +383,7 @@  add_sym (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type
 
 	  first_flag = 0;
 
-	  strcpy (next_arg->name, name);
+	  next_arg->name = gfc_get_string ("%s", name);
 	  next_arg->ts.type = type;
 	  next_arg->ts.kind = kind;
 	  next_arg->optional = optional;
@@ -4145,7 +4140,7 @@  keywords:
   for (; a; a = a->next)
     {
       for (f = formal; f; f = f->next)
-	if (strcmp (a->name, f->name) == 0)
+	if (a->name == f->name)
 	  break;
 
       if (f == NULL)
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 2c4d6e8228c..fd91e280b93 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5029,7 +5029,7 @@  gfc_get_common (const char *name, int from_module)
     {
       st->n.common = gfc_get_common_head ();
       st->n.common->where = gfc_current_locus;
-      strcpy (st->n.common->name, name);
+      st->n.common->name = name;
     }
 
   return st->n.common;
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 00a178772df..cc9d4e3f9d8 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -3057,7 +3057,7 @@  set_symbol_common_block (gfc_symbol *sym, gfc_common_head *common_block)
   if (sym->common_block == common_block)
     return;
 
-  if (sym->common_block && sym->common_block->name[0] != '\0')
+  if (sym->common_block && sym->common_block->name != NULL)
     {
       sym->common_block->refs--;
       if (sym->common_block->refs == 0)
diff --git a/gcc/fortran/trans-common.c b/gcc/fortran/trans-common.c
index bd9721dee41..18f87e00320 100644
--- a/gcc/fortran/trans-common.c
+++ b/gcc/fortran/trans-common.c
@@ -243,16 +243,16 @@  gfc_sym_mangled_common_id (gfc_common_head *com)
 {
   int has_underscore;
   char mangled_name[GFC_MAX_MANGLED_SYMBOL_LEN + 1];
-  char name[GFC_MAX_SYMBOL_LEN + 1];
+  const char *name;
 
   /* Get the name out of the common block pointer.  */
-  strcpy (name, com->name);
+  name = com->name;
 
   /* If we're suppose to do a bind(c).  */
   if (com->is_bind_c == 1 && com->binding_label)
     return get_identifier (com->binding_label);
 
-  if (strcmp (name, BLANK_COMMON_NAME) == 0)
+  if (name == gfc_get_string (BLANK_COMMON_NAME))
     return get_identifier (name);
 
   if (flag_underscoring)
@@ -1252,7 +1252,7 @@  finish_equivalences (gfc_namespace *ns)
 	      c->where = ns->proc_name->declared_at;
 	    else if (ns->is_block_data)
 	      c->where = ns->sym_root->n.sym->declared_at;
-	    strcpy (c->name, z->module);
+	    c->name = z->module;
 	  }
 	else
 	  c = NULL;
@@ -1286,7 +1286,7 @@  gfc_trans_common (gfc_namespace *ns)
     {
       c = gfc_get_common_head ();
       c->where = ns->blank_common.head->common_head->where;
-      strcpy (c->name, BLANK_COMMON_NAME);
+      c->name = gfc_get_string (BLANK_COMMON_NAME);
       translate_common (c, ns->blank_common.head);
     }