Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reenable class-memaccess warning #74363

Merged
merged 13 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down
6 changes: 2 additions & 4 deletions src/coreclr/classlibnative/bcltype/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2892,7 +2892,7 @@ ClrDataAccess::GetOOMStaticData(struct DacpOomData *oomData)

SOSDacEnter();

memset(oomData, 0, sizeof(DacpOomData));
*oomData = {};

if (!GCHeapUtilities::IsServerHeap())
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/debug/daccess/request_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/debug/di/dbgtransportmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/ee/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/ee/funceval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

//
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/inc/dbgappdomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ struct AppDomainEnumerationIPCBlock
pADInfo->FreeEntry();

#ifdef _DEBUG
memset(pADInfo, 0, sizeof(AppDomainInfo));
*pADInfo = {};
#endif

// decrement the used slot count
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/debug/inc/dbgtransportsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -422,7 +422,7 @@ class DbgTransportSession
// 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
Expand Down
9 changes: 1 addition & 8 deletions src/coreclr/debug/shared/dbgtransportsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13662,8 +13662,8 @@ gc_heap::init_semi_shared()

memset (full_gc_counts, 0, sizeof (full_gc_counts));
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

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));
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
#endif //BACKGROUND_GC
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/gcpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/handletable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/ilasm/asmman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 9 additions & 26 deletions src/coreclr/ilasm/asmman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/ilasm/asmtemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ template <class T> class RBNODEBUCKET
{
alloc_count++;
pRet = &bucket[i];
memset(pRet, 0, sizeof(RBNODE<T>));
*pRet = {};
pRet->dwInUse = 1;
return pRet;
}
Expand Down Expand Up @@ -551,10 +551,7 @@ template <class T> class RBNODEPOOL
RBNODEBUCKET<T> base;

public:
RBNODEPOOL()
{
memset(&base,0,sizeof(RBNODEBUCKET<T>));
};
RBNODEPOOL() = default;

RBNODE<T>* AllocNode()
{
Expand Down Expand Up @@ -681,7 +678,7 @@ template <class T> class RBTREE
};

public:
RBTREE()
RBTREE() : NodePool{}
{
pRoot = NodePool.AllocNode();
InitSpecNode(pRoot);
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/ilasm/assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
/**************************************************************************/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading