This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/70038] [5.3.0 and 4.9.1]Wrong optimization with -O2
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 02 Mar 2016 07:45:56 +0000
- Subject: [Bug c/70038] [5.3.0 and 4.9.1]Wrong optimization with -O2
- Auto-submitted: auto-generated
- References: <bug-70038-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70038
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to kenlon from comment #2)
> call to stat with a null argument is not the matter,it will return -1,that
> is ok.
> the matter code is:
> (prevlinkname ? "TRUE":"NULL");
>
> if (prevlinkname) {
> ....
> }
>
> it will not judge "prevlinkname".
No call to stat is the issue.
Take the code you have:
if (stat(prevlinkname, &stat_buf) == 0)
{
unlink(prevlinkname);
}
printf("%p %s\n",prevlinkname,(prevlinkname ? "TRUE":"NULL"));
After the call to stat, GCC assumes prevlinkname is non null as it was an
argument to stat; so it does "TRUE" branch of the comparison.
Again calling stat with a NULL argument is undefined so GCC can assume all
calls to stat have a non-null argument.