Skip to content

Commit

Permalink
Reenable C4244 in repo (#70026)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
AaronRobinsonMSFT authored Jun 14, 2022
1 parent 1615e78 commit 89962a5
Show file tree
Hide file tree
Showing 39 changed files with 158 additions and 150 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/inc/corhlprpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ class RidBitmap
HRESULT hr = S_OK;
mdToken rid = RidFromToken(token);
SIZE_T index = rid / 8;
BYTE bit = (1 << (rid % 8));
BYTE bit = (BYTE)(1 << (rid % 8));

if (index >= buffer.Size())
{
Expand All @@ -623,7 +623,7 @@ class RidBitmap
{
mdToken rid = RidFromToken(token);
SIZE_T index = rid / 8;
BYTE bit = (1 << (rid % 8));
BYTE bit = (BYTE)(1 << (rid % 8));

return ((index < buffer.Size()) && (buffer[index] & bit));
}
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/inc/llvm/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ struct Elf32_Sym {
void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
void setBindingAndType(unsigned char b, unsigned char t) {
st_info = (b << 4) + (t & 0x0f);
st_info = (unsigned char)((b << 4) + (t & 0x0f));
}
};

Expand All @@ -849,7 +849,7 @@ struct Elf64_Sym {
void setBinding(unsigned char b) { setBindingAndType(b, getType()); }
void setType(unsigned char t) { setBindingAndType(getBinding(), t); }
void setBindingAndType(unsigned char b, unsigned char t) {
st_info = (b << 4) + (t & 0x0f);
st_info = (unsigned char)((b << 4) + (t & 0x0f));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/inc/pal_endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
extern "C++" {
inline UINT16 SWAP16(UINT16 x)
{
return (x >> 8) | (x << 8);
return (UINT16)((x >> 8) | (x << 8));
}

inline UINT32 SWAP32(UINT32 x)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/cruntime/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ PAL_fread(void * buffer, size_t size, size_t count, PAL_FILE * f)
}
else
{
temp[nCount++]=nChar;
temp[nCount++]= (char)nChar;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/coreclr/pal/src/cruntime/printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,

if (*Fmt && **Fmt == '%')
{
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
}
else
{
Expand All @@ -285,7 +285,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
if (**Fmt == '*')
{
*Store = FALSE;
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
}

/* grab width specifier */
Expand All @@ -294,8 +294,8 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
TempStrPtr = TempStr;
while (isdigit(**Fmt))
{
*TempStrPtr++ = **Fmt;
*Out++ = *(*Fmt)++;
*TempStrPtr++ = (CHAR)**Fmt;
*Out++ = (CHAR)*(*Fmt)++;
}
*TempStrPtr = 0; /* end string */
*Width = atoi(TempStr);
Expand Down Expand Up @@ -406,7 +406,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,

Out += strlen(scanf_longlongfmt);
}
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
Result = TRUE;
}
else if (**Fmt == 'e' || **Fmt == 'E' || **Fmt == 'f' ||
Expand All @@ -416,7 +416,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
*Type = SCANF_TYPE_FLOAT;
/* this gets rid of %E/%G since they're they're the
same when scanning */
*Out++ = tolower( *(*Fmt)++ );
*Out++ = (CHAR)tolower( *(*Fmt)++ );
Result = TRUE;
}
else if (**Fmt == 'n')
Expand All @@ -425,7 +425,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
{
*Out++ = 'h';
}
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
*Type = SCANF_TYPE_N;
Result = TRUE;
}
Expand Down Expand Up @@ -489,8 +489,8 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
unsigned char prev, next;

/* get the interval boundaries */
prev = (*Fmt)[-1];
next = (*Fmt)[1];
prev = (unsigned char)(*Fmt)[-1];
next = (unsigned char)(*Fmt)[1];

/* if boundaries were inverted, replace the already-copied
low boundary by the 'real' low boundary */
Expand All @@ -514,7 +514,7 @@ static BOOL Internal_ScanfExtractFormatW(LPCWSTR *Fmt, LPSTR Out, int iOutSize,
else
{
/* plain character; just copy it */
*Out++ = **Fmt;
*Out++ = (CHAR)**Fmt;
(*Fmt)++;
}
}
Expand Down Expand Up @@ -625,7 +625,7 @@ int PAL_wvsscanf(LPCWSTR Buffer, LPCWSTR Format, va_list ap)
{
if (Prefix == SCANF_PREFIX_SHORT)
{
*(va_arg(ap, short *)) = Buff - Buffer;
*(va_arg(ap, short *)) = (short)(Buff - Buffer);
}
else
{
Expand Down
18 changes: 9 additions & 9 deletions src/coreclr/pal/src/cruntime/printfcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
*Out++ = 'l';
*Out++ = 'l';
}
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
Result = TRUE;
}
else if (**Fmt == 'e' || **Fmt == 'E' || **Fmt == 'f' ||
Expand All @@ -719,7 +719,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
}

*Type = PFF_TYPE_FLOAT;
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
Result = TRUE;
}
else if (**Fmt == 'n')
Expand All @@ -733,7 +733,7 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L
{
*Out++ = 'h';
}
*Out++ = *(*Fmt)++;
*Out++ = (CHAR)*(*Fmt)++;
*Type = PFF_TYPE_N;
Result = TRUE;
}
Expand Down Expand Up @@ -1220,8 +1220,8 @@ int CoreVfwprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const wchar_16 *for
TempInt = va_arg(ap, INT); /* value not used */
}

TempWChar[0] = va_arg(ap, int);
TempWChar[1] = 0;
TempWChar[0] = (WCHAR)va_arg(ap, int);
TempWChar[1] = W('\0');

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

if (Prefix == PFF_PREFIX_SHORT)
{
*(va_arg(ap, short *)) = written;
*(va_arg(ap, short *)) = (short)written;
}
else
{
Expand Down Expand Up @@ -1605,7 +1605,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
TempInt = va_arg(ap, INT); /* value not used */
}

TempWChar = va_arg(ap, int);
TempWChar = (WCHAR)va_arg(ap, int);
Length = WideCharToMultiByte(CP_ACP, 0, &TempWChar, 1,
TempBuffer, sizeof(TempBuffer),
0, 0);
Expand All @@ -1617,7 +1617,7 @@ int CoreVfprintf(CPalThread *pthrCurrent, PAL_FILE *stream, const char *format,
va_end(ap);
return -1;
}
TempBuffer[Length] = 0;
TempBuffer[Length] = W('\0');

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

if (Prefix == PFF_PREFIX_SHORT)
{
*(va_arg(ap, short *)) = written;
*(va_arg(ap, short *)) = (short)written;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/pal/src/cruntime/silent_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ int Silent_PAL_vfprintf(PAL_FILE *stream, const char *format, va_list aparg)
TempInt = va_arg(ap, INT); /* value not used */
}

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

if (Prefix == PFF_PREFIX_SHORT)
{
*(va_arg(ap, short *)) = written;
*(va_arg(ap, short *)) = (short)written;
}
else
{
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/pal/src/file/filetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ BOOL PALAPI FileTimeToSystemTime( CONST FILETIME * lpFileTime,
#endif /* HAVE_GMTIME_R */

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

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

lpSystemTime->wSecond = UnixSystemTime->tm_sec;
lpSystemTime->wMinute = UnixSystemTime->tm_min;
lpSystemTime->wHour = UnixSystemTime->tm_hour;
lpSystemTime->wSecond = (WORD)UnixSystemTime->tm_sec;
lpSystemTime->wMinute = (WORD)UnixSystemTime->tm_min;
lpSystemTime->wHour = (WORD)UnixSystemTime->tm_hour;
return TRUE;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/locale/utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ class UTF8Encoding
DecoderReplacementFallback decoderReplacementFallback;
DecoderExceptionFallback decoderExceptionFallback;

bool InRange(WCHAR c, WCHAR begin, WCHAR end)
bool InRange(int c, int begin, int end)
{
return begin <= c && c <= end;
}
Expand Down
16 changes: 8 additions & 8 deletions src/coreclr/pal/src/misc/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ GetSystemTime(
goto EXIT;
}

lpSystemTime->wYear = 1900 + utPtr->tm_year;
lpSystemTime->wMonth = utPtr->tm_mon + 1;
lpSystemTime->wDayOfWeek = utPtr->tm_wday;
lpSystemTime->wDay = utPtr->tm_mday;
lpSystemTime->wHour = utPtr->tm_hour;
lpSystemTime->wMinute = utPtr->tm_min;
lpSystemTime->wSecond = utPtr->tm_sec;
lpSystemTime->wYear = (WORD)(1900 + utPtr->tm_year);
lpSystemTime->wMonth = (WORD)(utPtr->tm_mon + 1);
lpSystemTime->wDayOfWeek = (WORD)utPtr->tm_wday;
lpSystemTime->wDay = (WORD)utPtr->tm_mday;
lpSystemTime->wHour = (WORD)utPtr->tm_hour;
lpSystemTime->wMinute = (WORD)utPtr->tm_min;
lpSystemTime->wSecond = (WORD)utPtr->tm_sec;

if(-1 == timeofday_retval)
{
Expand All @@ -101,7 +101,7 @@ GetSystemTime(
int old_seconds;
int new_seconds;

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

old_seconds = utPtr->tm_sec;
new_seconds = timeval.tv_sec%60;
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/pal/src/safecrt/input.inl
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ scanit:
} else
#else /* _UNICODE */
if (fl_wchar_arg) {
*(char16_t UNALIGNED *)pointer = ch;
*(char16_t UNALIGNED *)pointer = (char16_t)ch;
pointer = (char16_t *)pointer + 1;
#ifdef _SECURE_SCANF
--array_width;
Expand Down Expand Up @@ -867,7 +867,7 @@ getnum:

if (_ISXDIGIT(ch)) {
num64 <<= 4;
ch = _hextodec(ch);
ch = _hextodec((_TCHAR)ch);
}
else
++done_flag;
Expand Down Expand Up @@ -910,7 +910,7 @@ getnum:

if (_ISXDIGIT(ch)) {
number = (number << 4);
ch = _hextodec(ch);
ch = _hextodec((_TCHAR)ch);
}
else
++done_flag;
Expand Down Expand Up @@ -1262,7 +1262,7 @@ static int __cdecl _inc(miniFILE* fileptr)
static void __cdecl _un_inc(int chr, miniFILE* fileptr)
{
if (_TEOF != chr) {
_ungettc_nolock(chr,fileptr);
_ungettc_nolock((char)chr,fileptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/safecrt/wcslwr_s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DLLEXPORT errno_t __cdecl _wcslwr_s(char16_t *string, size_t sz)

for (int i = 0; string[i] != 0; i++)
{
string[i] = towlower(string[i]);
string[i] = (char16_t)towlower(string[i]);
}

_FILL_STRING(string, sz, length + 1);
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/utilcode/clrconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ void CLRConfig::Initialize()
if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_DisableConfigCache) != 0)
return;

const WCHAR prefixC = towlower(COMPLUS_PREFIX[0]);
const WCHAR prefixD = towlower(DOTNET_PREFIX[0]);
const WCHAR prefixC = (WCHAR)towlower(COMPLUS_PREFIX[0]);
const WCHAR prefixD = (WCHAR)towlower(DOTNET_PREFIX[0]);

// Create a cache of environment variables
WCHAR* wszStrings = GetEnvironmentStringsW();
Expand All @@ -645,7 +645,7 @@ void CLRConfig::Initialize()
// null terminated strings
for(WCHAR *wszCurr = wszStrings; *wszCurr; wszCurr++)
{
WCHAR wch = towlower(*wszCurr);
WCHAR wch = (WCHAR)towlower(*wszCurr);

// Lets only cache env variables with targeted prefixes
bool matchC = wch == prefixC;
Expand Down
6 changes: 3 additions & 3 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,13 @@ if(GCC)
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")
set(WARNINGS_C "-Wmissing-prototypes -Wstrict-prototypes -Wnested-externs")

set(WERROR "-Werror=return-type")
set(WERROR_C "-Werror=implicit-function-declaration")

if (CMAKE_C_COMPILER_ID MATCHES "Clang")
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")
endif()

set(WERROR "-Werror=return-type")
set(WERROR_C "-Werror=implicit-function-declaration")

check_c_compiler_flag("-Werror=incompatible-pointer-types" WERROR_INCOMPATIBLE_POINTER_TYPES)
if(WERROR_INCOMPATIBLE_POINTER_TYPES)
set(WERROR_C "${WERROR_C} -Werror=incompatible-pointer-types")
Expand Down
1 change: 0 additions & 1 deletion src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#pragma warning(disable:4152) // W4: nonstandard extension, function/data pointer conversion in expression
#pragma warning(disable:4201) // W4: nonstandard extension used: nameless struct/union
#pragma warning(disable:4210) // W4: nonstandard extension used: function given file scope
#pragma warning(disable:4244) // W2: integer conversion, possible loss of data
#pragma warning(disable:4245) // W4: signed/unsigned mismatch
#pragma warning(disable:4389) // W4: signed/unsigned mismatch
#pragma warning(disable:4505) // W4: unreferenced function with internal linkage has been removed
Expand Down
Loading

0 comments on commit 89962a5

Please sign in to comment.