(declare_function_name): If char_array_type_node isn't large enough
authorRichard Kenner <kenner@gcc.gnu.org>
Thu, 28 Jan 1993 00:21:01 +0000 (19:21 -0500)
committerRichard Kenner <kenner@gcc.gnu.org>
Thu, 28 Jan 1993 00:21:01 +0000 (19:21 -0500)
for the name, make a larger type.

From-SVN: r3368

gcc/c-common.c

index 1a8838afed92fdfd2f69001afd1b4179ee5a67f7..3c51f0bf7b5736a7f2ccc188e8696b19801fc4d5 100644 (file)
@@ -29,8 +29,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 void
 declare_function_name ()
 {
-  tree decl, init;
+  tree decl, type, init;
   char *name, *printable_name;
+  int len;
 
   if (current_function_decl == NULL)
     {
@@ -50,29 +51,43 @@ declare_function_name ()
       printable_name = (*decl_printable_name) (current_function_decl, &kind);
     }
 
+  /* If the default size of char arrays isn't big enough for the name,
+     make a bigger one.  */
+  len = strlen (name) + 1;
+  type = char_array_type_node;
+  if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TREE_TYPE (char_array_type_node)))
+      < len)
+    type = build_array_type (char_type_node,
+                            build_index_type (build_int_2 (len, 0)));
+
   push_obstacks_nochange ();
-  decl = build_decl (VAR_DECL, get_identifier ("__FUNCTION__"),
-                    char_array_type_node);
+  decl = build_decl (VAR_DECL, get_identifier ("__FUNCTION__"), type);
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
   DECL_SOURCE_LINE (decl) = 0;
   DECL_IN_SYSTEM_HEADER (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  init = build_string (strlen (name) + 1, name);
-  TREE_TYPE (init) = char_array_type_node;
+  init = build_string (len, name);
+  TREE_TYPE (init) = type;
   DECL_INITIAL (decl) = init;
   finish_decl (pushdecl (decl), init, NULL_TREE);
 
+  len = strlen (printable_name) + 1;
+  type = char_array_type_node;
+  if (TREE_INT_CST_LOW (TYPE_MAX_VALUE (TREE_TYPE (char_array_type_node)))
+      < len)
+    type = build_array_type (char_type_node,
+                            build_index_type (build_int_2 (len, 0)));
+
   push_obstacks_nochange ();
-  decl = build_decl (VAR_DECL, get_identifier ("__PRETTY_FUNCTION__"),
-                    char_array_type_node);
+  decl = build_decl (VAR_DECL, get_identifier ("__PRETTY_FUNCTION__"), type);
   TREE_STATIC (decl) = 1;
   TREE_READONLY (decl) = 1;
   DECL_SOURCE_LINE (decl) = 0;
   DECL_IN_SYSTEM_HEADER (decl) = 1;
   DECL_IGNORED_P (decl) = 1;
-  init = build_string (strlen (printable_name) + 1, printable_name);
-  TREE_TYPE (init) = char_array_type_node;
+  init = build_string (len, printable_name);
+  TREE_TYPE (init) = type;
   DECL_INITIAL (decl) = init;
   finish_decl (pushdecl (decl), init, NULL_TREE);
 }