http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57837
Bug ID: 57837 Summary: ARM function pointer tailcall miscompilation regression Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: me at williamgrant dot id.au Created attachment 30469 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30469&action=edit arm.md fix The fix for PR target/19599 in svn trunk r198928 causes predicated function pointer tailcalls for some ARM targets to lose their predicate and execute unconditionally, resulting in a crash or other misbehaviour. I was able to reproduce the miscompilation, manifesting as a segfault, using -march=armv4t -marm -O3, as below: gcc -march=armv4t -marm -O3 -o bx-test bx-test.c ---- void baz() {}; void (*bar)() = baz; void foo(int c) { if (c == 1) { foo(0); } bar(); } int main(int argc, char **argv) { foo(1); } ---- Today's trunk gives the following asm: ---- foo: cmp r0, #1 stmfd sp!, {r4, lr} ldr r4, .L8 ldrne r3, [r4] ldmnefd sp!, {r4, lr} bx r3 @ indirect register sibling call ---- Note the bx to an r3 that is uninitialised when r0 == 1; it should actually be a bxne. The bug in arm.md is fairly clear: the %? is missing from two bx instructions, so the predicate is omitted. After identifying the bad code I discovered that the issue was raised in review, but deemed irrelevant (http://gcc.gnu.org/ml/gcc-patches/2013-05/msg01022.html). The attached patch fixes the bug for me.