This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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  <>

	PR inline-asm/8788
	* stmt.c (expand_asm_operands): Avoid calling force_reg on BLKmode

	* 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 } */
        : "+r" (stack->regs)

Roger Sayle,                         E-mail:
OpenEye Scientific Software,         WWW:
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]