This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/7226: Spurious "output number 1 not directly addressable" error with asm =m constraint
- From: Trevor Blackwell <tlb at tlb dot blackwells dot net>
- To: gcc-gnats at gcc dot gnu dot org
- Date: Sat, 6 Jul 2002 17:42:20 -0700 (PDT)
- Subject: optimization/7226: Spurious "output number 1 not directly addressable" error with asm =m constraint
>Number: 7226
>Category: optimization
>Synopsis: gcc -O can't compile some asm functions with memory operands
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: ice-on-legal-code
>Submitter-Id: net
>Arrival-Date: Sat Jul 06 17:46:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Trevor Blackwell
>Release: 3.1.1 20020617 (prerelease) [FreeBSD]
>Organization:
>Environment:
System: FreeBSD tlb.blackwells.net 4.5-RELEASE-p2 FreeBSD 4.5-RELEASE-p2 #3: Sat Mar 9 12:32:15 PST 2002 root@tlb.umbrellaresearch.com:/d1/usr-obj/usr/src/sys/TLB i386
host: i386-portbld-freebsd4.5
build: i386-portbld-freebsd4.5
target: i386-portbld-freebsd4.5
configured with: ./..//gcc-20020617/configure --disable-nls --with-gnu-as --with-gnu-ld --with-gxx-include-dir=/usr/local/lib/gcc-lib/i386-portbld-freebsd4.5/3.1.1/include/g++ --disable-libgcj --disable-shared --prefix=/usr/local i386-portbld-freebsd4.5
>Description:
When I compile, I get:
$ g++31 -O -o t-gcc-asm t-gcc-asm.cc
t-gcc-asm.cc: In function `int main()':
t-gcc-asm.cc:13: output number 1 not directly addressable
The asm function below should set foo=13 and bar=14.
It works if you compile with -O0, or if you declare bar volatile.
It works if you add a (pointless) statement &bar; ahead of the asm,
to force bar into memory.
It works if you make it be a C program instead of C++.
gcc 2.95.3 compiles it OK, either as C++ or C.
Presumably the =m constraint isn't forcing the operand to memory like
it should.
I don't see the same problem with only 1 "=m" operand.
>How-To-Repeat:
Compile this C++ program with -O. Add -DFIX1 or -DFIX2 for workarounds.
---- t-gcc-asm.cc ---
extern "C" int printf(const char *, ...);
int main()
{
int foo;
#ifdef FIX1
volatile int bar;
#else
int bar;
#endif
#ifdef FIX2
&bar;
#endif
asm("push %%eax;"
"mov $13, %%eax;"
"mov %%eax, %0;"
"mov $14, %%eax;"
"mov %%eax, %1;"
"pop %%eax;"
: "=m" (foo), "=m" (bar));
printf("foo=%d bar=%d\n",foo,bar);
}
-----------------------
>Fix:
- Declare bar volatile.
- Use a register constraint (but this doesn't work in my application, because
it's already using all available registers.)
- Take the address of bar somewhere in the function.
>Release-Note:
>Audit-Trail:
>Unformatted: