c/4161: gcc c compiler producing incorrect code

norman@arcady.u-net.com norman@arcady.u-net.com
Tue Aug 28 16:36:00 GMT 2001


>Number:         4161
>Category:       c
>Synopsis:       c compiler produces incorrect code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 28 16:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Norman Stevens
>Release:        3.0.1
>Organization:
>Environment:
System: Linux arcady 2.2.16-1 #5 Mon Jun 12 19:43:48 BST 2000 i586 unknown
Architecture: i586

host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../gcc-3.0.1/configure --prefix=/usr i386-pc-linux-gnu : (reconfigured) 
>Description:
	The code generated from the following source is incorrect. The line
	"str = tmp;" seems to be removed by the optimizer. If the code is
	compiled using -O0,  -O1 or -O2 then the output is correct, if the code
	is compiled with -O2 then the output is incorrect. Note that the 
	problem only occurs when the -fPIC and -O2 options are _both_ present.

	With -O2 the output is

	dtd/kdex.dtd
	/kdex.dtd

	without -O2 the output (correct) is

	dtd/kdex.dtd
	dtd/kdex.dtd

>How-To-Repeat:
	gcc -fPIC -O2 -o u u.c

/*********************************************************/
# 1 "u.c"
extern int printf (const char *, ...);

void xmlCleanURI(void *p)
{
}

static int xmlParseRelativeURI(void *p, const char **str)
{
        printf ( "%s\n", *str);
        return 0;
}

static int xmlParseAbsoluteURI(void *p, const char **str)
{
        printf ( "%s\n", *str);
        while (**str != '/' && **str != '\0') (*str)++;
        return 2;
}

int
xmlParseURIReference(void * uri, const char *str)
{
        int ret;
        const char *tmp = str;

        ret = xmlParseAbsoluteURI(uri, &str);
        if (ret != 0)
        {
                xmlCleanURI(uri);
                str = tmp;
                ret = xmlParseRelativeURI(uri, &str);
        }
        return ret;
}

int main (void)
{
        xmlParseURIReference (0, "dtd/kdex.dtd");
        return 0;
}

/*********************************************************/

>Fix:
	Removing the -O2 flag is a workaround.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list