Bug 20328 - assembly constraints fail unless optimizing code
Summary: assembly constraints fail unless optimizing code
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-05 01:19 UTC by Matthew Dempsky
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Dempsky 2005-03-05 01:19:20 UTC
The following code (taken from L4Ka::Pistachio) compiles correctly on gcc
(3.3.4, 3.3.5, and 3.4.4) when given any optimization level, but fails when you
don't use any:

$ cat foo.c
unsigned char
inb (unsigned long port)
{
  unsigned char tmp;

  if (port < 0x100)
    __asm__ __volatile__ ("inb %w1, %0":"=al" (tmp):"dN" (port));
  else
    __asm__ __volatile__ ("inb %%dx, %0": "=al" (tmp):"d" (port));

  return tmp;
}
$ gcc -c foo.c
foo.c: In function `inb':
foo.c:7: error: impossible constraint in `asm'
foo.c:9: error: impossible constraint in `asm'
$ gcc -c foo.c -O
$
Comment 1 Giovanni Bajo 2005-03-05 01:26:53 UTC
Which target triplet?
Comment 2 Andrew Pinski 2005-03-05 01:31:21 UTC
You don't want the "al" contstraint at all.

Read the docs to figure out which constaint you really want.  the constraint "al" means pick either the 
"a" constraint or the "l" constraint
Comment 3 Matthew Dempsky 2005-03-05 06:44:00 UTC
Subject: Re:  assembly constraints fail unless optimizing code

On Sat, 2005-03-05 at 01:26 +0000, giovannibajo at libero dot it wrote:
> Which target triplet?

i386-pc-linux-gnu

Comment 4 Matthew Dempsky 2005-03-05 06:52:51 UTC
Subject: Re:  assembly constraints fail unless optimizing code

On Sat, 2005-03-05 at 01:31 +0000, pinskia at gcc dot gnu dot org wrote:
> You don't want the "al" contstraint at all.
> 
> Read the docs to figure out which constaint you really want.  the constraint "al" means pick either the 
> "a" constraint or the "l" constraint

The original code's not mine at all, so I don't know what constraint is
actually wanted.  However, after looking through section 5.36 of the gcc
3.4.3 manual, I can't figure out what the "l" constraint means for the
i386 architecture anyways.

So maybe the original code *shouldn't* be using the "=al" constraint,
but either the manual's missing a description of the "l" constraint for
i386 so I can't decide whether it's correct or not, or gcc's not
complaining about an illegal constraint when optimizations are enabled
(or maybe that's an optimization feature?).