Reenable class-memaccess warning (#74363)
authorAaron Robinson <arobins@microsoft.com>
Thu, 25 Aug 2022 20:23:56 +0000 (13:23 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Aug 2022 20:23:56 +0000 (13:23 -0700)
* Reenable class-memaccess warning

* Match x64 logic in emitarm.cpp

* Make GCProtect sections with "gc" variable consistent

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
56 files changed:
eng/native/configurecompiler.cmake
src/coreclr/classlibnative/bcltype/system.cpp
src/coreclr/debug/daccess/request.cpp
src/coreclr/debug/daccess/request_common.h
src/coreclr/debug/di/dbgtransportmanager.cpp
src/coreclr/debug/ee/controller.cpp
src/coreclr/debug/ee/funceval.cpp
src/coreclr/debug/inc/dbgappdomain.h
src/coreclr/debug/inc/dbgtransportsession.h
src/coreclr/debug/shared/dbgtransportsession.cpp
src/coreclr/gc/gc.cpp
src/coreclr/gc/gcpriv.h
src/coreclr/gc/handletable.cpp
src/coreclr/ilasm/asmman.cpp
src/coreclr/ilasm/asmman.hpp
src/coreclr/ilasm/asmtemplates.h
src/coreclr/ilasm/assembler.cpp
src/coreclr/ilasm/assembler.h
src/coreclr/ildasm/dis.h
src/coreclr/ildasm/dman.cpp
src/coreclr/inc/arraylist.h
src/coreclr/inc/corhlpr.cpp
src/coreclr/jit/block.cpp
src/coreclr/jit/compiler.cpp
src/coreclr/jit/emitarm.cpp
src/coreclr/jit/fginline.cpp
src/coreclr/jit/hashbv.cpp
src/coreclr/jit/lclvars.cpp
src/coreclr/jit/morph.cpp
src/coreclr/nativeaot/Runtime/eventtrace.cpp
src/coreclr/vm/amd64/gmscpu.h
src/coreclr/vm/appdomain.cpp
src/coreclr/vm/appdomainnative.cpp
src/coreclr/vm/assemblybinder.cpp
src/coreclr/vm/assemblynative.cpp
src/coreclr/vm/cachelinealloc.cpp
src/coreclr/vm/cachelinealloc.h
src/coreclr/vm/callsiteinspect.cpp
src/coreclr/vm/clrex.cpp
src/coreclr/vm/clrtocomcall.cpp
src/coreclr/vm/comdelegate.cpp
src/coreclr/vm/comutilnative.cpp
src/coreclr/vm/customattribute.cpp
src/coreclr/vm/eventreporter.cpp
src/coreclr/vm/eventtrace.cpp
src/coreclr/vm/excep.cpp
src/coreclr/vm/exceptionhandling.cpp
src/coreclr/vm/interoplibinterface_comwrappers.cpp
src/coreclr/vm/interoplibinterface_objc.cpp
src/coreclr/vm/invokeutil.cpp
src/coreclr/vm/loaderallocator.cpp
src/coreclr/vm/multicorejit.cpp
src/coreclr/vm/stringliteralmap.cpp
src/coreclr/vm/syncblk.h
src/coreclr/vm/threads.cpp
src/coreclr/vm/weakreferencenative.cpp

index 0642fcc..9594de5 100644 (file)
@@ -451,7 +451,6 @@ if (CLR_CMAKE_HOST_UNIX)
     add_compile_options(-Wno-uninitialized)
     add_compile_options(-Wno-strict-aliasing)
     add_compile_options(-Wno-array-bounds)
-    add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>)
     add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-misleading-indentation>)
     add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-stringop-overflow>)
     add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-restrict>)
index 2f1387d..f0c4877 100644 (file)
@@ -162,14 +162,12 @@ void SystemNative::GenericFailFast(STRINGREF refMesgString, EXCEPTIONREF refExce
         EXCEPTIONREF refExceptionForWatsonBucketing;
         STRINGREF refErrorSourceString;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-
-    GCPROTECT_BEGIN(gc);
-
     gc.refMesgString = refMesgString;
     gc.refExceptionForWatsonBucketing = refExceptionForWatsonBucketing;
     gc.refErrorSourceString = refErrorSourceString;
 
+    GCPROTECT_BEGIN(gc);
+
     // Managed code injected FailFast maps onto the unmanaged version
     // (EEPolicy::HandleFatalError) in the following manner: the exit code is
     // always set to COR_E_FAILFAST and the address passed (usually a failing
index f3bd9da..88c1c03 100644 (file)
@@ -2892,7 +2892,7 @@ ClrDataAccess::GetOOMStaticData(struct DacpOomData *oomData)
 
     SOSDacEnter();
 
-    memset(oomData, 0, sizeof(DacpOomData));
+    *oomData = {};
 
     if (!GCHeapUtilities::IsServerHeap())
     {
@@ -2921,7 +2921,7 @@ ClrDataAccess::GetOOMData(CLRDATA_ADDRESS oomAddr, struct DacpOomData *data)
         return E_INVALIDARG;
 
     SOSDacEnter();
-    memset(data, 0, sizeof(DacpOomData));
+    *data = {};
 
     if (!GCHeapUtilities::IsServerHeap())
         hr = E_FAIL; // doesn't make sense to call this on WKS mode
@@ -2974,7 +2974,7 @@ ClrDataAccess::GetGCInterestingInfoStaticData(struct DacpGCInterestingInfoData *
     static_assert_no_msg(DAC_MAX_GC_MECHANISM_BITS_COUNT == MAX_GC_MECHANISM_BITS_COUNT);
 
     SOSDacEnter();
-    memset(data, 0, sizeof(DacpGCInterestingInfoData));
+    *data = {};
 
     if (g_heap_type != GC_HEAP_SVR)
     {
@@ -3007,7 +3007,7 @@ ClrDataAccess::GetGCInterestingInfoData(CLRDATA_ADDRESS interestingInfoAddr, str
         return E_INVALIDARG;
 
     SOSDacEnter();
-    memset(data, 0, sizeof(DacpGCInterestingInfoData));
+    *data = {};
 
     if (!GCHeapUtilities::IsServerHeap())
         hr = E_FAIL; // doesn't make sense to call this on WKS mode
index e6ab53d..95488cb 100644 (file)
@@ -44,7 +44,7 @@ HeapTableIndex(DPTR(unused_gc_heap**) heaps, size_t index)
 
 // field_offset = g_gcDacGlobals->gc_heap_field_offsets
 // p_field_offset = field_offset[field_index]
-// p_field = BASE + p_field_offset 
+// p_field = BASE + p_field_offset
 // field_index++
 #define LOAD_BASE(field_name, field_type)                                                    \
     DPTR(int) p_##field_name##_offset = TableIndex(field_offsets, field_index, sizeof(int)); \
@@ -114,8 +114,7 @@ inline bool IsRegionGCEnabled()
 inline dac_gc_heap
 LoadGcHeapData(TADDR heap)
 {
-    dac_gc_heap result;
-    memset(&result, 0, sizeof(dac_gc_heap));
+    dac_gc_heap result = {};
 
     DPTR(int) field_offsets = g_gcDacGlobals->gc_heap_field_offsets;
     int field_index = 0;
@@ -163,9 +162,7 @@ inline void EnumGcHeap(TADDR heap)
 inline dac_generation
 LoadGeneration(TADDR generation)
 {
-    dac_generation result;
-    memset(&result, 0, sizeof(dac_generation));
-
+    dac_generation result = {};
     DPTR(int) field_offsets = g_gcDacGlobals->generation_field_offsets;
     int field_index = 0;
 
index 3773414..27501d8 100644 (file)
@@ -13,8 +13,9 @@
 DbgTransportTarget *g_pDbgTransportTarget = NULL;
 
 DbgTransportTarget::DbgTransportTarget()
+    : m_pProcessList{}
+    , m_sLock{}
 {
-    memset(this, 0, sizeof(*this));
 }
 
 // Initialization routine called only by the DbgTransportManager.
index cd955ed..7400ad4 100644 (file)
@@ -368,7 +368,7 @@ void ControllerStackInfo::SetReturnFrameWithActiveFrame()
 
     // Invalidate the active frame.
     m_activeFound = false;
-    memset(&(m_activeFrame), 0, sizeof(m_activeFrame));
+    m_activeFrame = {};
     m_activeFrame.fp = LEAF_MOST_FRAME;
 }
 
index 82fe538..33b00b5 100644 (file)
@@ -3301,7 +3301,7 @@ static void DoNormalFuncEval( DebuggerEval *pDE,
         ThrowHR(COR_E_OVERFLOW);
     }
     FuncEvalArgInfo * pFEArgInfo = (FuncEvalArgInfo *)_alloca(cbAllocSize);
-    memset(pFEArgInfo, 0, cbAllocSize);
+    *pFEArgInfo = {};
 
     GatherFuncEvalArgInfo(pDE, mSig, argData, pFEArgInfo);
 
@@ -3483,7 +3483,7 @@ static void GCProtectArgsAndDoNormalFuncEval(DebuggerEval *pDE,
         ThrowHR(COR_E_OVERFLOW);
     }
     OBJECTREF * pObjectRefArray = (OBJECTREF*)_alloca(cbAllocSize);
-    memset(pObjectRefArray, 0, cbAllocSize);
+    *pObjectRefArray = {};
     GCPROTECT_ARRAY_BEGIN(*pObjectRefArray, pDE->m_argCount);
 
     //
index 7b7c362..92e0a5f 100644 (file)
@@ -283,7 +283,7 @@ struct AppDomainEnumerationIPCBlock
         pADInfo->FreeEntry();
 
 #ifdef _DEBUG
-        memset(pADInfo, 0, sizeof(AppDomainInfo));
+        *pADInfo = {};
 #endif
 
         // decrement the used slot count
index b5cc233..71c50c1 100644 (file)
@@ -305,7 +305,7 @@ class DbgTransportSession
 {
 public:
     // No real work done in the constructor. Use Init() instead.
-    DbgTransportSession();
+    DbgTransportSession() = default;
 
     // Cleanup what is allocated/created in Init()
     ~DbgTransportSession();
@@ -422,7 +422,7 @@ private:
     // error is raised) and which incoming messages are valid.
     enum SessionState
     {
-        SS_Closed,      // No session and no attempt is being made to form one
+        SS_Closed = 0,  // No session and no attempt is being made to form one
         SS_Opening_NC,  // Session is being formed but no connection is established yet
         SS_Opening,     // Session is being formed, the low level connection is in place
         SS_Open,        // Session is fully formed and normal transport messages can be sent and received
index 47f7c3f..259e45f 100644 (file)
@@ -31,13 +31,6 @@ DbgTransportSession *g_pDbgTransport = NULL;
 #include "ddmarshalutil.h"
 #endif // !RIGHT_SIDE_COMPILE
 
-// No real work done in the constructor. Use Init() instead.
-DbgTransportSession::DbgTransportSession()
-{
-    m_ref = 1;
-    m_eState = SS_Closed;
-}
-
 DbgTransportSession::~DbgTransportSession()
 {
     DbgTransportLog(LC_Proxy, "DbgTransportSession::~DbgTransportSession() called");
@@ -81,7 +74,7 @@ HRESULT DbgTransportSession::Init(DebuggerIPCControlBlock *pDCB, AppDomainEnumer
 
     // Start with a blank slate so that Shutdown() on a partially initialized instance will only do the
     // cleanup necessary.
-    memset(this, 0, sizeof(*this));
+    *this = {};
 
     // Because of the above memset the embedded classes/structs need to be reinitialized especially
     // the two way pipe; it expects the in/out handles to be -1 instead of 0.
index 53a4dac..fd9b9b0 100644 (file)
@@ -13662,8 +13662,8 @@ gc_heap::init_semi_shared()
 
     memset (full_gc_counts, 0, sizeof (full_gc_counts));
 
-    memset (&last_ephemeral_gc_info, 0, sizeof (last_ephemeral_gc_info));
-    memset (&last_full_blocking_gc_info, 0, sizeof (last_full_blocking_gc_info));
+    last_ephemeral_gc_info = {};
+    last_full_blocking_gc_info = {};
 #ifdef BACKGROUND_GC
     memset (&last_bgc_info, 0, sizeof (last_bgc_info));
 #endif //BACKGROUND_GC
@@ -14029,7 +14029,7 @@ gc_heap::init_gc_heap (int h_number)
 #ifdef MULTIPLE_HEAPS
 #ifdef _DEBUG
     memset (committed_by_oh_per_heap, 0, sizeof (committed_by_oh_per_heap));
-#endif    
+#endif
 
     g_heaps [h_number] = this;
 
@@ -20852,7 +20852,7 @@ BOOL gc_heap::should_proceed_with_gc()
             // The no_gc mode was already in progress yet we triggered another GC,
             // this effectively exits the no_gc mode.
             restore_data_for_no_gc();
-            
+
             memset (&current_no_gc_region_info, 0, sizeof (current_no_gc_region_info));
         }
         else
@@ -28763,7 +28763,7 @@ uint8_t* gc_heap::find_next_marked (uint8_t* x, uint8_t* end,
 #ifdef FEATURE_EVENT_TRACE
 void gc_heap::init_bucket_info()
 {
-    memset (bucket_info, 0, sizeof (bucket_info));
+    *bucket_info = {};
 }
 
 void gc_heap::add_plug_in_condemned_info (generation* gen, size_t plug_size)
index 75b2388..c70ea95 100644 (file)
@@ -648,7 +648,7 @@ struct etw_bucket_info
     uint32_t count;
     size_t size;
 
-    etw_bucket_info() {}
+    etw_bucket_info() = default;
 
     void set (uint16_t _index, uint32_t _count, size_t _size)
     {
index a5cfa3b..0af5d3e 100644 (file)
@@ -111,7 +111,7 @@ HHANDLETABLE HndCreateHandleTable(const uint32_t *pTypeFlags, uint32_t uTypeCoun
     if (pTable == NULL)
         return NULL;
 
-    memset (pTable, 0, dwSize);
+    memset ((void*)pTable, 0, dwSize);
 
     // allocate the initial handle segment
     pTable->pSegmentList = SegmentAlloc(pTable);
index 447267d..18d78a2 100644 (file)
@@ -166,13 +166,12 @@ void    AsmMan::AddFile(_In_ __nullterminated char* szName, DWORD dwAttr, BinStr
     Assembler* pAsm = (Assembler*)m_pAssembler;
     if(tmp==NULL)
     {
-        tmp = new AsmManFile;
+        tmp = new (nothrow) AsmManFile();
         if(tmp==NULL)
         {
             pAsm->report->error("\nOut of memory!\n");
             return;
         }
-        memset(tmp,0,sizeof(AsmManFile));
         if((dwAttr & 0x80000000)!=0) pAsm->m_fEntryPointPresent = TRUE;
         tmp->szName = szName;
         tmp->dwAttr = dwAttr;
@@ -256,9 +255,8 @@ void    AsmMan::StartAssembly(_In_ __nullterminated char* szName, _In_opt_z_ cha
     }
     else
     {
-        if((m_pCurAsmRef = new AsmManAssembly))
+        if((m_pCurAsmRef = new (nothrow) AsmManAssembly()))
         {
-            memset(m_pCurAsmRef,0,sizeof(AsmManAssembly));
             m_pCurAsmRef->usVerMajor = (USHORT)0xFFFF;
             m_pCurAsmRef->usVerMinor = (USHORT)0xFFFF;
             m_pCurAsmRef->usBuild = (USHORT)0xFFFF;
@@ -676,9 +674,8 @@ void    AsmMan::SetAssemblyAutodetect()
 
 void    AsmMan::StartComType(_In_ __nullterminated char* szName, DWORD dwAttr)
 {
-    if((m_pCurComType = new AsmManComType))
+    if((m_pCurComType = new (nothrow) AsmManComType()))
     {
-        memset(m_pCurComType,0,sizeof(AsmManComType));
         m_pCurComType->szName = szName;
         m_pCurComType->dwAttr = dwAttr;
         m_pCurComType->m_fNew = TRUE;
index 972c838..99cfc57 100644 (file)
@@ -17,12 +17,7 @@ struct AsmManFile
     BinStr* pHash;
     BOOL    m_fNew;
     CustomDescrList m_CustomDescrList;
-    AsmManFile()
-    {
-        szName = NULL;
-        pHash = NULL;
-        m_fNew = TRUE;
-    }
+    AsmManFile() = default;
     ~AsmManFile()
     {
         if(szName)  delete szName;
@@ -56,28 +51,16 @@ struct AsmManAssembly
        USHORT  usVerMinor;
        USHORT  usBuild;
        USHORT  usRevision;
-    AsmManAssembly()
+    AsmManAssembly() = default;
+    ~AsmManAssembly()
     {
-    /*
-        usVerMajor = usVerMinor = usBuild = usRevision = 0xFFFF;
-        szName = szAlias = NULL;
-        dwAlias = dwAttr = 0;
-        tkTok = 0;
-        pPublicKey = pPublicKeyToken =pHashBlob = pLocale = NULL;
-        ulHashAlgorithm = 0;
-        m_fNew = TRUE;
-        isAutodetect = isRef = FALSE;
-    */
+        if(szAlias && (szAlias != szName)) delete [] szAlias;
+        if(szName) delete [] szName;
+        if(pPublicKey) delete pPublicKey;
+        if(pPublicKeyToken) delete pPublicKeyToken;
+        if(pHashBlob) delete pHashBlob;
+        if(pLocale) delete pLocale;
     }
-       ~AsmManAssembly()
-       {
-               if(szAlias && (szAlias != szName)) delete [] szAlias;
-               if(szName) delete [] szName;
-               if(pPublicKey) delete pPublicKey;
-               if(pPublicKeyToken) delete pPublicKeyToken;
-               if(pHashBlob) delete pHashBlob;
-               if(pLocale) delete pLocale;
-       }
     int ComparedTo(AsmManAssembly* pX){ return strcmp(szAlias,pX->szAlias); }
 };
 //typedef SORTEDARRAY<AsmManAssembly> AsmManAssemblyList;
index 3790896..cde4944 100644 (file)
@@ -519,7 +519,7 @@ public:
             {
                 alloc_count++;
                 pRet = &bucket[i];
-                memset(pRet, 0, sizeof(RBNODE<T>));
+                *pRet = {};
                 pRet->dwInUse = 1;
                 return pRet;
             }
@@ -551,10 +551,7 @@ private:
     RBNODEBUCKET<T> base;
 
 public:
-    RBNODEPOOL()
-    {
-        memset(&base,0,sizeof(RBNODEBUCKET<T>));
-    };
+    RBNODEPOOL() = default;
 
     RBNODE<T>* AllocNode()
     {
@@ -681,7 +678,7 @@ private:
     };
 
 public:
-    RBTREE()
+    RBTREE() : NodePool{}
     {
         pRoot = NodePool.AllocNode();
         InitSpecNode(pRoot);
index 4aa217a..6984c18 100644 (file)
@@ -1026,7 +1026,7 @@ void Assembler::EmitByte(int val)
 void Assembler::NewSEHDescriptor(void) //sets m_SEHD
 {
     m_SEHDstack.PUSH(m_SEHD);
-    m_SEHD = new SEH_Descriptor;
+    m_SEHD = new (nothrow) SEH_Descriptor();
     if(m_SEHD == NULL) report->error("Failed to allocate SEH descriptor\n");
 }
 /**************************************************************************/
@@ -1886,9 +1886,8 @@ void Assembler::ResetEvent(__inout_z __inout char* szName, mdToken typeSpec, DWO
         report->error("Event '%s...' -- name too long (%d characters).\n",szName,strlen(szName));
         szName[MAX_CLASSNAME_LENGTH-1] = c;
     }
-    if((m_pCurEvent = new EventDescriptor))
+    if((m_pCurEvent = new (nothrow) EventDescriptor()))
     {
-        memset(m_pCurEvent,0,sizeof(EventDescriptor));
         m_pCurEvent->m_tdClass = m_pCurClass->m_cl;
         m_pCurEvent->m_szName = szName;
         m_pCurEvent->m_dwAttr = dwAttr;
@@ -1943,13 +1942,12 @@ void Assembler::ResetProp(__inout_z __inout char * szName, BinStr* bsType, DWORD
         report->error("Property '%s...' -- name too long (%d characters).\n",szName,strlen(szName));
         szName[MAX_CLASSNAME_LENGTH-1] = c;
     }
-    m_pCurProp = new PropDescriptor;
+    m_pCurProp = new (nothrow) PropDescriptor();
     if(m_pCurProp == NULL)
     {
         report->error("Failed to allocate Property Descriptor\n");
         return;
     }
-    memset(m_pCurProp,0,sizeof(PropDescriptor));
     m_pCurProp->m_tdClass = m_pCurClass->m_cl;
     m_pCurProp->m_szName = szName;
     m_pCurProp->m_dwAttr = dwAttr;
index 43ecddf..eaf6d9d 100644 (file)
@@ -287,10 +287,7 @@ struct SEH_Descriptor
         mdTypeRef   cException; // what to catch
     };
 
-    SEH_Descriptor()
-    {
-        memset(this, 0, sizeof(*this));
-    }
+    SEH_Descriptor() = default;
 };
 
 
@@ -340,6 +337,7 @@ struct EventDescriptor
     mdEvent             m_edEventTok;
     BOOL                m_fNew;
     CustomDescrList     m_CustomDescrList;
+    EventDescriptor() = default;
     ~EventDescriptor() { m_tklOthers.RESET(false); };
 };
 typedef FIFO<EventDescriptor> EventDList;
@@ -360,6 +358,7 @@ struct PropDescriptor
     mdProperty          m_pdPropTok;
     BOOL                m_fNew;
     CustomDescrList     m_CustomDescrList;
+    PropDescriptor() = default;
     ~PropDescriptor() { m_tklOthers.RESET(false); };
 };
 typedef FIFO<PropDescriptor> PropDList;
index 8f66cd4..6aef96a 100644 (file)
@@ -94,7 +94,13 @@ struct LocalComTypeDescr
     mdToken             tkImplementation;
     WCHAR*              wzName;
     DWORD               dwFlags;
-    LocalComTypeDescr()  { wzName=NULL; };
+    LocalComTypeDescr(mdExportedType exportedType, mdTypeDef typeDef, mdToken impl, WCHAR* name, DWORD flags)
+        : tkComTypeTok{exportedType}
+        , tkTypeDef{typeDef}
+        , tkImplementation{impl}
+        , wzName{name}
+        , dwFlags{flags}
+    { };
     ~LocalComTypeDescr() { if(wzName) SDELETE(wzName); };
 };
 
index e462fbc..60704b6 100644 (file)
@@ -573,15 +573,9 @@ void DumpComTypes(void* GUICookie)
                                                                 &tkTypeDef,         // [OUT] TypeDef token within the file.
                                                                 &dwFlags)))         // [OUT] Flags.
                 {
-                    LocalComTypeDescr* pCTD = new LocalComTypeDescr;
-                    memset(pCTD,0,sizeof(LocalComTypeDescr));
-                    pCTD->tkComTypeTok = rComTypeTok[ix];
-                    pCTD->tkTypeDef = tkTypeDef;
-                    pCTD->tkImplementation = tkImplementation;
-                    pCTD->wzName = new WCHAR[ulNameLen+1];
+                    LocalComTypeDescr* pCTD = new LocalComTypeDescr(rComTypeTok[ix], tkTypeDef, tkImplementation, new WCHAR[ulNameLen+1], dwFlags);
                     memcpy(pCTD->wzName,wzName,ulNameLen*sizeof(WCHAR));
                     pCTD->wzName[ulNameLen] = 0;
-                    pCTD->dwFlags = dwFlags;
 
                     if (g_pLocalComType == NULL)
                     {
index e4e0082..f2ffe29 100644 (file)
@@ -226,14 +226,16 @@ class ArrayListBase
             return m_block != NULL;
         }
 
+#ifndef DACCESS_COMPILE
         void ClearUnusedMemory()
         {
             if (m_remaining < m_block->m_blockSize)
-                ZeroMemory(&(m_block->m_array[m_remaining]), (m_block->m_blockSize - m_remaining) * sizeof(void*));
+                ZeroMemory(m_block->m_array + m_remaining, (m_block->m_blockSize - m_remaining) * sizeof(void*));
 #ifdef HOST_64BIT
             m_block->m_padding = 0;
-#endif
+#endif // HOST_64BIT
         }
+#endif // DACCESS_COMPILE
 
         void **GetNextPtr()
         {
index e42d45e..9808fee 100644 (file)
@@ -32,9 +32,9 @@ extern "C" {
 
 void __stdcall DecoderInit(void *pThis, COR_ILMETHOD *header)
 {
+    memset(pThis, 0, sizeof(COR_ILMETHOD_DECODER));
     COR_ILMETHOD_DECODER *decoder = (COR_ILMETHOD_DECODER *)pThis;
 
-    memset(decoder, 0, sizeof(COR_ILMETHOD_DECODER));
     if (header->Tiny.IsTiny())
     {
         decoder->SetMaxStack(header->Tiny.GetMaxStack());
index b30641d..041a0f6 100644 (file)
@@ -1451,7 +1451,7 @@ BasicBlock* Compiler::bbNewBasicBlock(BBjumpKinds jumpKind)
 
     // TODO-Throughput: The following memset is pretty expensive - do something else?
     // Note that some fields have to be initialized to 0 (like bbFPStateX87)
-    memset(block, 0, sizeof(*block));
+    memset((void*)block, 0, sizeof(*block));
 
     // scopeInfo needs to be able to differentiate between blocks which
     // correspond to some instrs (and so may have some LocalVarInfo
index a04d516..818c8bd 100644 (file)
@@ -2368,10 +2368,7 @@ unsigned ReinterpretHexAsDecimal(unsigned in)
 
 void Compiler::compInitOptions(JitFlags* jitFlags)
 {
-#ifdef UNIX_AMD64_ABI
-    opts.compNeedToAlignFrame = false;
-#endif // UNIX_AMD64_ABI
-    memset(&opts, 0, sizeof(opts));
+    opts = {};
 
     if (compIsForInlining())
     {
index fc45a76..a546d5a 100644 (file)
@@ -7739,7 +7739,7 @@ void emitter::emitDispLargeJmp(
     // Next, display the unconditional branch
 
     // Reset the local instrDesc
-    memset(&idJmp, 0, sizeof(idJmp));
+    memset(pidJmp, 0, sizeof(instrDescJmp));
 
     pidJmp->idIns(INS_b);
     pidJmp->idInsFmt(IF_T2_J2);
index 7c8cdd2..d0b29da 100644 (file)
@@ -895,8 +895,7 @@ void Compiler::fgInvokeInlineeCompiler(GenTreeCall* call, InlineResult* inlineRe
     noway_assert(opts.OptEnabled(CLFLG_INLINING));
 
     // This is the InlineInfo struct representing a method to be inlined.
-    InlineInfo inlineInfo;
-    memset(&inlineInfo, 0, sizeof(inlineInfo));
+    InlineInfo            inlineInfo{};
     CORINFO_METHOD_HANDLE fncHandle = call->gtCallMethHnd;
 
     inlineInfo.fncHandle              = fncHandle;
index f24b0e4..a706f06 100644 (file)
@@ -383,7 +383,7 @@ hashBv* hashBv::Create(Compiler* compiler)
     else
     {
         result = new (compiler, CMK_hashBv) hashBv(compiler);
-        memset(result, 0, sizeof(hashBv));
+        memset((void*)result, 0, sizeof(hashBv));
         result->nodeArr = result->initialVector;
     }
 
index cb844b3..78bf365 100644 (file)
@@ -227,7 +227,7 @@ void Compiler::lvaInitTypeRef()
 
     lvaTable         = getAllocator(CMK_LvaTable).allocate<LclVarDsc>(lvaTableCnt);
     size_t tableSize = lvaTableCnt * sizeof(*lvaTable);
-    memset(lvaTable, 0, tableSize);
+    memset((void*)lvaTable, 0, tableSize);
     for (unsigned i = 0; i < lvaTableCnt; i++)
     {
         new (&lvaTable[i], jitstd::placement_t()) LclVarDsc(); // call the constructor.
index 2e638b2..d6d8e4c 100644 (file)
@@ -5688,7 +5688,7 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result,
         // Undo some changes made in anticipation of inlining...
 
         // Zero out the used locals
-        memset(lvaTable + startVars, 0, (lvaCount - startVars) * sizeof(*lvaTable));
+        memset((void*)(lvaTable + startVars), 0, (lvaCount - startVars) * sizeof(*lvaTable));
         for (unsigned i = startVars; i < lvaCount; i++)
         {
             new (&lvaTable[i], jitstd::placement_t()) LclVarDsc(); // call the constructor.
index d0e861b..5cdd8c9 100644 (file)
@@ -3842,7 +3842,9 @@ void ETW::ExceptionLog::ExceptionThrown(CrawlFrame* pCf, BOOL bIsReThrownExcepti
             OBJECTREF innerExceptionObj;
             STRINGREF exceptionMessageRef;
         } gc;
-        ZeroMemory(&gc, sizeof(gc));
+        gc.exceptionObj = NULL;
+        gc.innerExceptionObj = NULL;
+        gc.exceptionMessageRef = NULL;
         GCPROTECT_BEGIN(gc);
 
         gc.exceptionObj = pThread->GetThrowable();
index 985a8c1..9836f03 100644 (file)
@@ -31,7 +31,7 @@ struct MachState
     MachState()
     {
         LIMITED_METHOD_DAC_CONTRACT;
-        INDEBUG(memset(this, 0xCC, sizeof(MachState));)
+        INDEBUG(memset((void*)this, 0xCC, sizeof(MachState));)
     }
 
     bool   isValid()    { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(dac_cast<TADDR>(_pRetAddr) != INVALID_POINTER_CC); return(_pRetAddr != 0); }
index b8b5ab4..90ec6df 100644 (file)
@@ -3747,10 +3747,10 @@ void AppDomain::RaiseLoadingAssemblyEvent(DomainAssembly *pAssembly)
     {
         if (CoreLibBinder::GetField(FIELD__ASSEMBLYLOADCONTEXT__ASSEMBLY_LOAD)->GetStaticOBJECTREF() != NULL)
         {
-            struct _gc {
+            struct {
                 OBJECTREF    orThis;
             } gc;
-            ZeroMemory(&gc, sizeof(gc));
+            gc.orThis = NULL;
 
             ARG_SLOT args[1];
             GCPROTECT_BEGIN(gc);
@@ -3833,14 +3833,14 @@ AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pThrowable, BOOL isTerminatin
     if (orDelegate == NULL)
         return FALSE;
 
-    struct _gc {
+    struct {
         OBJECTREF Delegate;
         OBJECTREF Sender;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.Delegate = orDelegate;
+    gc.Sender = NULL;
 
     GCPROTECT_BEGIN(gc);
-    gc.Delegate = orDelegate;
     if (orDelegate != NULL)
     {
         DistributeUnhandledExceptionReliably(&gc.Delegate, &gc.Sender, pThrowable, isTerminating);
@@ -4347,11 +4347,12 @@ DomainAssembly* AppDomain::RaiseTypeResolveEventThrowing(DomainAssembly* pAssemb
 
     GCX_COOP();
 
-    struct _gc {
+    struct {
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.AssemblyRef = NULL;
+    gc.str = NULL;
 
     GCPROTECT_BEGIN(gc);
 
@@ -4404,11 +4405,12 @@ Assembly* AppDomain::RaiseResourceResolveEvent(DomainAssembly* pAssembly, LPCSTR
 
     GCX_COOP();
 
-    struct _gc {
+    struct {
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.AssemblyRef = NULL;
+    gc.str = NULL;
 
     GCPROTECT_BEGIN(gc);
 
@@ -4465,11 +4467,12 @@ AppDomain::RaiseAssemblyResolveEvent(
 
     Assembly* pAssembly = NULL;
 
-    struct _gc {
+    struct {
         OBJECTREF AssemblyRef;
         STRINGREF str;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.AssemblyRef = NULL;
+    gc.str = NULL;
 
     GCPROTECT_BEGIN(gc);
     {
index 59c6ab9..7901278 100644 (file)
@@ -42,7 +42,7 @@ FCIMPL0(Object*, AppDomainNative::GetLoadedAssemblies)
 {
     FCALL_CONTRACT;
 
-    struct _gc
+    struct
     {
         PTRARRAYREF     AsmArray;
     } gc;
index c676f31..a710a82 100644 (file)
@@ -78,7 +78,7 @@ static void MvidMismatchFatalError(GUID mvidActual, GUID mvidExpected, LPCUTF8 s
 void AssemblyBinder::DeclareDependencyOnMvid(LPCUTF8 simpleName, GUID mvid, bool compositeComponent, LPCUTF8 imageName)
 {
     _ASSERTE(imageName != NULL);
-    
+
     // If the table is empty, then we didn't fill it with all the loaded assemblies as they were loaded. Record this detail, and fix after adding the dependency
     bool addAllLoadedModules = false;
     if (m_assemblySimpleNameMvidCheckHash.GetCount() == 0)
@@ -180,10 +180,10 @@ void AssemblyBinder::GetNameForDiagnosticsFromManagedALC(INT_PTR managedALC, /*
     OBJECTREF* alc = reinterpret_cast<OBJECTREF*>(managedALC);
 
     GCX_COOP();
-    struct _gc {
+    struct {
         STRINGREF alcName;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.alcName = NULL;
 
     GCPROTECT_BEGIN(gc);
 
index 1e9d030..cee26dd 100644 (file)
@@ -956,13 +956,13 @@ FCIMPL1(Object*, AssemblyNative::GetReferencedAssemblies, AssemblyBaseObject * p
 {
     FCALL_CONTRACT;
 
-    struct _gc {
+    struct {
         PTRARRAYREF ItemArray;
         ASSEMBLYNAMEREF pObj;
         ASSEMBLYREF refAssembly;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-
+    gc.ItemArray = NULL;
+    gc.pObj = NULL;
     gc.refAssembly = (ASSEMBLYREF)ObjectToOBJECTREF(pAssemblyUNSAFE);
 
     if (gc.refAssembly == NULL)
index 7b9c1f9..8ea226a 100644 (file)
@@ -121,7 +121,6 @@ LNew:
         tempPtr = new (nothrow) CacheLine();
         if (tempPtr != NULL)
         {
-            tempPtr->Init64();
             tempPtr->m_pAddr[0] = pv;
             m_registryList.InsertHead(tempPtr);
         }
@@ -181,38 +180,32 @@ void *CCacheLineAllocator::GetCacheLine64()
     CONTRACT_END;
 
     LPCacheLine tempPtr = m_freeList64.RemoveHead();
-    if (tempPtr != NULL)
+    if (tempPtr == NULL)
     {
-        // initialize the bucket before returning
-        tempPtr->Init64();
-        RETURN tempPtr;
-    }
-
-#define AllocSize (4096*16)
-
-    ////////////////////////////////'
-    /// Virtual Allocation for some more cache lines
+        const ULONG AllocSize  = 4096 * 16;
 
-    BYTE* ptr = (BYTE*)VAlloc(AllocSize);
-
-    if(!ptr)
-        RETURN NULL;
+        // Virtual Allocation for some more cache lines
+        BYTE* ptr = (BYTE*)VAlloc(AllocSize);
+        if(!ptr)
+            RETURN NULL;
 
+        tempPtr = (LPCacheLine)ptr;
+        // Link all the buckets
+        tempPtr = tempPtr+1;
+        LPCacheLine maxPtr = (LPCacheLine)(ptr + AllocSize);
 
-    tempPtr = (LPCacheLine)ptr;
-    // Link all the buckets
-    tempPtr = tempPtr+1;
-    LPCacheLine maxPtr = (LPCacheLine)(ptr + AllocSize);
+        while(tempPtr < maxPtr)
+        {
+            m_freeList64.InsertHead(tempPtr);
+            tempPtr++;
+        }
 
-    while(tempPtr < maxPtr)
-    {
-        m_freeList64.InsertHead(tempPtr);
-        tempPtr++;
+        // return the first block
+        tempPtr = (LPCacheLine)ptr;
     }
 
-    // return the first block
-    tempPtr = (LPCacheLine)ptr;
-    tempPtr->Init64();
+    // initialize cacheline, 64 bytes
+    memset((void*)tempPtr,0,64);
     RETURN tempPtr;
 }
 
@@ -238,8 +231,8 @@ void *CCacheLineAllocator::GetCacheLine32()
     LPCacheLine tempPtr = m_freeList32.RemoveHead();
     if (tempPtr != NULL)
     {
-        // initialize the bucket before returning
-        tempPtr->Init32();
+        // initialize cacheline, 32 bytes
+        memset((void*)tempPtr,0,32);
         RETURN tempPtr;
     }
     tempPtr = (LPCacheLine)GetCacheLine64();
index 8556fab..4ea26c1 100644 (file)
@@ -45,7 +45,7 @@ public:
         numValidBytes    = numEntries * sizeof(void *)
     };
 
-    // store next pointer and the entries
+    // store next pointer and the entries - total of 16 pointers
     SLink   m_Link;
     union
     {
@@ -53,35 +53,6 @@ public:
         BYTE    m_xxx[numValidBytes];
     };
 
-    // init
-    void Init32()
-    {
-        CONTRACTL
-        {
-            NOTHROW;
-            GC_NOTRIGGER;
-            MODE_ANY;
-        }
-        CONTRACTL_END;
-
-        // initialize cacheline
-        memset(&m_Link,0,32);
-    }
-
-    void Init64()
-    {
-        CONTRACTL
-        {
-            NOTHROW;
-            GC_NOTRIGGER;
-            MODE_ANY;
-        }
-        CONTRACTL_END;
-
-        // initialize cacheline
-        memset(&m_Link,0,64);
-    }
-
     CacheLine()
     {
         CONTRACTL
@@ -93,9 +64,11 @@ public:
         CONTRACTL_END;
 
         // initialize cacheline
-        memset(&m_Link,0,sizeof(CacheLine));
+        m_Link = {};
+        memset(m_xxx,0,numValidBytes);
     }
 };
+static_assert(sizeof(CacheLine) == (16 * sizeof(void*)), "Cacheline should be exactly 16 pointers in size");
 #include <poppack.h>
 
 typedef CacheLine* LPCacheLine;
index 00725cd..dabbe89 100644 (file)
@@ -316,7 +316,7 @@ void CallsiteInspect::GetCallsiteArgs(
     }
     CONTRACTL_END;
 
-    struct _gc
+    struct
     {
         PTRARRAYREF Args;
         PTRARRAYREF ArgsTypes;
@@ -324,7 +324,11 @@ void CallsiteInspect::GetCallsiteArgs(
         OBJECTREF CurrArgType;
         OBJECTREF CurrArg;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.Args = NULL;
+    gc.ArgsTypes = NULL;
+    gc.ArgsIsByRef = NULL;
+    gc.CurrArgType = NULL;
+    gc.CurrArg = NULL;
     GCPROTECT_BEGIN(gc);
     {
         // Ensure the sig is in a known state
@@ -390,15 +394,15 @@ void CallsiteInspect::PropagateOutParametersBackToCallsite(
     }
     CONTRACTL_END;
 
-    struct _gc
+    struct
     {
         OBJECTREF RetVal;
         PTRARRAYREF OutArgs;
         OBJECTREF CurrArg;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-    gc.OutArgs = outArgs;
     gc.RetVal = retVal;
+    gc.OutArgs = outArgs;
+    gc.CurrArg = NULL;
     GCPROTECT_BEGIN(gc);
     {
         FramedMethodFrame *frame = callsite.Frame;
index 8ce03df..976e45e 100644 (file)
@@ -1309,12 +1309,6 @@ BOOL EETypeAccessException::GetThrowableMessage(SString &result)
 // EEArgumentException is an EE exception subclass representing a bad argument
 // ---------------------------------------------------------------------------
 
-typedef struct {
-    OBJECTREF pThrowable;
-    STRINGREF s1;
-    OBJECTREF pTmpThrowable;
-} ProtectArgsStruct;
-
 OBJECTREF EEArgumentException::CreateThrowable()
 {
 
@@ -1328,15 +1322,22 @@ OBJECTREF EEArgumentException::CreateThrowable()
 
     _ASSERTE(GetThreadNULLOk() != NULL);
 
-    ProtectArgsStruct prot;
-    memset(&prot, 0, sizeof(ProtectArgsStruct));
-    ResMgrGetString(m_resourceName, &prot.s1);
-    GCPROTECT_BEGIN(prot);
+    struct
+    {
+        OBJECTREF pThrowable;
+        STRINGREF s1;
+        OBJECTREF pTmpThrowable;
+    } gc;
+    gc.pThrowable = NULL;
+    gc.s1 = NULL;
+    gc.pTmpThrowable = NULL;
+    ResMgrGetString(m_resourceName, &gc.s1);
+    GCPROTECT_BEGIN(gc);
 
     MethodTable *pMT = CoreLibBinder::GetException(m_kind);
-    prot.pThrowable = AllocateObject(pMT);
+    gc.pThrowable = AllocateObject(pMT);
 
-    MethodDesc* pMD = MemberLoader::FindMethod(prot.pThrowable->GetMethodTable(),
+    MethodDesc* pMD = MemberLoader::FindMethod(gc.pThrowable->GetMethodTable(),
                             COR_CTOR_METHOD_NAME, &gsig_IM_Str_Str_RetVoid);
 
     if (!pMD)
@@ -1354,8 +1355,8 @@ OBJECTREF EEArgumentException::CreateThrowable()
     if (m_kind == kArgumentException)
     {
         ARG_SLOT args1[] = {
-            ObjToArgSlot(prot.pThrowable),
-            ObjToArgSlot(prot.s1),
+            ObjToArgSlot(gc.pThrowable),
+            ObjToArgSlot(gc.s1),
             ObjToArgSlot(argName),
         };
         exceptionCtor.Call(args1);
@@ -1363,16 +1364,16 @@ OBJECTREF EEArgumentException::CreateThrowable()
     else
     {
         ARG_SLOT args1[] = {
-            ObjToArgSlot(prot.pThrowable),
+            ObjToArgSlot(gc.pThrowable),
             ObjToArgSlot(argName),
-            ObjToArgSlot(prot.s1),
+            ObjToArgSlot(gc.s1),
         };
         exceptionCtor.Call(args1);
     }
 
     GCPROTECT_END(); //Prot
 
-    return prot.pThrowable;
+    return gc.pThrowable;
 }
 
 
@@ -1453,13 +1454,16 @@ OBJECTREF EETypeLoadException::CreateThrowable()
 
     MethodTable *pMT = CoreLibBinder::GetException(kTypeLoadException);
 
-    struct _gc {
+    struct {
         OBJECTREF pNewException;
         STRINGREF pNewAssemblyString;
         STRINGREF pNewClassString;
         STRINGREF pNewMessageArgString;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.pNewException = NULL;
+    gc.pNewAssemblyString = NULL;
+    gc.pNewClassString = NULL;
+    gc.pNewMessageArgString = NULL;
     GCPROTECT_BEGIN(gc);
 
     gc.pNewClassString = StringObject::NewString(m_fullName);
@@ -1632,11 +1636,12 @@ OBJECTREF EEFileLoadException::CreateThrowable()
     }
     CONTRACTL_END;
 
-    struct _gc {
+    struct {
         OBJECTREF pNewException;
         STRINGREF pNewFileString;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.pNewException = NULL;
+    gc.pNewFileString = NULL;
     GCPROTECT_BEGIN(gc);
 
     gc.pNewFileString = StringObject::NewString(m_name);
index 19a6dca..73b942d 100644 (file)
@@ -300,13 +300,14 @@ UINT32 CLRToCOMEventCallWorker(ComPlusMethodFrame* pFrame, ComPlusCallMethodDesc
     }
     CONTRACTL_END;
 
-    struct _gc {
+    struct {
         OBJECTREF EventProviderTypeObj;
         OBJECTREF EventProviderObj;
         OBJECTREF ThisObj;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-
+    gc.EventProviderTypeObj = NULL;
+    gc.EventProviderObj = NULL;
+    gc.ThisObj = NULL;
 
     LOG((LF_STUBS, LL_INFO1000, "Calling CLRToCOMEventCallWorker %s::%s \n", pMD->m_pszDebugClassName, pMD->m_pszDebugMethodName));
 
@@ -598,7 +599,14 @@ UINT32 CLRToCOMLateBoundWorker(
         OBJECTREF RetValType;
         OBJECTREF RetVal;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.MemberName = NULL;
+    gc.ItfTypeObj = NULL;
+    gc.Args = NULL;
+    gc.ArgsIsByRef = NULL;
+    gc.ArgsTypes = NULL;
+    gc.ArgsWrapperTypes = NULL;
+    gc.RetValType = NULL;
+    gc.RetVal = NULL;
     GCPROTECT_BEGIN(gc);
     {
         // Retrieve the exposed type object for the interface.
index 4dde887..aec6496 100644 (file)
@@ -3202,13 +3202,15 @@ void DistributeUnhandledExceptionReliably(OBJECTREF *pDelegate,
 
     EX_TRY
     {
-        struct _gc
+        struct
         {
             PTRARRAYREF Array;
             OBJECTREF   InnerDelegate;
             OBJECTREF   EventArgs;
         } gc;
-        ZeroMemory(&gc, sizeof(gc));
+        gc.Array = NULL;
+        gc.InnerDelegate = NULL;
+        gc.EventArgs = NULL;
 
         GCPROTECT_BEGIN(gc);
 
index 5ed7e1d..3f04936 100644 (file)
@@ -89,16 +89,17 @@ FCIMPL3(VOID, ExceptionNative::GetStackTracesDeepCopy, Object* pExceptionObjectU
     ASSERT(pStackTraceUnsafe != NULL);
     ASSERT(pDynamicMethodsUnsafe != NULL);
 
-    struct _gc
+    struct
     {
         StackTraceArray stackTrace;
         StackTraceArray stackTraceCopy;
         EXCEPTIONREF refException;
         PTRARRAYREF dynamicMethodsArray; // Object array of Managed Resolvers
         PTRARRAYREF dynamicMethodsArrayCopy; // Copy of the object array of Managed Resolvers
-    };
-    _gc gc;
-    ZeroMemory(&gc, sizeof(gc));
+    } gc;
+    gc.refException = NULL;
+    gc.dynamicMethodsArray = NULL;
+    gc.dynamicMethodsArrayCopy = NULL;
 
     // GC protect the array reference
     HELPER_METHOD_FRAME_BEGIN_PROTECT(gc);
@@ -153,14 +154,14 @@ FCIMPL3(VOID, ExceptionNative::SaveStackTracesFromDeepCopy, Object* pExceptionOb
 
     ASSERT(pExceptionObjectUnsafe != NULL);
 
-    struct _gc
+    struct
     {
         StackTraceArray stackTrace;
         EXCEPTIONREF refException;
         PTRARRAYREF dynamicMethodsArray; // Object array of Managed Resolvers
-    };
-    _gc gc;
-    ZeroMemory(&gc, sizeof(gc));
+    } gc;
+    gc.refException = NULL;
+    gc.dynamicMethodsArray = NULL;
 
     // GC protect the array reference
     HELPER_METHOD_FRAME_BEGIN_PROTECT(gc);
index e8495ad..23da0d1 100644 (file)
@@ -136,7 +136,8 @@ CustomAttributeManagedValues Attribute::GetManagedCaValue(CaValue* pCaVal)
     WRAPPER_NO_CONTRACT;
 
     CustomAttributeManagedValues gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.string = NULL;
+    gc.array = NULL;
     GCPROTECT_BEGIN(gc)
     {
         CorSerializationType type = pCaVal->type.tag;
index 7732ad0..c2a8436 100644 (file)
@@ -606,9 +606,9 @@ void ReportExceptionStackHelper(OBJECTREF exObj, EventReporter& reporter, SmallS
         EXCEPTIONREF ex;
         STRINGREF remoteStackTraceString;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
     gc.exObj = exObj;
     gc.ex = (EXCEPTIONREF)exObj;
+    gc.remoteStackTraceString = NULL;
 
     GCPROTECT_BEGIN(gc);
 
index 42f05b6..3582cbb 100644 (file)
@@ -4761,7 +4761,9 @@ VOID ETW::ExceptionLog::ExceptionThrown(CrawlFrame  *pCf, BOOL bIsReThrownExcept
             OBJECTREF innerExceptionObj;
             STRINGREF exceptionMessageRef;
         } gc;
-        ZeroMemory(&gc, sizeof(gc));
+        gc.exceptionObj = NULL;
+        gc.innerExceptionObj = NULL;
+        gc.exceptionMessageRef = NULL;
         GCPROTECT_BEGIN(gc);
 
         gc.exceptionObj = pThread->GetThrowable();
index 183bee1..8af866c 100644 (file)
@@ -109,13 +109,6 @@ BOOL IsExceptionFromManagedCode(const EXCEPTION_RECORD * pExceptionRecord)
 #define SZ_UNHANDLED_EXCEPTION W("Unhandled exception.")
 #define SZ_UNHANDLED_EXCEPTION_CHARLEN ((sizeof(SZ_UNHANDLED_EXCEPTION) / sizeof(WCHAR)))
 
-
-typedef struct {
-    OBJECTREF pThrowable;
-    STRINGREF s1;
-    OBJECTREF pTmpThrowable;
-} ProtectArgsStruct;
-
 PEXCEPTION_REGISTRATION_RECORD GetCurrentSEHRecord();
 BOOL IsUnmanagedToManagedSEHHandler(EXCEPTION_REGISTRATION_RECORD*);
 
@@ -8387,7 +8380,7 @@ BOOL SetupWatsonBucketsForNonPreallocatedExceptions(OBJECTREF oThrowable /* = NU
     {
         OBJECTREF oThrowable;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oThrowable = NULL;
     GCPROTECT_BEGIN(gc);
 
     // Get the throwable to be used
@@ -8511,7 +8504,7 @@ BOOL SetupWatsonBucketsForEscapingPreallocatedExceptions()
     {
         OBJECTREF oThrowable;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oThrowable = NULL;
     GCPROTECT_BEGIN(gc);
 
     // Get the throwable corresponding to the escaping exception
@@ -8663,7 +8656,8 @@ void SetupWatsonBucketsForUEF(BOOL fUseLastThrownObject)
         OBJECTREF oThrowable;
         U1ARRAYREF oBuckets;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oThrowable = NULL;
+    gc.oBuckets = NULL;
     GCPROTECT_BEGIN(gc);
 
     gc.oThrowable = fUseLastThrownObject ? pThread->LastThrownObject() : pThread->GetThrowable();
@@ -8812,10 +8806,8 @@ BOOL IsThrowableThreadAbortException(OBJECTREF oThrowable)
     {
         OBJECTREF oThrowable;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-    GCPROTECT_BEGIN(gc);
-
     gc.oThrowable = oThrowable;
+    GCPROTECT_BEGIN(gc);
 
     fIsTAE = IsExceptionOfType(kThreadAbortException, &gc.oThrowable);
 
@@ -8872,10 +8864,8 @@ PTR_ExInfo GetEHTrackerForPreallocatedException(OBJECTREF oPreAllocThrowable,
     {
         OBJECTREF oPreAllocThrowable;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-    GCPROTECT_BEGIN(gc);
-
     gc.oPreAllocThrowable = oPreAllocThrowable;
+    GCPROTECT_BEGIN(gc);
 
     // Start walking the list to find the tracker corresponding
     // to the preallocated exception object.
@@ -8922,10 +8912,8 @@ PTR_EHWatsonBucketTracker GetWatsonBucketTrackerForPreallocatedException(OBJECTR
     {
         OBJECTREF oPreAllocThrowable;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-    GCPROTECT_BEGIN(gc);
-
     gc.oPreAllocThrowable = oPreAllocThrowable;
+    GCPROTECT_BEGIN(gc);
 
     // Before doing anything, check if this is a thread abort exception. If it is,
     // then simply return the reference to the UE watson bucket tracker since it
@@ -9088,9 +9076,10 @@ BOOL SetupWatsonBucketsForFailFast(EXCEPTIONREF refException)
         OBJECTREF oInnerMostExceptionThrowable;
         U1ARRAYREF oBuckets;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
-    GCPROTECT_BEGIN(gc);
     gc.refException = refException;
+    gc.oInnerMostExceptionThrowable = NULL;
+    gc.oBuckets = NULL;
+    GCPROTECT_BEGIN(gc);
 
     Thread *pThread = GetThread();
 
@@ -9362,7 +9351,9 @@ void SetupInitialThrowBucketDetails(UINT_PTR adjustedIp)
         OBJECTREF oInnerMostExceptionThrowable;
         U1ARRAYREF refSourceWatsonBucketArray;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oCurrentThrowable = NULL;
+    gc.oInnerMostExceptionThrowable = NULL;
+    gc.refSourceWatsonBucketArray = NULL;
 
     GCPROTECT_BEGIN(gc);
 
@@ -9968,7 +9959,9 @@ void SetStateForWatsonBucketing(BOOL fIsRethrownException, OBJECTHANDLE ohOrigin
         OBJECTREF oInnerMostExceptionThrowable;
         U1ARRAYREF refSourceWatsonBucketArray;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oCurrentThrowable = NULL;
+    gc.oInnerMostExceptionThrowable = NULL;
+    gc.refSourceWatsonBucketArray = NULL;
     GCPROTECT_BEGIN(gc);
 
     Thread* pThread = GetThread();
@@ -10787,7 +10780,12 @@ void ExceptionNotifications::DeliverNotificationInternal(ExceptionNotificationHa
         OBJECTREF   oCurrentThrowable;
         OBJECTREF   oCurAppDomain;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.oNotificationDelegate = NULL;
+    gc.arrDelegates = NULL;
+    gc.oInnerDelegate = NULL;
+    gc.oEventArgs = NULL;
+    gc.oCurrentThrowable = NULL;
+    gc.oCurAppDomain = NULL;
 
     // This will hold the MethodDesc of the callback that will be invoked.
     MethodDesc *pMDDelegate = NULL;
index 0790751..e95036c 100644 (file)
@@ -1308,8 +1308,6 @@ void ExceptionTracker::InitializeCrawlFrameForExplicitFrame(CrawlFrame* pcfThisF
     }
     CONTRACTL_END;
 
-    INDEBUG(memset(pcfThisFrame, 0xCC, sizeof(*pcfThisFrame)));
-
     // Clear various flags
     pcfThisFrame->isFrameless = false;
     pcfThisFrame->isInterrupted = false;
@@ -1396,7 +1394,6 @@ void ExceptionTracker::InitializeCrawlFrame(CrawlFrame* pcfThisFrame, Thread* pT
     }
     CONTRACTL_END;
 
-    INDEBUG(memset(pcfThisFrame, 0xCC, sizeof(*pcfThisFrame)));
     pcfThisFrame->pRD = pRD;
 
     // Clear various flags
index 245de11..53bc963 100644 (file)
@@ -326,7 +326,8 @@ namespace
                 PTRARRAYREF arrRefTmp;
                 PTRARRAYREF arrRef;
             } gc;
-            ::ZeroMemory(&gc, sizeof(gc));
+            gc.arrRefTmp = NULL;
+            gc.arrRef = NULL;
             GCPROTECT_BEGIN(gc);
 
             // Only add objects that are in the correct thread
@@ -695,11 +696,9 @@ namespace
             OBJECTREF implRef;
             OBJECTREF instRef;
         } gc;
-        ::ZeroMemory(&gc, sizeof(gc));
-        GCPROTECT_BEGIN(gc);
-
         gc.implRef = impl;
         gc.instRef = instance;
+        GCPROTECT_BEGIN(gc);
 
         // Check the object's SyncBlock for a managed object wrapper.
         SyncBlock* syncBlock = gc.instRef->GetSyncBlock();
@@ -807,14 +806,13 @@ namespace
             OBJECTREF wrapperMaybeRef;
             OBJECTREF objRefMaybe;
         } gc;
-        ::ZeroMemory(&gc, sizeof(gc));
+        gc.implRef = impl;
+        gc.wrapperMaybeRef = wrapperMaybe;
+        gc.objRefMaybe = NULL;
         GCPROTECT_BEGIN(gc);
 
         STRESS_LOG4(LF_INTEROP, LL_INFO1000, "Get or Create EOC: (Identity: 0x%p) (Flags: %x) (Maybe: 0x%p) (ID: %lld)\n", identity, flags, OBJECTREFToObject(wrapperMaybe), wrapperId);
 
-        gc.implRef = impl;
-        gc.wrapperMaybeRef = wrapperMaybe;
-
         ExtObjCxtCache* cache = ExtObjCxtCache::GetInstance();
         InteropLib::OBJECTHANDLE handle = NULL;
 
@@ -1121,10 +1119,9 @@ namespace InteropLibImports
                 OBJECTREF implRef;
                 OBJECTREF objsEnumRef;
             } gc;
-            ::ZeroMemory(&gc, sizeof(gc));
-            GCPROTECT_BEGIN(gc);
-
             gc.implRef = NULL; // Use the globally registered implementation.
+            gc.objsEnumRef = NULL;
+            GCPROTECT_BEGIN(gc);
 
             // Pass the objects along to get released.
             ExtObjCxtCache* cache = ExtObjCxtCache::GetInstanceNoThrow();
@@ -1228,11 +1225,10 @@ namespace InteropLibImports
                 OBJECTREF wrapperMaybeRef;
                 OBJECTREF objRef;
             } gc;
-            ::ZeroMemory(&gc, sizeof(gc));
-            GCPROTECT_BEGIN(gc);
-
             gc.implRef = NULL; // Use the globally registered implementation.
             gc.wrapperMaybeRef = NULL; // No supplied wrapper here.
+            gc.objRef = NULL;
+            GCPROTECT_BEGIN(gc);
 
             // Get wrapper for external object
             bool success = TryGetOrCreateObjectForComInstanceInternal(
@@ -1315,7 +1311,7 @@ namespace InteropLibImports
             {
                 OBJECTREF objRef;
             } gc;
-            ::ZeroMemory(&gc, sizeof(gc));
+            gc.objRef = NULL;
             GCPROTECT_BEGIN(gc);
 
             // Get the target of the external object's reference.
index a1c6886..a59d56a 100644 (file)
@@ -85,7 +85,7 @@ extern "C" void* QCALLTYPE ObjCMarshal_CreateReferenceTrackingHandle(
         {
             OBJECTREF objRef;
         } gc;
-        ::ZeroMemory(&gc, sizeof(gc));
+        gc.objRef = NULL;
         GCPROTECT_BEGIN(gc);
 
         gc.objRef = obj.Get();
@@ -327,7 +327,8 @@ void* ObjCMarshalNative::GetPropagatingExceptionCallback(
             OBJECTREF throwableRef;
             REFLECTMETHODREF methodRef;
         } gc;
-        ::ZeroMemory(&gc, sizeof(gc));
+        gc.throwableRef = NULL;
+        gc.methodRef = NULL;
         GCPROTECT_BEGIN(gc);
 
         // Creating the StubMethodInfo isn't cheap, so check
index 4b69f58..ea2278e 100644 (file)
@@ -570,7 +570,8 @@ OBJECTREF InvokeUtil::CreateClassLoadExcept(OBJECTREF* classes, OBJECTREF* excep
         OBJECTREF o;
         STRINGREF str;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
+    gc.o = NULL;
+    gc.str = NULL;
 
     MethodTable *pVMClassLoadExcept = CoreLibBinder::GetException(kReflectionTypeLoadException);
     gc.o = AllocateObject(pVMClassLoadExcept);
index 86a72ff..a67b909 100644 (file)
@@ -733,15 +733,17 @@ LOADERHANDLE LoaderAllocator::AllocateHandle(OBJECTREF value)
 
     LOADERHANDLE retVal;
 
-    struct _gc
+    struct
     {
         OBJECTREF value;
         LOADERALLOCATORREF loaderAllocator;
         PTRARRAYREF handleTable;
         PTRARRAYREF handleTableOld;
     } gc;
-
-    ZeroMemory(&gc, sizeof(gc));
+    gc.value = NULL;
+    gc.loaderAllocator = NULL;
+    gc.handleTable = NULL;
+    gc.handleTableOld = NULL;
 
     GCPROTECT_BEGIN(gc);
 
@@ -903,14 +905,16 @@ OBJECTREF LoaderAllocator::CompareExchangeValueInHandle(LOADERHANDLE handle, OBJ
 
     OBJECTREF retVal;
 
-    struct _gc
+    struct
     {
         OBJECTREF value;
         OBJECTREF compare;
         OBJECTREF previous;
     } gc;
+    gc.value = NULL;
+    gc.compare = NULL;
+    gc.previous = NULL;
 
-    ZeroMemory(&gc, sizeof(gc));
     GCPROTECT_BEGIN(gc);
 
     gc.value = valueUNSAFE;
index c90ab23..3bcc0e0 100644 (file)
@@ -283,14 +283,14 @@ bool ModuleVersion::GetModuleVersion(Module * pModule)
 }
 
 ModuleRecord::ModuleRecord(unsigned lenName, unsigned lenAsmName)
+    : version{}
+    , jitMethodCount{}
+    , wLoadLevel{}
 {
     LIMITED_METHOD_CONTRACT;
 
-    memset(this, 0, sizeof(ModuleRecord));
-
     recordID = Pack8_24(MULTICOREJIT_MODULE_RECORD_ID, sizeof(ModuleRecord));
 
-    wLoadLevel = 0;
     // Extra data
     lenModuleName = (unsigned short) lenName;
     lenAssemblyName = (unsigned short) lenAsmName;
index 240b57b..f607e3a 100644 (file)
@@ -634,10 +634,7 @@ void StringLiteralEntry::DeleteEntry (StringLiteralEntry *pEntry)
     _ASSERTE (VolatileLoad(&pEntry->m_dwRefCount) == 0);
 
 #ifdef _DEBUG
-    memset (pEntry, 0xc, sizeof(StringLiteralEntry));
-#endif
-
-#ifdef _DEBUG
+    memset (&pEntry->m_pStringObj, 0xc, sizeof(pEntry->m_pStringObj));
     pEntry->m_bDeleted = TRUE;
 #endif
 
index 931feff..dbad515 100644 (file)
@@ -626,9 +626,25 @@ public:
 #endif // !TARGET_UNIX
 
     InteropSyncBlockInfo()
+        : m_pUMEntryThunk{}
+#ifdef FEATURE_COMINTEROP
+        , m_pCCW{}
+#ifdef FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
+        , m_pCCF{}
+#endif // FEATURE_COMINTEROP_UNMANAGED_ACTIVATION
+        , m_pRCW{}
+#endif // FEATURE_COMINTEROP
+#ifdef FEATURE_COMWRAPPERS
+        , m_externalComObjectContext{}
+        , m_managedObjectComWrapperLock{}
+        , m_managedObjectComWrapperMap{}
+#endif // FEATURE_COMWRAPPERS
+#ifdef FEATURE_OBJCMARSHAL
+        , m_taggedMemory{}
+        , m_taggedAlloc{}
+#endif // FEATURE_OBJCMARSHAL
     {
         LIMITED_METHOD_CONTRACT;
-        ZeroMemory(this, sizeof(InteropSyncBlockInfo));
 
 #if defined(FEATURE_COMWRAPPERS)
         // The GC thread does enumerate these objects so add CRST_UNSAFE_COOPGC.
index 85ffc91..f1f8f4f 100644 (file)
@@ -1973,36 +1973,37 @@ void Thread::HandleThreadStartupFailure()
 
     _ASSERTE(GetThreadNULLOk() != NULL);
 
-    struct ProtectArgs
+    struct
     {
         OBJECTREF pThrowable;
         OBJECTREF pReason;
-    } args;
-    memset(&args, 0, sizeof(ProtectArgs));
+    } gc;
+    gc.pThrowable = NULL;
+    gc.pReason = NULL;
 
-    GCPROTECT_BEGIN(args);
+    GCPROTECT_BEGIN(gc);
 
     MethodTable *pMT = CoreLibBinder::GetException(kThreadStartException);
-    args.pThrowable = AllocateObject(pMT);
+    gc.pThrowable = AllocateObject(pMT);
 
     MethodDescCallSite exceptionCtor(METHOD__THREAD_START_EXCEPTION__EX_CTOR);
 
     if (m_pExceptionDuringStartup)
     {
-        args.pReason = CLRException::GetThrowableFromException(m_pExceptionDuringStartup);
+        gc.pReason = CLRException::GetThrowableFromException(m_pExceptionDuringStartup);
         Exception::Delete(m_pExceptionDuringStartup);
         m_pExceptionDuringStartup = NULL;
     }
 
     ARG_SLOT args1[] = {
-        ObjToArgSlot(args.pThrowable),
-        ObjToArgSlot(args.pReason),
+        ObjToArgSlot(gc.pThrowable),
+        ObjToArgSlot(gc.pReason),
     };
     exceptionCtor.Call(args1);
 
     GCPROTECT_END(); //Prot
 
-    RaiseTheExceptionInternalOnly(args.pThrowable, FALSE);
+    RaiseTheExceptionInternalOnly(gc.pThrowable, FALSE);
 }
 
 #ifndef TARGET_UNIX
index e6ad103..b26d017 100644 (file)
@@ -203,8 +203,9 @@ NOINLINE Object* LoadComWeakReferenceTarget(WEAKREFERENCEREF weakReference, Type
         OBJECTREF rcw;
         OBJECTREF target;
     } gc;
-    ZeroMemory(&gc, sizeof(gc));
     gc.weakReference = weakReference;
+    gc.rcw = NULL;
+    gc.target = NULL;
 
     FC_INNER_PROLOG_NO_ME_SETUP();
     HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_PROTECT(Frame::FRAME_ATTR_EXACT_DEPTH|Frame::FRAME_ATTR_CAPTURE_DEPTH_2, gc);