[Bug 1770676] Re: gcc optimizer bug
Bug Watch Updater
1770676 at bugs.launchpad.net
Mon May 14 22:18:27 UTC 2018
** Changed in: gcc
Status: Unknown => New
** Changed in: gcc
Importance: Unknown => Medium
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-5 in Ubuntu.
https://bugs.launchpad.net/bugs/1770676
Title:
gcc optimizer bug
Status in gcc:
New
Status in gcc-5 package in Ubuntu:
Confirmed
Status in gcc-7 package in Ubuntu:
Confirmed
Bug description:
While investigating why cronolog was no longer changing a log symlink
in bionic, I discovered a bug in gcc (reproducable in 7.3.0-16ubuntu3
in bionic and 5.4.0-6ubuntu1~16.04.9 in xenial) for code compiled with
-O2. I have created a simple testcase to reproduce the problem, which
is attached.
You can reproduce the problem with the following:
# ====
set -x
echo "First, we compile and run without optimization:"
gcc -o testcase testcase.c && ./testcase
echo "Then, we compile and run with optimization:"
gcc -O2 -o testcase testcase.c && ./testcase
# ====
Which outputs:
+ echo 'First, we compile and run without optimization:'
First, we compile and run without optimization:
+ gcc -o testcase testcase.c
+ ./testcase
foo in func() is NULL (expected)
foo in func() is NULL (expected)
foo in main() is NULL (expected)
foo in main() is NULL (expected)
+ echo 'Then, we compile and run with optimization:'
Then, we compile and run with optimization:
+ gcc -O2 -o testcase testcase.c
+ ./testcase
foo in func() is NULL (expected)
foo in func() is not NULL (NOT EXPECTED!)
foo in main() is NULL (expected)
foo in main() is NULL (expected)
The problem occurs after calling:
stat(foo, &stat_buf);
Where foo is a NULL pointer. After the return from this function, foo
will no longer be NULL when the code is compiled with optimization -
but only when the pointer is a function parameter of func(). The issue
does not occur when the same codepath is called in main(). (You can
argue calling stat with a NULL pointer is bad behavior, however this
code has been in cronolog, working fine when compiled with -O2, for
years).
I can reproduce this easily on multiple systems, bionic with "gcc
(Ubuntu 7.3.0-16ubuntu3) 7.3.0" and xenial with "gcc (Ubuntu
5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609".
I could not initially reproduce the cronolog testcase in xenial,
leading me to some suspicion that it may be related to retpoline or
other recent compiler changes - and in fact after recompiling cronolog
on xenial I can reproduce the issue there as well.
To manage notifications about this bug go to:
https://bugs.launchpad.net/gcc/+bug/1770676/+subscriptions
More information about the foundations-bugs
mailing list