https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83292
Bug ID: 83292 Summary: __builtin_apply() triggers x87 stack exception on 32-bit x86 Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: achurch+gcc at achurch dot org Target Milestone: --- Calling a function with __builtin_apply() on 32-bit x86 causes the next x87 instruction to raise an x87 stack exception, as a side effect of mixing MMX instructions (saving %mm[0-2]) and x87 instructions (fstp after the function call, I presume to pop possible return values off the x87 stack). Note that it's not possible to completely work around this with -mfpmath=sse because fild is still used to load a 64-bit integer (s/int/long long/ in the test case below). The problem occurs at least as far back as GCC 5.4.0; I haven't tested earlier versions. Editing the generated assembly to bracket the __builtin_apply() code with fstenv/fldenv seems to fix the problem. Testcase: ========================== void foo(void) { } int main(void) { __builtin_apply(foo, __builtin_apply_args(), 0); volatile int i = 1; float f = i; return f==1.0f ? 0 : 1; } ==========================