Skip to content

Commit b71eba8

Browse files
Reenable compiler warning 4244 under coreclr/ (#66398)
* From vm/ * From util/ * From debug/ * GCInfo related Use MAXDWORD instead of DWORD_MAX. Remove DWORD_MAX from pal, since it is not used anywhere.
1 parent 763936e commit b71eba8

File tree

10 files changed

+92
-116
lines changed

10 files changed

+92
-116
lines changed

src/coreclr/debug/daccess/gcdump_dac.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* are all about.
99
*/
1010
#ifdef __MSC_VER
11-
#pragma warning(disable:4244) // conversion from 'unsigned int' to 'unsigned short', possible loss of data
1211
#pragma warning(disable:4189) // local variable is initialized but not referenced
1312
#endif // __MSC_VER
1413

@@ -43,6 +42,5 @@
4342
#endif // !TARGET_X86
4443

4544
#ifdef __MSC_VER
46-
#pragma warning(default:4244)
4745
#pragma warning(default:4189)
4846
#endif // __MSC_VER

src/coreclr/jit/gcencode.cpp

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

src/coreclr/jit/jitgcinfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ struct RegSlotIdKey
2727
{
2828
}
2929

30-
RegSlotIdKey(unsigned short regNum, unsigned short flags) : m_regNum(regNum), m_flags(flags)
30+
RegSlotIdKey(unsigned short regNum, unsigned flags) : m_regNum(regNum), m_flags((unsigned short)flags)
3131
{
32+
assert(m_flags == flags);
3233
}
3334

3435
static unsigned GetHashCode(RegSlotIdKey rsk)
@@ -52,8 +53,10 @@ struct StackSlotIdKey
5253
{
5354
}
5455

55-
StackSlotIdKey(int offset, bool fpRel, unsigned short flags) : m_offset(offset), m_fpRel(fpRel), m_flags(flags)
56+
StackSlotIdKey(int offset, bool fpRel, unsigned flags)
57+
: m_offset(offset), m_fpRel(fpRel), m_flags((unsigned short)flags)
5658
{
59+
assert(flags == m_flags);
5760
}
5861

5962
static unsigned GetHashCode(StackSlotIdKey ssk)

src/coreclr/pal/inc/rt/intsafe.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949

5050
#endif
5151

52-
#define DWORD_MAX 0xffffffffUL
53-
5452
//
5553
// It is common for -1 to be used as an error value for various types
5654
//

src/coreclr/utilcode/stgpooli.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ ULONG CPackedLen::GetLength( // Length or -1 on error.
309309
//*****************************************************************************
310310
// Encode a length.
311311
//*****************************************************************************
312-
#ifdef _MSC_VER
313-
#pragma warning(disable:4244) // conversion from unsigned long to unsigned char
314-
#endif
315312
void* CPackedLen::PutLength( // First byte past length.
316313
void *pData, // Pack the length here.
317314
ULONG iLen) // The length.
@@ -323,13 +320,13 @@ void* CPackedLen::PutLength( // First byte past length.
323320

324321
if (iLen <= 0x7F)
325322
{
326-
*pBytes = iLen;
323+
*pBytes = (BYTE)iLen;
327324
return pBytes + 1;
328325
}
329326

330327
if (iLen <= 0x3FFF)
331328
{
332-
*pBytes = (iLen >> 8) | 0x80;
329+
*pBytes = (BYTE)((iLen >> 8) | 0x80);
333330
*(pBytes+1) = iLen & 0xFF;
334331
return pBytes + 2;
335332
}
@@ -341,7 +338,3 @@ void* CPackedLen::PutLength( // First byte past length.
341338
*(pBytes+3) = iLen & 0xFF;
342339
return pBytes + 4;
343340
} // void* CPackedLen::PutLength()
344-
#ifdef _MSC_VER
345-
#pragma warning(default:4244) // conversion from unsigned long to unsigned char
346-
#endif
347-

src/coreclr/vm/ceeload.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464
#include "typekey.h"
6565
#include "peimagelayout.inl"
6666

67-
#ifdef _MSC_VER
68-
#pragma warning(push)
69-
#pragma warning(disable:4244)
70-
#endif // _MSC_VER
71-
7267
#ifdef TARGET_64BIT
7368
#define COR_VTABLE_PTRSIZED COR_VTABLE_64BIT
7469
#define COR_VTABLE_NOT_PTRSIZED COR_VTABLE_32BIT
@@ -1854,9 +1849,10 @@ void Module::FreeModuleIndex(ModuleIndex index)
18541849
WRAPPER_NO_CONTRACT;
18551850
// We subtracted 1 after we allocated this ID, so we need to
18561851
// add 1 before we free it.
1857-
DWORD val = index.m_dwIndex + 1;
1852+
SIZE_T val = index.m_dwIndex + 1;
18581853

1859-
g_pModuleIndexDispenser->DisposeId(val);
1854+
_ASSERTE(val <= MAXDWORD);
1855+
g_pModuleIndexDispenser->DisposeId((DWORD)val);
18601856
}
18611857

18621858

@@ -4790,7 +4786,7 @@ ICorJitInfo::BlockCounts * Module::AllocateMethodBlockCounts(mdToken _token, DWO
47904786
}
47914787
CONTRACT_END;
47924788

4793-
assert(_ILSize != 0);
4789+
_ASSERTE(_ILSize != 0);
47944790

47954791
DWORD listSize = sizeof(CORCOMPILE_METHOD_PROFILE_LIST);
47964792
DWORD headerSize = sizeof(CORBBTPROF_METHOD_HEADER);
@@ -4809,7 +4805,7 @@ ICorJitInfo::BlockCounts * Module::AllocateMethodBlockCounts(mdToken _token, DWO
48094805
methodProfileData->method.ILSize = _ILSize;
48104806
methodProfileData->method.cBlock = _count;
48114807

4812-
assert(methodProfileData->size == methodProfileData->Size());
4808+
_ASSERTE(methodProfileData->size == methodProfileData->Size());
48134809

48144810
// Link it to the per module list of profile data buffers
48154811

@@ -5026,10 +5022,12 @@ class ProfileEmitter
50265022
for (SectionList *pSec = pSectionList; pSec; pSec = pSec->next, secCount++)
50275023
{
50285024
SIZE_T offset = profileMap->getCurrentOffset();
5029-
assert((offset & 0x3) == 0);
5025+
_ASSERTE((offset & 0x3) == 0);
5026+
_ASSERTE(offset <= MAXDWORD);
50305027

50315028
SIZE_T actualSize = pSec->profileMap.getCurrentOffset();
50325029
SIZE_T alignUpSize = AlignUp(actualSize, sizeof(DWORD));
5030+
_ASSERTE(alignUpSize <= MAXDWORD);
50335031

50345032
profileMap->Allocate(alignUpSize);
50355033

@@ -5043,8 +5041,8 @@ class ProfileEmitter
50435041
tableEntry = (CORBBTPROF_SECTION_TABLE_ENTRY *) profileMap->getOffsetPtr(tableEntryOffset);
50445042
tableEntry += secCount;
50455043
tableEntry->FormatID = pSec->format;
5046-
tableEntry->Data.Offset = offset;
5047-
tableEntry->Data.Size = alignUpSize;
5044+
tableEntry->Data.Offset = (DWORD)offset;
5045+
tableEntry->Data.Size = (DWORD)alignUpSize;
50485046
}
50495047
}
50505048

@@ -5952,12 +5950,14 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc
59525950
sHeaderOffset = profileMap->getCurrentOffset();
59535951
sHeader = (CORBBTPROF_SCENARIO_HEADER *) profileMap->Allocate(sizeHeader.Value());
59545952

5955-
sHeader->size = sHeaderSize.Value();
5953+
_ASSERTE(sHeaderSize.Value() <= MAXDWORD);
5954+
_ASSERTE(cName.Value() <= MAXDWORD);
5955+
sHeader->size = (DWORD)sHeaderSize.Value();
59565956
sHeader->scenario.ordinal = 1;
59575957
sHeader->scenario.mask = 1;
59585958
sHeader->scenario.priority = 0;
59595959
sHeader->scenario.numRuns = 1;
5960-
sHeader->scenario.cName = cName.Value();
5960+
sHeader->scenario.cName = (DWORD)cName.Value();
59615961
wcscpy_s(sHeader->scenario.name, cName.Value(), pName);
59625962
}
59635963

@@ -5968,18 +5968,20 @@ static void ProfileDataAllocateScenarioInfo(ProfileEmitter * pEmitter, LPCSTR sc
59685968
CORBBTPROF_SCENARIO_RUN *sRun;
59695969
sRun = (CORBBTPROF_SCENARIO_RUN *) profileMap->Allocate(sizeRun.Value());
59705970

5971+
_ASSERTE(cCmdLine.Value() <= MAXDWORD);
5972+
_ASSERTE(cSystemInfo.Value() <= MAXDWORD);
59715973
sRun->runTime = runTime;
59725974
sRun->mvid = *pMvid;
5973-
sRun->cCmdLine = cCmdLine.Value();
5974-
sRun->cSystemInfo = cSystemInfo.Value();
5975+
sRun->cCmdLine = (DWORD)cCmdLine.Value();
5976+
sRun->cSystemInfo = (DWORD)cSystemInfo.Value();
59755977
wcscpy_s(sRun->cmdLine, cCmdLine.Value(), pCmdLine);
59765978
wcscpy_s(sRun->cmdLine+cCmdLine.Value(), cSystemInfo.Value(), pSystemInfo);
59775979
}
59785980
#ifdef _DEBUG
59795981
{
59805982
CORBBTPROF_SCENARIO_HEADER * sHeader;
59815983
sHeader = (CORBBTPROF_SCENARIO_HEADER *) profileMap->getOffsetPtr(sHeaderOffset);
5982-
assert(sHeader->size == sHeader->Size());
5984+
_ASSERTE(sHeader->size == sHeader->Size());
59835985
}
59845986
#endif
59855987
}
@@ -6018,7 +6020,7 @@ static void ProfileDataAllocateMethodBlockCounts(ProfileEmitter * pEmitter, CORC
60186020
{
60196021
CORBBTPROF_METHOD_HEADER * pInfo = methodProfileList->GetInfo();
60206022

6021-
assert(pInfo->size == pInfo->Size());
6023+
_ASSERTE(pInfo->size == pInfo->Size());
60226024

60236025
//
60246026
// We set methodWasExecuted based upon the ExecutionCount of the very first block
@@ -6087,7 +6089,8 @@ static void ProfileDataAllocateMethodBlockCounts(ProfileEmitter * pEmitter, CORC
60876089
profileMap->Allocate(sizeof(CORBBTPROF_TOKEN_LIST_SECTION_HEADER) +
60886090
pTokenArray->Size() * sizeof(CORBBTPROF_TOKEN_INFO));
60896091

6090-
header->NumTokens = pTokenArray->Size();
6092+
_ASSERTE(pTokenArray->Size() <= MAXDWORD);
6093+
header->NumTokens = (DWORD)pTokenArray->Size();
60916094
memcpy( (header + 1), &((*pTokenArray)[0]), pTokenArray->Size() * sizeof(CORBBTPROF_TOKEN_INFO));
60926095

60936096
// Reset the collected tokens
@@ -6348,7 +6351,8 @@ HRESULT Module::WriteMethodProfileDataLogFile(bool cleanup)
63486351
HandleHolder profileDataFile(OpenMethodProfileDataLogFile(mvid));
63496352

63506353
ULONG count;
6351-
BOOL result = WriteFile(profileDataFile, profileImage.getOffsetPtr(0), profileImage.getCurrentOffset(), &count, NULL);
6354+
_ASSERTE(profileImage.getCurrentOffset() <= MAXDWORD);
6355+
BOOL result = WriteFile(profileDataFile, profileImage.getOffsetPtr(0), (DWORD)profileImage.getCurrentOffset(), &count, NULL);
63526356
if (!result || (count != profileImage.getCurrentOffset()))
63536357
{
63546358
DWORD lasterror = GetLastError();
@@ -7849,10 +7853,6 @@ bool Module::HasReferenceByName(LPCUTF8 pModuleName)
78497853
}
78507854
#endif
78517855

7852-
#ifdef _MSC_VER
7853-
#pragma warning(pop)
7854-
#endif // _MSC_VER: warning C4244
7855-
78567856
#if defined(_DEBUG) && !defined(DACCESS_COMPILE)
78577857
NOINLINE void NgenForceFailure_AV()
78587858
{

src/coreclr/vm/method.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
#include "clrtocomcall.h"
3737
#endif
3838

39-
#ifdef _MSC_VER
40-
#pragma warning(push)
41-
#pragma warning(disable:4244)
42-
#endif // _MSC_VER
43-
4439
#ifdef FEATURE_MINIMETADATA_IN_TRIAGEDUMPS
4540
GVAL_IMPL(DWORD, g_MiniMetaDataBuffMaxSize);
4641
GVAL_IMPL(TADDR, g_MiniMetaDataBuffAddress);
@@ -1730,7 +1725,7 @@ MethodDescChunk *MethodDescChunk::CreateChunk(LoaderHeap *pHeap, DWORD methodDes
17301725

17311726
_ASSERTE((oneSize & MethodDesc::ALIGNMENT_MASK) == 0);
17321727

1733-
DWORD maxMethodDescsPerChunk = MethodDescChunk::MaxSizeOfMethodDescs / oneSize;
1728+
DWORD maxMethodDescsPerChunk = (DWORD)(MethodDescChunk::MaxSizeOfMethodDescs / oneSize);
17341729

17351730
if (methodDescCount == 0)
17361731
methodDescCount = maxMethodDescsPerChunk;
@@ -4113,7 +4108,3 @@ void MethodDesc::PrepareForUseAsAFunctionPointer()
41134108
SetValueTypeParametersLoaded();
41144109
}
41154110
#endif //!DACCESS_COMPILE
4116-
4117-
#ifdef _MSC_VER
4118-
#pragma warning(pop)
4119-
#endif // _MSC_VER: warning C4244

src/coreclr/vm/method.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ class MethodDescChunk
22602260
m_methodTable = pMT;
22612261
}
22622262

2263-
inline void SetSizeAndCount(ULONG sizeOfMethodDescs, COUNT_T methodDescCount)
2263+
inline void SetSizeAndCount(SIZE_T sizeOfMethodDescs, COUNT_T methodDescCount)
22642264
{
22652265
LIMITED_METHOD_CONTRACT;
22662266

src/coreclr/vm/methodtablebuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7053,7 +7053,7 @@ VOID MethodTableBuilder::AllocAndInitMethodDescChunk(COUNT_T startIndex, COUNT_T
70537053
}
70547054
_ASSERTE(offset == sizeof(MethodDescChunk) + sizeOfMethodDescs);
70557055

7056-
pChunk->SetSizeAndCount((ULONG)sizeOfMethodDescs, methodDescCount);
7056+
pChunk->SetSizeAndCount(sizeOfMethodDescs, methodDescCount);
70577057

70587058
GetHalfBakedClass()->AddChunk(pChunk);
70597059
}

src/coreclr/vm/typehash.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
#include "typekey.h"
1717
#include "dacenumerablehash.inl"
1818

19-
#ifdef _MSC_VER
20-
#pragma warning(push)
21-
#pragma warning(disable:4244)
22-
#endif // _MSC_VER
23-
2419
#ifndef DACCESS_COMPILE
2520

2621
// ============================================================================
@@ -168,7 +163,7 @@ static DWORD HashPossiblyInstantiatedType(mdTypeDef token, Instantiation inst)
168163
}
169164
}
170165

171-
return dwHash;
166+
return (DWORD)dwHash;
172167
}
173168

174169
// Calculate hash value for a function pointer type
@@ -187,7 +182,7 @@ static DWORD HashFnPtrType(BYTE callConv, DWORD numArgs, TypeHandle *retAndArgTy
187182
dwHash = ((dwHash << 5) + dwHash) ^ retAndArgTypes[i].AsTAddr();
188183
}
189184

190-
return dwHash;
185+
return (DWORD)dwHash;
191186
}
192187

193188
// Calculate hash value for an array/pointer/byref type
@@ -199,7 +194,7 @@ static DWORD HashParamType(CorElementType kind, TypeHandle typeParam)
199194
dwHash = ((dwHash << 5) + dwHash) ^ kind;
200195
dwHash = ((dwHash << 5) + dwHash) ^ typeParam.AsTAddr();
201196

202-
return dwHash;
197+
return (DWORD)dwHash;
203198
}
204199

205200
// Calculate hash value from type handle
@@ -234,10 +229,12 @@ static DWORD HashTypeHandle(TypeHandle t)
234229
else if (t.IsGenericVariable())
235230
{
236231
_ASSERTE(!"Generic variables are unexpected here.");
237-
retVal = t.AsTAddr();
232+
retVal = 0;
238233
}
239234
else
235+
{
240236
retVal = HashPossiblyInstantiatedType(t.GetCl(), Instantiation());
237+
}
241238

242239
return retVal;
243240
}
@@ -578,7 +575,3 @@ void EETypeHashEntry::SetTypeHandle(TypeHandle handle)
578575
m_data = handle.AsPtr();
579576
}
580577
#endif // !DACCESS_COMPILE
581-
582-
#ifdef _MSC_VER
583-
#pragma warning(pop)
584-
#endif // _MSC_VER: warning C4244

0 commit comments

Comments
 (0)