diff options
author | Jason Merrill <jason@redhat.com> | 2022-10-20 13:51:37 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-10-24 16:28:03 -0400 |
commit | 244021b6c1a7bdeb777874ddc2ebcecb95610ef1 (patch) | |
tree | c6b4c10a0916da733a3fc55f3bb726d5b7286dc6 /gcc/cp | |
parent | 205538832b7033699047900cf25928f5920d8b93 (diff) | |
download | gcc-244021b6c1a7bdeb777874ddc2ebcecb95610ef1.zip gcc-244021b6c1a7bdeb777874ddc2ebcecb95610ef1.tar.gz gcc-244021b6c1a7bdeb777874ddc2ebcecb95610ef1.tar.bz2 |
tree: add build_string_literal overloads
Simplify several calls to build_string_literal by not requiring redundant
strlen or IDENTIFIER_* in the caller.
I also corrected a wrong comment on IDENTIFIER_LENGTH.
gcc/ChangeLog:
* tree.h (build_string_literal): New one-argument overloads that
take tree (identifier) and const char *.
* builtins.cc (fold_builtin_FILE)
(fold_builtin_FUNCTION)
* gimplify.cc (gimple_add_init_for_auto_var)
* vtable-verify.cc (verify_bb_vtables): Simplify calls.
gcc/cp/ChangeLog:
* cp-gimplify.cc (fold_builtin_source_location)
* vtable-class-hierarchy.cc (register_all_pairs): Simplify calls to
build_string_literal.
(build_string_from_id): Remove.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-gimplify.cc | 6 | ||||
-rw-r--r-- | gcc/cp/vtable-class-hierarchy.cc | 20 |
2 files changed, 6 insertions, 20 deletions
diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 28c3398..cc8bfad 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3378,10 +3378,10 @@ fold_builtin_source_location (location_t loc) if (const char *fname = LOCATION_FILE (loc)) { fname = remap_macro_filename (fname); - val = build_string_literal (strlen (fname) + 1, fname); + val = build_string_literal (fname); } else - val = build_string_literal (1, ""); + val = build_string_literal (""); } else if (strcmp (n, "_M_function_name") == 0) { @@ -3390,7 +3390,7 @@ fold_builtin_source_location (location_t loc) if (current_function_decl) name = cxx_printable_name (current_function_decl, 2); - val = build_string_literal (strlen (name) + 1, name); + val = build_string_literal (name); } else if (strcmp (n, "_M_line") == 0) val = build_int_cst (TREE_TYPE (field), LOCATION_LINE (loc)); diff --git a/gcc/cp/vtable-class-hierarchy.cc b/gcc/cp/vtable-class-hierarchy.cc index cc1df1e..1e180ea 100644 --- a/gcc/cp/vtable-class-hierarchy.cc +++ b/gcc/cp/vtable-class-hierarchy.cc @@ -467,19 +467,6 @@ check_and_record_registered_pairs (tree vtable_decl, tree vptr_address, return !inserted_something; } -/* Given an IDENTIFIER_NODE, build and return a string literal based on it. */ - -static tree -build_string_from_id (tree identifier) -{ - int len; - - gcc_assert (TREE_CODE (identifier) == IDENTIFIER_NODE); - - len = IDENTIFIER_LENGTH (identifier); - return build_string_literal (len + 1, IDENTIFIER_POINTER (identifier)); -} - /* A class may contain secondary vtables in it, for various reasons. This function goes through the decl chain of a class record looking for any fields that point to secondary vtables, and adding calls to @@ -920,7 +907,7 @@ register_all_pairs (tree body) if (flag_vtv_debug) - str1 = build_string_from_id (DECL_NAME (base_ptr_var_decl)); + str1 = build_string_literal (DECL_NAME (base_ptr_var_decl)); new_type = build_pointer_type (TREE_TYPE (base_ptr_var_decl)); arg1 = build1 (ADDR_EXPR, new_type, base_ptr_var_decl); @@ -953,7 +940,7 @@ register_all_pairs (tree body) if (vtable_decl) { vtable_should_be_output = TREE_ASM_WRITTEN (vtable_decl); - str2 = build_string_from_id (DECL_NAME (vtable_decl)); + str2 = build_string_literal (DECL_NAME (vtable_decl)); } if (vtable_decl && vtable_should_be_output) @@ -1009,8 +996,7 @@ register_all_pairs (tree body) arg2 = build_key_buffer_arg (base_ptr_var_decl); if (str2 == NULL_TREE) - str2 = build_string_literal (strlen ("unknown") + 1, - "unknown"); + str2 = build_string_literal ("unknown"); if (flag_vtv_debug) output_set_info (current->class_info->class_type, |