Anyone want to spot the problem with this optimisation? I'm calling DirectoryContentsList.isStillLoading(). First the unoptimised code:
jassert(directoryList != nullptr); while (directoryList->isStillLoading()) {} 5A171DF4 mov ecx,dword ptr [this] 5A171DF7 add ecx,0F4h 5A171DFD call juce::ScopedPointer<juce::XmlElement>::operator* (5A0B4630h) 5A171E02 mov ecx,eax 5A171E04 call juce::DirectoryContentsList::isStillLoading (5A2834B0h) 5A171E09 movzx eax,al 5A171E0C test eax,eax 5A171E0E je PresetBrowser::refresh+82h (5A171E12h) 5A171E10 jmp PresetBrowser::refresh+64h (5A171DF4h)
And now the optimised:
5A281DE0 mov eax,dword ptr [eax+64h] jassert(directoryList != nullptr); while (directoryList->isStillLoading()) {} 5A281DE3 test eax,eax 5A281DE5 jne PresetBrowser::refresh+53h (5A281DE3h)
If I'm reading this right, it is the digital equivalent of guarding a bank by taking a picture, going to the pub and staring at the picture. Am I reading it right?
- The function isStillLoading() does this: {return fileFindHandle != nullptr;}
- fileFindHandle is updated by another thread.
- The compiler misses this entirely and copies fileFIndHandle directly into eax and then keeps checking eax to see if it's turned into a nullptr yet.
- It doesn't.
I can disable optimisation for this function, but this is so broken ... is there something I'm doing wrong with the complier?
J.