Skip to content

Commit 89962a5

Browse files
Reenable C4244 in repo (#70026)
* Reenable 4244 warning for Mono. * Enable compiler errors for gcc/clang. * Fix issues enabling -Werror=implicit-int-conversion * Revert turning on implicit-int-conversion as error. This check was triggering failures on parts of the PAL that require additional scrutiny beyond the scope of this work.
1 parent 1615e78 commit 89962a5

39 files changed

+158
-150
lines changed

src/coreclr/inc/corhlprpriv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ class RidBitmap
605605
HRESULT hr = S_OK;
606606
mdToken rid = RidFromToken(token);
607607
SIZE_T index = rid / 8;
608-
BYTE bit = (1 << (rid % 8));
608+
BYTE bit = (BYTE)(1 << (rid % 8));
609609

610610
if (index >= buffer.Size())
611611
{
@@ -623,7 +623,7 @@ class RidBitmap
623623
{
624624
mdToken rid = RidFromToken(token);
625625
SIZE_T index = rid / 8;
626-
BYTE bit = (1 << (rid % 8));
626+
BYTE bit = (BYTE)(1 << (rid % 8));
627627

628628
return ((index < buffer.Size()) && (buffer[index] & bit));
629629
}

src/coreclr/inc/llvm/ELF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ struct Elf32_Sym {
829829
void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
830830
void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
831831
void setBindingAndType(unsigned char b, unsigned char t) {
832-
st_info = (b << 4) + (t & 0x0f);
832+
st_info = (unsigned char)((b << 4) + (t & 0x0f));
833833
}
834834
};
835835

@@ -849,7 +849,7 @@ struct Elf64_Sym {
849849
void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
850850
void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
851851
void setBindingAndType(unsigned char b, unsigned char t) {
852-
st_info = (b << 4) + (t & 0x0f);
852+
st_info = (unsigned char)((b << 4) + (t & 0x0f));
853853
}
854854
};
855855

src/coreclr/pal/inc/pal_endian.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
extern "C++" {
1717
inline UINT16 SWAP16(UINT16 x)
1818
{
19-
return (x >> 8) | (x << 8);
19+
return (UINT16)((x >> 8) | (x << 8));
2020
}
2121

2222
inline UINT32 SWAP32(UINT32 x)

src/coreclr/pal/src/cruntime/file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ PAL_fread(void * buffer, size_t size, size_t count, PAL_FILE * f)
522522
}
523523
else
524524
{
525-
temp[nCount++]=nChar;
525+
temp[nCount++]= (char)nChar;
526526
}
527527
}
528528
}

src/coreclr/pal/src/cruntime/printf.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
265265

266266
if (*Fmt && **Fmt == '%')
267267
{
268-
*Out++ = *(*Fmt)++;
268+
*Out++ = (CHAR)*(*Fmt)++;
269269
}
270270
else
271271
{
@@ -285,7 +285,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
285285
if (**Fmt == '*')
286286
{
287287
*Store = FALSE;
288-
*Out++ = *(*Fmt)++;
288+
*Out++ = (CHAR)*(*Fmt)++;
289289
}
290290

291291
/* grab width specifier */
@@ -294,8 +294,8 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
294294
TempStrPtr = TempStr;
295295
while (isdigit(**Fmt))
296296
{
297-
*TempStrPtr++ = **Fmt;
298-
*Out++ = *(*Fmt)++;
297+
*TempStrPtr++ = (CHAR)**Fmt;
298+
*Out++ = (CHAR)*(*Fmt)++;
299299
}
300300
*TempStrPtr = 0; /* end string */
301301
*Width = atoi(TempStr);
@@ -406,7 +406,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
406406

407407
Out += strlen(scanf_longlongfmt);
408408
}
409-
*Out++ = *(*Fmt)++;
409+
*Out++ = (CHAR)*(*Fmt)++;
410410
Result = TRUE;
411411
}
412412
else if (**Fmt == 'e' || **Fmt == 'E' || **Fmt == 'f' ||
@@ -416,7 +416,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
416416
*Type = SCANF_TYPE_FLOAT;
417417
/* this gets rid of %E/%G since they're they're the
418418
same when scanning */
419-
*Out++ = tolower( *(*Fmt)++ );
419+
*Out++ = (CHAR)tolower( *(*Fmt)++ );
420420
Result = TRUE;
421421
}
422422
else if (**Fmt == 'n')
@@ -425,7 +425,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
425425
{
426426
*Out++ = 'h';
427427
}
428-
*Out++ = *(*Fmt)++;
428+
*Out++ = (CHAR)*(*Fmt)++;
429429
*Type = SCANF_TYPE_N;
430430
Result = TRUE;
431431
}
@@ -489,8 +489,8 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
489489
unsigned char prev, next;
490490

491491
/* get the interval boundaries */
492-
prev = (*Fmt)[-1];
493-
next = (*Fmt)[1];
492+
prev = (unsigned char)(*Fmt)[-1];
493+
next = (unsigned char)(*Fmt)[1];
494494

495495
/* if boundaries were inverted, replace the already-copied
496496
low boundary by the 'real' low boundary */
@@ -514,7 +514,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
514514
else
515515
{
516516
/* plain character; just copy it */
517-
*Out++ = **Fmt;
517+
*Out++ = (CHAR)**Fmt;
518518
(*Fmt)++;
519519
}
520520
}
@@ -625,7 +625,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap)
625625
{
626626
if (Prefix == SCANF_PREFIX_SHORT)
627627
{
628-
*(va_arg(ap, short *)) = Buff - Buffer;
628+
*(va_arg(ap, short *)) = (short)(Buff - Buffer);
629629
}
630630
else
631631
{

src/coreclr/pal/src/cruntime/printfcpp.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
706706
*Out++ = 'l';
707707
*Out++ = 'l';
708708
}
709-
*Out++ = *(*Fmt)++;
709+
*Out++ = (CHAR)*(*Fmt)++;
710710
Result = TRUE;
711711
}
712712
else if (**Fmt == 'e' || **Fmt == 'E' || **Fmt == 'f' ||
@@ -719,7 +719,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
719719
}
720720

721721
*Type = PFF_TYPE_FLOAT;
722-
*Out++ = *(*Fmt)++;
722+
*Out++ = (CHAR)*(*Fmt)++;
723723
Result = TRUE;
724724
}
725725
else if (**Fmt == 'n')
@@ -733,7 +733,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
733733
{
734734
*Out++ = 'h';
735735
}
736-
*Out++ = *(*Fmt)++;
736+
*Out++ = (CHAR)*(*Fmt)++;
737737
*Type = PFF_TYPE_N;
738738
Result = TRUE;
739739
}
@@ -1220,8 +1220,8 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
12201220
TempInt = va_arg(ap, INT); /* value not used */
12211221
}
12221222

1223-
TempWChar[0] = va_arg(ap, int);
1224-
TempWChar[1] = 0;
1223+
TempWChar[0] = (WCHAR)va_arg(ap, int);
1224+
TempWChar[1] = W('\0');
12251225

12261226
/* do the padding (if needed)*/
12271227
paddingReturnValue =
@@ -1254,7 +1254,7 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
12541254

12551255
if (Prefix == PFF_PREFIX_SHORT)
12561256
{
1257-
*(va_arg(ap, short *)) = written;
1257+
*(va_arg(ap, short *)) = (short)written;
12581258
}
12591259
else
12601260
{
@@ -1605,7 +1605,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
16051605
TempInt = va_arg(ap, INT); /* value not used */
16061606
}
16071607

1608-
TempWChar = va_arg(ap, int);
1608+
TempWChar = (WCHAR)va_arg(ap, int);
16091609
Length = WideCharToMultiByte(CP_ACP, 0, &TempWChar, 1,
16101610
TempBuffer, sizeof(TempBuffer),
16111611
0, 0);
@@ -1617,7 +1617,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
16171617
va_end(ap);
16181618
return -1;
16191619
}
1620-
TempBuffer[Length] = 0;
1620+
TempBuffer[Length] = W('\0');
16211621

16221622
/* do the padding (if needed)*/
16231623
paddingReturnValue =
@@ -1648,7 +1648,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
16481648

16491649
if (Prefix == PFF_PREFIX_SHORT)
16501650
{
1651-
*(va_arg(ap, short *)) = written;
1651+
*(va_arg(ap, short *)) = (short)written;
16521652
}
16531653
else
16541654
{

src/coreclr/pal/src/cruntime/silent_printf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int Silent_PAL_vfprintf(PAL_FILE *stream, const char *format, va_list aparg)
168168
TempInt = va_arg(ap, INT); /* value not used */
169169
}
170170

171-
TempWChar = va_arg(ap, int);
171+
TempWChar = (WCHAR)va_arg(ap, int);
172172
Length = Silent_WideCharToMultiByte(&TempWChar, 1, TempBuffer, 4);
173173
if (!Length)
174174
{
@@ -204,7 +204,7 @@ int Silent_PAL_vfprintf(PAL_FILE *stream, const char *format, va_list aparg)
204204

205205
if (Prefix == PFF_PREFIX_SHORT)
206206
{
207-
*(va_arg(ap, short *)) = written;
207+
*(va_arg(ap, short *)) = (short)written;
208208
}
209209
else
210210
{

src/coreclr/pal/src/file/filetime.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,16 @@ BOOL PALAPI FileTimeToSystemTime( CONST FILETIME * lpFileTime,
294294
#endif /* HAVE_GMTIME_R */
295295

296296
/* Convert unix system time to Windows system time. */
297-
lpSystemTime->wDay = UnixSystemTime->tm_mday;
297+
lpSystemTime->wDay = (WORD)UnixSystemTime->tm_mday;
298298

299299
/* Unix time counts January as a 0, under Windows it is 1*/
300-
lpSystemTime->wMonth = UnixSystemTime->tm_mon + 1;
300+
lpSystemTime->wMonth = (WORD)UnixSystemTime->tm_mon + 1;
301301
/* Unix time returns the year - 1900, Windows returns the current year*/
302-
lpSystemTime->wYear = UnixSystemTime->tm_year + 1900;
302+
lpSystemTime->wYear = (WORD)UnixSystemTime->tm_year + 1900;
303303

304-
lpSystemTime->wSecond = UnixSystemTime->tm_sec;
305-
lpSystemTime->wMinute = UnixSystemTime->tm_min;
306-
lpSystemTime->wHour = UnixSystemTime->tm_hour;
304+
lpSystemTime->wSecond = (WORD)UnixSystemTime->tm_sec;
305+
lpSystemTime->wMinute = (WORD)UnixSystemTime->tm_min;
306+
lpSystemTime->wHour = (WORD)UnixSystemTime->tm_hour;
307307
return TRUE;
308308
}
309309
else

src/coreclr/pal/src/locale/utf8.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ class UTF8Encoding
10751075
DecoderReplacementFallback decoderReplacementFallback;
10761076
DecoderExceptionFallback decoderExceptionFallback;
10771077

1078-
bool InRange(WCHAR c, WCHAR begin, WCHAR end)
1078+
bool InRange(int c, int begin, int end)
10791079
{
10801080
return begin <= c && c <= end;
10811081
}

src/coreclr/pal/src/misc/time.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ GetSystemTime(
8282
goto EXIT;
8383
}
8484

85-
lpSystemTime->wYear = 1900 + utPtr->tm_year;
86-
lpSystemTime->wMonth = utPtr->tm_mon + 1;
87-
lpSystemTime->wDayOfWeek = utPtr->tm_wday;
88-
lpSystemTime->wDay = utPtr->tm_mday;
89-
lpSystemTime->wHour = utPtr->tm_hour;
90-
lpSystemTime->wMinute = utPtr->tm_min;
91-
lpSystemTime->wSecond = utPtr->tm_sec;
85+
lpSystemTime->wYear = (WORD)(1900 + utPtr->tm_year);
86+
lpSystemTime->wMonth = (WORD)(utPtr->tm_mon + 1);
87+
lpSystemTime->wDayOfWeek = (WORD)utPtr->tm_wday;
88+
lpSystemTime->wDay = (WORD)utPtr->tm_mday;
89+
lpSystemTime->wHour = (WORD)utPtr->tm_hour;
90+
lpSystemTime->wMinute = (WORD)utPtr->tm_min;
91+
lpSystemTime->wSecond = (WORD)utPtr->tm_sec;
9292

9393
if(-1 == timeofday_retval)
9494
{
@@ -101,7 +101,7 @@ GetSystemTime(
101101
int old_seconds;
102102
int new_seconds;
103103

104-
lpSystemTime->wMilliseconds = timeval.tv_usec/tccMillieSecondsToMicroSeconds;
104+
lpSystemTime->wMilliseconds = (WORD)(timeval.tv_usec/tccMillieSecondsToMicroSeconds);
105105

106106
old_seconds = utPtr->tm_sec;
107107
new_seconds = timeval.tv_sec%60;

src/coreclr/pal/src/safecrt/input.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ scanit:
665665
} else
666666
#else /* _UNICODE */
667667
if (fl_wchar_arg) {
668-
*(char16_t UNALIGNED *)pointer = ch;
668+
*(char16_t UNALIGNED *)pointer = (char16_t)ch;
669669
pointer = (char16_t *)pointer + 1;
670670
#ifdef _SECURE_SCANF
671671
--array_width;
@@ -867,7 +867,7 @@ getnum:
867867

868868
if (_ISXDIGIT(ch)) {
869869
num64 <<= 4;
870-
ch = _hextodec(ch);
870+
ch = _hextodec((_TCHAR)ch);
871871
}
872872
else
873873
++done_flag;
@@ -910,7 +910,7 @@ getnum:
910910

911911
if (_ISXDIGIT(ch)) {
912912
number = (number << 4);
913-
ch = _hextodec(ch);
913+
ch = _hextodec((_TCHAR)ch);
914914
}
915915
else
916916
++done_flag;
@@ -1262,7 +1262,7 @@ static int __cdecl _inc(miniFILE* fileptr)
12621262
static void __cdecl _un_inc(int chr, miniFILE* fileptr)
12631263
{
12641264
if (_TEOF != chr) {
1265-
_ungettc_nolock(chr,fileptr);
1265+
_ungettc_nolock((char)chr,fileptr);
12661266
}
12671267
}
12681268

src/coreclr/pal/src/safecrt/wcslwr_s.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ DLLEXPORT errno_t __cdecl _wcslwr_s(char16_t *string, size_t sz)
3030

3131
for (int i = 0; string[i] != 0; i++)
3232
{
33-
string[i] = towlower(string[i]);
33+
string[i] = (char16_t)towlower(string[i]);
3434
}
3535

3636
_FILL_STRING(string, sz, length + 1);

src/coreclr/utilcode/clrconfig.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ void CLRConfig::Initialize()
634634
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_DisableConfigCache) != 0)
635635
return;
636636

637-
const WCHAR prefixC = towlower(COMPLUS_PREFIX[0]);
638-
const WCHAR prefixD = towlower(DOTNET_PREFIX[0]);
637+
const WCHAR prefixC = (WCHAR)towlower(COMPLUS_PREFIX[0]);
638+
const WCHAR prefixD = (WCHAR)towlower(DOTNET_PREFIX[0]);
639639

640640
// Create a cache of environment variables
641641
WCHAR* wszStrings = GetEnvironmentStringsW();
@@ -645,7 +645,7 @@ void CLRConfig::Initialize()
645645
// null terminated strings
646646
for(WCHAR *wszCurr = wszStrings; *wszCurr; wszCurr++)
647647
{
648-
WCHAR wch = towlower(*wszCurr);
648+
WCHAR wch = (WCHAR)towlower(*wszCurr);
649649

650650
// Lets only cache env variables with targeted prefixes
651651
bool matchC = wch == prefixC;

src/mono/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,13 @@ if(GCC)
508508
set(WARNINGS "-Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Wno-format-zero-length -Wno-unused-function")
509509
set(WARNINGS_C "-Wmissing-prototypes -Wstrict-prototypes -Wnested-externs")
510510

511+
set(WERROR "-Werror=return-type")
512+
set(WERROR_C "-Werror=implicit-function-declaration")
513+
511514
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
512515
set(WARNINGS "${WARNINGS} -Qunused-arguments -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand -Wno-zero-length-array -Wno-asm-operand-widths")
513516
endif()
514517

515-
set(WERROR "-Werror=return-type")
516-
set(WERROR_C "-Werror=implicit-function-declaration")
517-
518518
check_c_compiler_flag("-Werror=incompatible-pointer-types" WERROR_INCOMPATIBLE_POINTER_TYPES)
519519
if(WERROR_INCOMPATIBLE_POINTER_TYPES)
520520
set(WERROR_C "${WERROR_C} -Werror=incompatible-pointer-types")

src/mono/cmake/config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#pragma warning(disable:4152) // W4: nonstandard extension, function/data pointer conversion in expression
1111
#pragma warning(disable:4201) // W4: nonstandard extension used: nameless struct/union
1212
#pragma warning(disable:4210) // W4: nonstandard extension used: function given file scope
13-
#pragma warning(disable:4244) // W2: integer conversion, possible loss of data
1413
#pragma warning(disable:4245) // W4: signed/unsigned mismatch
1514
#pragma warning(disable:4389) // W4: signed/unsigned mismatch
1615
#pragma warning(disable:4505) // W4: unreferenced function with internal linkage has been removed

0 commit comments

Comments
 (0)