https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348
Bug ID: 90348
Summary: Small inlined function has local variables in invalid
stack location
Product: gcc
Version: 8.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pieter.wuille at gmail dot com
Target Milestone: ---
Created attachment 46289
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46289&action=edit
Source file to reproduce the problem
In attachment is a small source file that seems to be miscompiled with "-O1
-finline-small-functions".
Tested versions/environments where the issue appears:
* GCC 7.3, Ubuntu 18.04.2, x86_64, "gcc -O1 -finline-small-functions test.i -o
test"
* GCC 8.3, Ubuntu 18.04.2, x86_64, "gcc -O1 -finline-small-functions test.i -o
test"
* GCC 8.3, Ubuntu 18.04.2, x86_64, "gcc -m32 -O1 -finline-small-functions
test.i -o test"
* GCC 9.0, Fedora 30, i686, "gcc -O2 test.i -o test"
In a loop, a 4-byte (or larger) char array "in" is created, and then
increasingly long prefixes initialized to zero. A small inlinable function
"set_one_on_stack" is invoked during the loop that should have no effect (it
sets a local variable "buf" to one in a roundabout way), but apparently the
"buf" variable is given the same stack location as the caller's "in" variable,
overwriting the latter. When compiled incorrectly, an unexpected assertion
occurs.
The test file is a reduced version of an issue observed on some platforms in
the Bitcoin Core unit tests. See
https://github.com/bitcoin/bitcoin/issues/14580 for more details.