cfgexpand.c (asm_clobber_reg_is_valid): Also produce error when stack pointer is clobbered.

gcc/
2018-12-11  Dimitar Dimitrov  <dimitar@dinux.eu>

	* cfgexpand.c (asm_clobber_reg_is_valid): Also produce
	error when stack pointer is clobbered.
	(expand_asm_stmt): Refactor clobber check in separate function.

gcc/testsuite/
2018-12-11  Dimitar Dimitrov  <dimitar@dinux.eu>

	* gcc.target/i386/pr52813.c: New test.

From-SVN: r267025
This commit is contained in:
Dimitar Dimitrov 2018-12-11 15:50:51 +00:00 committed by Richard Sandiford
parent f9d4d3cf93
commit 5b238a4591
4 changed files with 53 additions and 8 deletions

View file

@ -1,3 +1,9 @@
2018-12-11 Dimitar Dimitrov <dimitar@dinux.eu>
* cfgexpand.c (asm_clobber_reg_is_valid): Also produce
error when stack pointer is clobbered.
(expand_asm_stmt): Refactor clobber check in separate function.
2018-12-11 Eric Botcazou <botcazou@adacore.com>
* config/rs6000/vxworks.h (RS6000_STARTING_FRAME_OFFSET): Define,

View file

@ -2850,6 +2850,38 @@ tree_conflicts_with_clobbers_p (tree t, HARD_REG_SET *clobbered_regs)
return false;
}
/* Check that the given REGNO spanning NREGS is a valid
asm clobber operand. Some HW registers cannot be
saved/restored, hence they should not be clobbered by
asm statements. */
static bool
asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
{
bool is_valid = true;
HARD_REG_SET regset;
CLEAR_HARD_REG_SET (regset);
add_range_to_hard_reg_set (&regset, regno, nregs);
/* Clobbering the PIC register is an error. */
if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
&& overlaps_hard_reg_set_p (regset, Pmode, PIC_OFFSET_TABLE_REGNUM))
{
/* ??? Diagnose during gimplification? */
error ("PIC register clobbered by %qs in %<asm%>", regname);
is_valid = false;
}
/* Clobbering the STACK POINTER register is an error. */
if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
{
error ("Stack Pointer register clobbered by %qs in %<asm%>", regname);
is_valid = false;
}
return is_valid;
}
/* Generate RTL for an asm statement with arguments.
STRING is the instruction template.
OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
@ -2982,14 +3014,8 @@ expand_asm_stmt (gasm *stmt)
else
for (int reg = j; reg < j + nregs; reg++)
{
/* Clobbering the PIC register is an error. */
if (reg == (int) PIC_OFFSET_TABLE_REGNUM)
{
/* ??? Diagnose during gimplification? */
error ("PIC register clobbered by %qs in %<asm%>",
regname);
return;
}
if (!asm_clobber_reg_is_valid (reg, nregs, regname))
return;
SET_HARD_REG_BIT (clobbered_regs, reg);
rtx x = gen_rtx_REG (reg_raw_mode[reg], reg);

View file

@ -1,3 +1,7 @@
2018-12-11 Dimitar Dimitrov <dimitar@dinux.eu>
* gcc.target/i386/pr52813.c: New test.
2018-12-11 Jakub Jelinek <jakub@redhat.com>
PR target/88425

View file

@ -0,0 +1,9 @@
/* Ensure that stack pointer cannot be an asm clobber. */
/* { dg-do compile { target { ! ia32 } } } */
/* { dg-options "-O2" } */
void
test1 (void)
{
asm volatile ("" : : : "%esp"); /* { dg-error "Stack Pointer register clobbered" } */
}