From mboxrd@z Thu Jan 1 00:00:00 1970 From: "William M. Brack" To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: optimization/3387: GCC 3.0 optimisation -O2 -fPIC produces incorrect code Date: Fri, 22 Jun 2001 19:56:00 -0000 Message-id: <20010623025605.10340.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg01009.html List-Id: The following reply was made to PR optimization/3387; it has been noted by GNATS. From: "William M. Brack" To: Cc: Subject: Re: optimization/3387: GCC 3.0 optimisation -O2 -fPIC produces incorrect code Date: Sat, 23 Jun 2001 10:50:59 +0800 This is a multi-part message in MIME format. ------=_NextPart_000_0046_01C0FBD2.637B41E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Looking at the bug database for this report, it appears that the attached file was somehow lost during the web submission. If true, please add it to the PR for me; if false, please ignore this (and excuse my ignorance). W. Brack ------=_NextPart_000_0046_01C0FBD2.637B41E0 Content-Type: application/octet-stream; name="bug1.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bug1.c" /*=0D The following program generates incorrect code (judged by reading the = generated=0D assembler source) when compiled with flags -O2 and -fPIC. It seems to = compile=0D correctly with flags -O1 and -fPIC, as well as with flags -O2 only.=0D =0D The critical problem is that the routine "f1" modifies the referenced = param (str),=0D so the restoration of the initial value is required ( "str =3D tmp;" ). = However,=0D the generated code deletes that statement.=0D =0D Please note: This fragment is completely artificial - it is a VERY = reduced excerpt=0D from a reasonably complex program in which the problem caused complete = failure.=0D Any criticism about about "poor coding" will be taken as a personal = insult ;>)=0D */=0D =0D int f1(int uri, char **str);=0D int f2(int uri, char **str);=0D =0D int bug(int uri, char *str) {=0D int ret;=0D char *tmp =3D str; /* Save the initial value of param str */=0D =0D ret =3D f1(uri, &str); /* This routine modifies the value of str = */=0D if (ret !=3D 0) {=0D str =3D tmp; /* Restore the initial value of str */=0D ret =3D f2(uri, &str);=0D }=0D if (ret !=3D 0)=0D return(ret);=0D =0D ret =3D f2(uri, &str);=0D =0D return(0);=0D }=0D ------=_NextPart_000_0046_01C0FBD2.637B41E0--