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

Richard Sandiford rsandifo@redhat.com
Thu Apr 28 11:32:00 GMT 2005


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



More information about the Gcc-patches mailing list