[Bug tree-optimization/86071] New: -O0 -foptimize-sibling-calls doesn't optimize
Hi-Angel at yandex dot ru
gcc-bugzilla@gcc.gnu.org
Wed Jun 6 15:18:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86071
Bug ID: 86071
Summary: -O0 -foptimize-sibling-calls doesn't optimize
Product: gcc
Version: 8.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: Hi-Angel at yandex dot ru
Target Milestone: ---
# Steps to reproduce:
$ cat test.cpp
struct Node {
Node* children;
};
const Node& descend(const Node& node) {
if (!node.children) {
return node;
} else // not a leaf
return descend(*node.children);
}
int main() {
Node end;
Node ring = Node{new Node{&end}};
end.children = ˚
descend(ring);
}
$ g++ test.cpp -o a -O0 -g3 -foptimize-sibling-calls
$ ./a
[1] 21291 segmentation fault (core dumped) ./a
Running under gdb shows that crash is because of exhausted stack, i.e.
tail-recursion optimization didn't work.
# Additional information
This one testcase actually does work upon replacing -O0 with -O3.
However, I also have a bit bigger testcase, where tail-recursion optimization
doesn't work even with -O3. I wonder, if it's worth a separate bug.
More information about the Gcc-bugs
mailing list