From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26582 invoked by alias); 10 Aug 2002 09:06:02 -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 26560 invoked by uid 71); 10 Aug 2002 09:06:01 -0000 Resent-Date: 10 Aug 2002 09:06:01 -0000 Resent-Message-ID: <20020810090601.26559.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, mabs@netcabo.pt Received: (qmail 22998 invoked by uid 61); 10 Aug 2002 08:59:01 -0000 Message-Id: <20020810085901.22997.qmail@sources.redhat.com> Date: Sat, 10 Aug 2002 02:21:00 -0000 From: mabs@netcabo.pt Reply-To: mabs@netcabo.pt To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c/7565: GCC 2.95.3 rejects valid input. X-SW-Source: 2002-08/txt/msg00207.txt.bz2 List-Id: >Number: 7565 >Category: c >Synopsis: GCC 2.95.3 rejects valid input. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Sat Aug 10 02:06:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: mabs@netcabo.pt >Release: gcc version 2.95.3 20010315 (release) >Organization: >Environment: Problem found on a Pentium class computer, 16 MB RAM, running Win98 4.10.1998 and on a Pentium class computer, 64 MB RAM, running Linux 2.4.17. >Description: I have written an inline function using asm. This function copies one char string to another. It's prototype: extern inline int copy(char *target,const char *source); When this function is called twice with the same source parameter, the compiler produces the errors listed below. Using different source variables, even if they have the same value, that is, two different pointers pointing to the same string, the code compiles correctly. This behaviour seems to be independent of the target parameter. Output from ' gcc -v -save-temps -Wall -O exp.c ' : Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs gcc version 2.95.3 20010315 (release) /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/cpp0 -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTIMIZE__ -Wall -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ exp.c exp.i GNU CPP version 2.95.3 20010315 (release) (i386 Linux/ELF) #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/include /usr/include End of search list. The following default directories have been omitted from the search path: /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3 /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../i386-slackware-linux/include End of omitted list. /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/cc1 exp.i -quiet -dumpbase exp.c -O -Wall -version -o exp.s GNU C version 2.95.3 20010315 (release) (i386-slackware-linux) compiled by GNU C version 2.95.3 20010315 (release). exp.c: In function `test': exp.c:17: impossible register constraint in `asm' exp.c:17: impossible register constraint in `asm' exp.c:17: impossible register constraint in `asm' exp.c:17: impossible register constraint in `asm' exp.c:17: impossible register constraint in `asm' exp.c:17: `asm' needs too many reloads >How-To-Repeat: char string[30]="This is a string of length 30."; extern inline int copy(char *target,const char *source) { register int r; asm volatile ( ".intel_syntax noprefix;" "or ecx,-1;" "cld;" "0:;" "lodsb;" "inc ecx;" "stosb;" "test al,al;" "jnz 0b;" ".att_syntax" :"=c" (r),"+D" (target),"+S" (source)::"eax","cc" ); return(r); } void test(void) { char buffer1[64],buffer2[64]; copy(buffer1,string); copy(buffer2,string); return; } >Fix: The problem seems to be avoided if one can use a different pointer to refer to the same string in the second call to function 'copy'. I defined a global variable thusly: char *alternatepointer; And placed a call to a function 'setpointer' just before making the two calls to 'copy'. Function 'setpointer' simply loads the global variable 'alternatepointer' with the address of the string. One can then use the pointer 'string' in the first call to 'copy' and 'alternatepointer' in the second. Function 'setpointer' must be called without explicit reference to 'alternatepointer' (that's why it must be a global variable) and it cannot be inlined together with function 'copy'. Otherwise, this workaround will fail with the same errors. >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="exp.c" Content-Disposition: inline; filename="exp.c" char string[30]="This is a string of length 30."; extern inline int copy(char *target,const char *source) { register int r; asm volatile ( ".intel_syntax noprefix;" "or ecx,-1;" "cld;" "0:;" "lodsb;" "inc ecx;" "stosb;" "test al,al;" "jnz 0b;" ".att_syntax" :"=c" (r),"+D" (target),"+S" (source)::"eax","cc" ); return(r); } void test(void) { char buffer1[64],buffer2[64]; copy(buffer1,string); copy(buffer2,string); return; }