This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/70038] [5.3.0 and 4.9.1]Wrong optimization with -O2


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]