This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] PR inline-asm/8788: Improved constraint checking
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 8 May 2005 23:25:13 -0600 (MDT)
- Subject: [Committed] PR inline-asm/8788: Improved constraint checking
The following patch is my proposed solution to PR inline-asm/8788, which
according to bugzilla is one of GCC's most duplicated PRs.
The problem is that possible to write a dubious statement, such as the
new test case below, where a structure, union or array is given as an
argument to a constraint expecting (or allowing) a register. The current
code in stmt.c's expand_asm_operands first checks whether the constraint
allows registers, and if so, blindly attempt to force the operand into a
register. Unfortunately, for this PR, the operand happens to have mode
BLKmode, which causes an ICE in emit_move_insn when called from force_reg.
The simple fix below is to check that the mode of the operand is not
BLKmode before attempting to force it into a register. In the problematic
case, this allows the code to drop through to the following clauses which
issue a warning if a MEM also isn't a suitable form for the BLKmode value.
Thanks to Zack and DJE on IRC for confirming that there wasn't a more
appropriate macro for whether a mode can be forced to a register. I'm
assuming that TYPE_MODE (type) will never (sanely) be VOIDmode.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures. The new test case
ICEs with mainline, but generates a reasonable error with this patch.
I believe the test case is portable, let me know if it isn't.
Committed to mainline CVS.
2005-05-08 Roger Sayle <roger@eyesopen.com>
PR inline-asm/8788
* stmt.c (expand_asm_operands): Avoid calling force_reg on BLKmode
operands.
* gcc.dg/pr8788-1.c: New testcase.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.421
diff -c -3 -p -r1.421 stmt.c
*** stmt.c 27 Apr 2005 16:02:40 -0000 1.421
--- stmt.c 8 May 2005 22:09:44 -0000
*************** expand_asm_operands (tree string, tree o
*** 877,883 ****
if (asm_operand_ok (op, constraint) <= 0)
{
! if (allows_reg)
op = force_reg (TYPE_MODE (type), op);
else if (!allows_mem)
warning (0, "asm operand %d probably doesn%'t match constraints",
--- 877,883 ----
if (asm_operand_ok (op, constraint) <= 0)
{
! if (allows_reg && TYPE_MODE (type) != BLKmode)
op = force_reg (TYPE_MODE (type), op);
else if (!allows_mem)
warning (0, "asm operand %d probably doesn%'t match constraints",
/* PR inline-asm/8788 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
typedef struct {
long x[6];
} myjmp_buf;
typedef struct {
myjmp_buf regs;
} my_stack;
void switch_to_stack (my_stack *stack){
asm ( /* { dg-error "impossible constraint" } */
/* { dg-warning "asm operand 1" "asm operand 1" { target *-*-* } 14 } */
"\n"
: "+r" (stack->regs)
);
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833