From 97d17ac21c4835251b1b485584fafaa5b187968d Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Wed, 27 Jan 1993 19:21:01 -0500 Subject: [PATCH] (declare_function_name): If char_array_type_node isn't large enough for the name, make a larger type. From-SVN: r3368 --- gcc/c-common.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/gcc/c-common.c b/gcc/c-common.c index 1a8838afed9..3c51f0bf7b5 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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); } -- 2.30.2