I had mysterious bug in loading Vorbis Ogg files on Mac OSX. The first file is loaded correctly, the second crashes in some code that indicates the file is corrupted, the same happens even if I load the same exact file twice.
After long hours of deep debugging inside Vorbis I found out that the bug is caused by the system function "pow" (double power of) returning a (nan) for a completely valid input, and that happens only on the second call to (ov_read), on the first call the same exact values passed to "pow" returns valid result.
8 hours later and lots of Intel x87 documentation reading I found the problem. Long story short there is a function deep inside vorbis "vorbis_ftoi " that uses this assembly code:
__asm__("fistl %0": "=m"(i) : "t"(f));
Which should push and pop on the Intel FPU Stack. However on LLVM it generates this code:
fld QWORD PTR [ebp-0x20]
fist DWORD PTR [ebp-0x14]
Which pushes on the stack but never pops causing an FPU stack overflow. And that's obviously a bug in LLVM
The proper code generated by GCC looks like this:
fld QWORD PTR [ebp-0x20]
fist DWORD PTR [ebp-0xc]
fstp st(0) // pops off the stack
I wasted a day and a half and some bytes of my brian learning some garbage (x87 Instruction Set and Registers) on this, so I though I would share it.
Auday