[Bug middle-end/113921] Output register of an "asm volatile goto" is incorrectly clobbered/discarded
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Feb 14 19:07:04 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-02-14
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, GCC 11 version:
--- gcc/cfgexpand.c.jj 2023-05-09 12:59:04.381738365 +0200
+++ gcc/cfgexpand.c 2024-02-14 19:56:08.733150432 +0100
@@ -3639,7 +3639,16 @@ expand_asm_stmt (gasm *stmt)
emit_insn (copy_insn (PATTERN (curr)));
rtx_insn *copy = get_insns ();
end_sequence ();
- insert_insn_on_edge (copy, e);
+ if (rtx_insn *prev = e->insns.r)
+ {
+ /* Prepend copy before any other previously
+ inserted insns on the edge rather than append. */
+ e->insns.r = NULL;
+ insert_insn_on_edge (copy, e);
+ insert_insn_on_edge (prev, e);
+ }
+ else
+ insert_insn_on_edge (copy, e);
}
}
}
changes the emitted assembler:
@@ -7328,7 +7328,7 @@ sync_vmcs02_to_vmcs12:
# 0 "" 2
#NO_APP
.L1127:
- xorl %r12d, %r12d
+ movq %rax, %r12
.L1083:
movq %r12, 240(%rbx)
jmp .L1047
@@ -29897,7 +29897,7 @@ nested_vmx_vmexit:
# 0 "" 2
#NO_APP
.L5187:
- xorl %r12d, %r12d
+ movq %rax, %r12
.L5113:
movq %r12, %rdx
movl $7, %esi
which is I believe exactly what we want.
For GCC trunk the patch would be
--- gcc/cfgexpand.cc.jj 2024-02-10 11:25:09.995474027 +0100
+++ gcc/cfgexpand.cc 2024-02-14 19:54:30.811505882 +0100
@@ -3687,7 +3687,16 @@ expand_asm_stmt (gasm *stmt)
copy = get_insns ();
end_sequence ();
}
- insert_insn_on_edge (copy, e);
+ if (rtx_insn *prev = e->insns.r)
+ {
+ /* Prepend copy before any other previously
+ inserted insns on the edge rather than append. */
+ e->insns.r = NULL;
+ insert_insn_on_edge (copy, e);
+ insert_insn_on_edge (prev, e);
+ }
+ else
+ insert_insn_on_edge (copy, e);
}
}
}
and with trunk it triggers (I mean the prev != NULL case) only on the
nested_vmx_vmexit
function and not the other one.
Guess one could try to build whole kernel with instrumented gcc (just add
FILE *f = fopen ("/tmp/asmgoto", "a");
fprintf (f, "%s %s\n", main_input_filename ? main_input_filename : "-",
current_function_name ());
fclose (f);
next to the e->insns.r = NULL; in the patch or so) to find out what else it
affects.
More information about the Gcc-bugs
mailing list