From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4391 invoked by alias); 7 Jul 2002 00:46:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 4356 invoked by uid 71); 7 Jul 2002 00:46:03 -0000 Resent-Date: 7 Jul 2002 00:46:03 -0000 Resent-Message-ID: <20020707004603.4354.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, Trevor Blackwell Received: (qmail 3594 invoked from network); 7 Jul 2002 00:42:21 -0000 Received: from unknown (HELO tlb.blackwells.net) (206.111.132.170) by sources.redhat.com with SMTP; 7 Jul 2002 00:42:21 -0000 Received: (from tlb@localhost) by tlb.blackwells.net (8.11.6/8.11.1) id g670gKb46641; Sat, 6 Jul 2002 17:42:20 -0700 (PDT) (envelope-from tlb) Message-Id: <200207070042.g670gKb46641@tlb.blackwells.net> Date: Sat, 06 Jul 2002 17:46:00 -0000 From: Trevor Blackwell To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: optimization/7226: Spurious "output number 1 not directly addressable" error with asm =m constraint X-SW-Source: 2002-07/txt/msg00229.txt.bz2 List-Id: >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: