This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] - Proper hot/cold partitioning fixes patch.


Zack Weinberg <zack@codesourcery.com> writes:
> In general the use of alloca is discouraged, but this is a perfect
> example of a place where it *should* be used.  Like so:
>
>    assert (cfun && current_function_decl);
>    if (cfun->unlikely_text_section_name)
>      return;
>
>    if (flag_function_sections && DECL_SECTION_NAME (current_function_decl))
>      {
>        name = alloca (TREE_STRING_LENGTH (DECL_SECTION_NAME
>                                           (current_function_decl)));
>        strcpy (name, TREE_STRING_POINTER (DECL_SECTION_NAME
>                                           (current_function_decl)));
>        stripped_name = targetm.strip_name_encoding (name);
>        buffer = alloca (strlen (stripped_name) + 10);
>        strcpy (buffer, stripped_name);
>        strcat (buffer, "_unlikely");
>        cfun->unlikely_text_section_name = ggc_strdup (buffer);
>     }
>   else
>     cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
>
> It's still not pretty, though.  Seems to me there ought to be a better
> way, but I don't know one.

It could probably be simplied slightly by using ACONCAT from
libiberty.h.  E.g.:

        buffer = ACONCAT ((stripped_name, "_unlikely", NULL));

Richard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]