https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88936
Bug ID: 88936 Summary: -fipa-pta breaks bash (incorrect optimisation of recursive static function) Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: slyfox at inbox dot ru CC: marxin at gcc dot gnu.org Target Milestone: --- Initially bug is observed by muffindrake on #gentoo-portage as a series of mysterious bash failures. Here is the minimal reproducer: #include <stdio.h> /* How to reproduce: $ gcc -O2 -Wall -fno-stack-protector main.c -o c-bug && ./c-bug ff(1) = 1 $ gcc -O2 -Wall -fno-stack-protector -fipa-pta main.c -o c-bug-ipa-pta && ./c-bug-ipa-pta ff(1) = 3 */ static long bug (long depth, long * v) { if (depth == 0) { *v = 0; return 1; } long r = 1; long val = bug(depth - 1, &r); return 2 * r + val; } static long ff (long depth) { return bug(depth, (long*)NULL); } int main() { fprintf(stderr, "ff(1) = %ld\n", ff(1)); } Reproducible on 9.0.0 20190120, 8.2.0, 7.4.0, 6.5.0. Not reproducible on 5.5.0. Reproducible on multiple platforms. $ ./xgcc -B. -v Reading specs from ./specs COLLECT_GCC=./xgcc COLLECT_LTO_WRAPPER=./lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc/configure --enable-languages=c,c++ --disable-bootstrap --with-multilib-list=m64 --prefix=/home/slyfox/dev/git/gcc-native/../gcc-native-quick-installed --disable-nls CFLAGS='-O0 -g ' CXXFLAGS='-O0 -g ' --with-sysroot=/usr/x86_64-HEAD-linux-gnu Thread model: posix gcc version 9.0.0 20190120 (experimental) (GCC)