Use volatile store for g_hrFatalError
authorJan Kotas <jkotas@microsoft.com>
Thu, 12 Nov 2015 01:48:49 +0000 (17:48 -0800)
committerJan Kotas <jkotas@microsoft.com>
Thu, 12 Nov 2015 01:48:49 +0000 (17:48 -0800)
src/utilcode/ex.cpp

index d3e0393..e692e13 100644 (file)
@@ -1698,7 +1698,8 @@ void DECLSPEC_NORETURN ThrowOutOfMemory()
     
 #ifndef DACCESS_COMPILE
 
-    g_hrFatalError = COR_E_OUTOFMEMORY;
+    // Use volatile store to prevent compiler from optimizing the static variable away
+    VolatileStoreWithoutBarrier<HRESULT>(&g_hrFatalError, COR_E_OUTOFMEMORY);
 
     // Regular CLR builds - throw our pre-created OOM exception object
     PAL_CPP_THROW(Exception *, Exception::GetOOMException());