===================================================================
@@ -0,0 +1,39 @@
+/* Test case to check if function foo gets split and the cold function
+ gets a label. */
+/* { dg-require-effective-target freorder } */
+/* { dg-options "-O2 -freorder-blocks-and-partition --save-temps" } */
+
+#define SIZE 10000
+
+const char *sarr[SIZE];
+const char *buf_hot;
+const char *buf_cold;
+
+__attribute__((noinline))
+void
+foo (int path)
+{
+ int i;
+ if (path)
+ {
+ for (i = 0; i < SIZE; i++)
+ sarr[i] = buf_hot;
+ }
+ else
+ {
+ for (i = 0; i < SIZE; i++)
+ sarr[i] = buf_cold;
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ buf_hot = "hello";
+ buf_cold = "world";
+ foo (argc);
+ return 0;
+}
+
+/* { dg-final-use { scan-assembler "foo.cold" } } */
+/* { dg-final-use { cleanup-saved-temps } } */
===================================================================
@@ -1907,6 +1907,9 @@ final_scan_insn (rtx insn, FILE *file, int optimiz
#endif
rtx next;
+ char *cold_function_name;
+ const char *mangled_function_name;
+
insn_counter++;
/* Ignore deleted insns. These can occur when we split insns (due to a
@@ -1934,6 +1937,15 @@ final_scan_insn (rtx insn, FILE *file, int optimiz
targetm.asm_out.function_switched_text_sections (asm_out_file,
current_function_decl,
in_cold_section_p);
+ /* Emit a label for the split cold section. */
+ mangled_function_name
+ = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
+ cold_function_name = XNEWVEC (char,
+ strlen (mangled_function_name) + strlen (".cold") + 1);
+ sprintf (cold_function_name, "%s%s", mangled_function_name,
+ ".cold");
+ ASM_OUTPUT_LABEL (asm_out_file, cold_function_name);
+ XDELETEVEC (cold_function_name);
break;
case NOTE_INSN_BASIC_BLOCK: