public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/7565: GCC 2.95.3 rejects valid input.
@ 2002-08-10  2:21 mabs
  0 siblings, 0 replies; only message in thread
From: mabs @ 2002-08-10  2:21 UTC (permalink / raw)
  To: gcc-gnats


>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;
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-08-10  9:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-10  2:21 c/7565: GCC 2.95.3 rejects valid input mabs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).