Bug 163810 - register bool var in inline asm gets assigned a non-existent register
register bool var in inline asm gets assigned a non-existent register
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2005-07-21 07:51 EDT by Benjamin S. Scarlet
Modified: 2007-11-30 17:11 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-07-21 08:46:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Benjamin S. Scarlet 2005-07-21 07:51:21 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.0.4-4 Firefox/1.0.4

Description of problem:
passing a variable of the c++ type bool to an inline asm, it's possible to get the compiler to generate the register names "%dil" or "%sil", which the assembler rejects (I think correctly) as bad register names.

This looks to me like somewhere some person or code has tried to generate a name for the low 8 bits of %esi or %edi, as one might correctly generate %al as a name for the low 8 bits of %eax.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. make a file foo.cpp containing:
bool foo(int *x0, int *x1) {
    register bool b;
    asm volatile(
        "\tsete %[b]"
        : [b] "=r"(b),"+r"(*x1), "+m"(*x0)
        : "cc", "memory", "eax"
    return b;

void bar() {
    int x0 = 0;
    int x1 = 0;
2. compile it with g++ -S -O -c foo.cpp -o -


Actual Results:  I got (amid the rest of the assembly):

		sete %sil

Expected Results:  #APP
		sete %bl

(or some other valid register). Even if my inline asm is completely nonsensical, I don't expect gcc to generate invalid register names.

Additional info:

I haven't gotten this to happen with vanilla gcc-4.0.0 or if the variable type e is changed to "char", but I don't know if that's because it can't happen, or only if a different register is getting chosen of which it is legal to take the low 8-bits.
Comment 1 Jakub Jelinek 2005-07-21 07:55:34 EDT
Your testcase is bogus.  For 8-bit values you need to use q constraint rather
than r, which tells GCC to choose one of the registers that have 8-bit parts
in hardware in -m32 (on x86-64 with -m64 q is the same as r, as all registers
have 8-bit lower parts).
Comment 2 Benjamin S. Scarlet 2005-07-21 08:03:51 EDT
Thanks! (And thanks for the blindingly fast response).

One might argue that since gcc automatically interpreted the type of the
variable to figure out an "l" suffix, it does have enough information to figure
out that part of the constraint itself.

Thanks again though.
Comment 3 Jakub Jelinek 2005-07-21 08:46:06 EDT
asm is a general low level mechanism.  What you are suggesting would be to
clutter it with tons of various architecture specific tweaks.  That's not really
the way to go.

Note You need to log in before you can comment on or make changes to this bug.