Skip to content

[Mono] Fix warnings to enable W4 on Windows. #66710

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

Merged
merged 24 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8f529cb
Fix diagnostics_tracing_objects to build under W4 on Windows.
lateralusX Mar 16, 2022
3ebc4ca
Fix debugger-objects to build under W4 on Windows.
lateralusX Mar 29, 2022
fb9f87b
Fix monosgen-objects and monosgen-shared to build under W4 on Windows.
lateralusX Mar 24, 2022
8d254ec
Fix hot-reload-objects to build under W4 on Windows.
lateralusX Mar 21, 2022
f996846
Enable warning level W4 on Windows + disable not yet fixed w4 warnings.
lateralusX Mar 17, 2022
a504e9a
Fix signed/unsigned in for blocks of modified files.
lateralusX Mar 21, 2022
e51f349
Fix Warning 4146 on Windows.
lateralusX Mar 21, 2022
4d1655e
Enable warnings as errors on Windows build to prevent regression.
lateralusX Mar 21, 2022
a5f5219
Fix build error in mscordbi socket.
lateralusX Mar 22, 2022
bb04cb4
Fix additional warnings added since rebase.
lateralusX Mar 22, 2022
9e3f55f
Fix Windows x86 warnings.
lateralusX Mar 22, 2022
67245c1
Fix additional warnings.
lateralusX Mar 23, 2022
4da5f0c
Fix build error.
lateralusX Mar 23, 2022
592ae95
Fix warning build errors.
lateralusX Mar 23, 2022
62f2553
Switch back from treating all warnings as errors to promote strategy.
lateralusX Mar 25, 2022
926c058
Fix some more warnings.
lateralusX Mar 28, 2022
6a2b9d0
Disable some warnings as errors to flush out last CI failures.
lateralusX Mar 29, 2022
4b765ec
Fix warnings on x86/arm.
lateralusX Mar 29, 2022
a287d25
Fix build error.
lateralusX Mar 29, 2022
4071809
Re-enable warnings.
lateralusX Mar 29, 2022
00d6b20
Fix build errors.
lateralusX Mar 30, 2022
c259ec3
32-bit shift assumes wrap around in some scenarios.
lateralusX Apr 4, 2022
3b635bd
Review feedback.
lateralusX Apr 6, 2022
0617776
Disable zlib warnings in cmake instead of source files.
lateralusX Apr 11, 2022
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
11 changes: 9 additions & 2 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(MONO_ZERO_LEN_ARRAY 1)
set(INTERNAL_ZLIB 1)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") # statically link VC runtime library
add_compile_options(/W3) # set warning level 3
add_compile_options(/W4) # set warning level 4
add_compile_options(/EHsc) # set exception handling behavior
add_compile_options(/FC) # use full pathnames in diagnostics
add_link_options(/STACK:0x800000) # set stack size to 8MB (default is 1MB)
Expand Down Expand Up @@ -623,7 +623,14 @@ if(LLVM_PREFIX)
set(LLVM_LIBDIR "${LLVM_PREFIX}/lib")
set(LLVM_INCLUDEDIR "${llvm_includedir}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${llvm_cflags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${llvm_cxxflags} -fexceptions -fno-rtti")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# /EHsc already enabled, prevent LLVM flags to disable it. Corresponds to -fexceptions.
string(REPLACE "/EHs-c-" "" llvm_cxxflags "${llvm_cxxflags}")
# /GR- already enabled and inherited from LLVM flags. Corresponds to -fno-rtti.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${llvm_cxxflags}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${llvm_cxxflags} -fexceptions -fno-rtti")
endif()
add_definitions(-DLLVM_API_VERSION=${llvm_api_version})
endif()

Expand Down
54 changes: 39 additions & 15 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,47 @@
#ifdef _MSC_VER

// FIXME This is all questionable but the logs are flooded and nothing else is fixing them.
#pragma warning(disable:4018) // signed/unsigned mismatch
#pragma warning(disable:4090) // const problem
#pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
#pragma warning(disable:4244) // integer conversion, possible loss of data
#pragma warning(disable:4018) // W3: signed/unsigned mismatch
#pragma warning(disable:4090) // W1: const problem
#pragma warning(disable:4100) // W4: unreferenced formal parameter
#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
#pragma warning(disable:4702) // W4: unreachable code
#pragma warning(disable:4706) // W4: assignment within conditional expression

// promote warnings to errors
#pragma warning( error:4013) // function undefined; assuming extern returning int
#pragma warning( error:4022) // call and prototype disagree
#pragma warning( error:4047) // differs in level of indirection
#pragma warning( error:4098) // void return returns a value
#pragma warning( error:4113) // call and prototype disagree
#pragma warning( error:4172) // returning address of local variable or temporary
#pragma warning( error:4197) // top-level volatile in cast is ignored
#pragma warning( error:4273) // inconsistent dll linkage
#pragma warning( error:4293) // shift count negative or too big, undefined behavior
#pragma warning( error:4312) // 'type cast': conversion from 'MonoNativeThreadId' to 'gpointer' of greater size
#pragma warning( error:4715) // 'keyword' not all control paths return a value
#pragma warning(error:4005) // W1: 'identifier' : macro redefinition
#pragma warning(error:4013) // W3: function undefined; assuming extern returning int
#pragma warning(error:4022) // W1: call and prototype disagree
#pragma warning(error:4047) // W1: differs in level of indirection
#pragma warning(error:4065) // W?: switch with default but no case
#pragma warning(error:4098) // W1: void return returns a value
#pragma warning(error:4113) // W1: call and prototype disagree
#pragma warning(error:4127) // W4: conditional expression is constant
#pragma warning(error:4131) // W4: 'function' : uses old-style declarator
#pragma warning(error:4146) // W2: unary minus operator applied to unsigned type, result still unsigned
#pragma warning(error:4172) // W1: returning address of local variable or temporary
#pragma warning(error:4189) // W4: local variable is initialized but not referenced
#pragma warning(error:4197) // W3: top-level volatile in cast is ignored
#pragma warning(error:4273) // W1: inconsistent dll linkage
#pragma warning(error:4293) // W1: shift count negative or too big, undefined behavior
#pragma warning(error:4297) // W1: function assumed not to throw an exception but does
#pragma warning(error:4306) // W2: conversion from 'type1' to 'type2' of greater size
#pragma warning(error:4309) // W2: truncation of constant
#pragma warning(error:4310) // W3: cast truncates constant value
#pragma warning(error:4312) // W1: conversion from 'type1' to 'type2' of greater size
#pragma warning(error:4324) // W4: structure was padded due to __declspec(align())
#pragma warning(error:4456) // W4: declaration of 'identifier' hides previous local declaration
#pragma warning(error:4459) // W4: declaration of 'identifier' hides global declaration
#pragma warning(error:4701) // W4: potentially uninitialized local variable 'name' used
#pragma warning(error:4703) // W4: potentially uninitialized local pointer variable 'name' used
#pragma warning(error:4715) // W1: 'function' : not all control paths return a value
#pragma warning(error:4740) // W4: flow in or out of inline asm code suppresses global optimization, x86 only

#include <SDKDDKVer.h>

Expand Down
23 changes: 12 additions & 11 deletions src/mono/dlls/mscordbi/socket-dbi/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,26 @@
#endif
#include <errno.h>
#include <stdio.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#endif


Socket::~Socket()
{
Close();
}

int Socket::OpenSocketAcceptConnection(const char *address, const char *port) {
socketId = -1;
socketId = INVALID_SOCKET;

#ifdef WIN32
WSADATA wsadata;
int err;
WSADATA wsadata;
int err;

err = WSAStartup (2, &wsadata);
if (err) {
err = WSAStartup (2, &wsadata);
if (err) {
return -1;
}
}
#endif

struct addrinfo *result = NULL, *ptr = NULL, hints;
Expand All @@ -71,7 +72,7 @@ int Socket::OpenSocketAcceptConnection(const char *address, const char *port) {
// Create a SOCKET for connecting to server
socketId = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);

if (socketId == -1) {
if (socketId == INVALID_SOCKET) {
return -1;
}

Expand All @@ -80,17 +81,17 @@ int Socket::OpenSocketAcceptConnection(const char *address, const char *port) {
continue;

iResult = bind(socketId, ptr->ai_addr, (int)ptr->ai_addrlen);
if (iResult == -1)
if (iResult == SOCKET_ERROR)
continue;

iResult = listen(socketId, 16);
if (iResult == -1)
if (iResult == SOCKET_ERROR)
continue;

break;
}

if (iResult != -1)
if (iResult != SOCKET_ERROR)
socketId = accept(socketId, NULL, NULL);

freeaddrinfo(result);
Expand Down
9 changes: 9 additions & 0 deletions src/mono/dlls/mscordbi/socket-dbi/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@
#ifndef __SOCKET_DBI_H__
#define __SOCKET_DBI_H__

#ifdef WIN32
#include <winsock2.h>
#endif

class Socket {
#ifdef WIN32
SOCKET socketId;
#else
long long socketId;
#endif

public:
~Socket();
int OpenSocketAcceptConnection(const char *address, const char *port);
Expand Down
52 changes: 26 additions & 26 deletions src/mono/mono/arch/x86/x86-codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ typedef union {
x86_byte (inst, imb.b [2]); \
x86_byte (inst, imb.b [3]); \
} while (0)
#define x86_imm_emit16(inst,imm) do { *(short*)(inst) = (imm); (inst) += 2; } while (0)
#define x86_imm_emit16(inst,imm) do { *(short*)(inst) = (short)(imm); (inst) += 2; } while (0)
#define x86_imm_emit8(inst,imm) do { *(inst) = (unsigned char)((imm) & 0xff); ++(inst); } while (0)
#define x86_is_imm8(imm) (((int)(imm) >= -128 && (int)(imm) <= 127))
#define x86_is_imm16(imm) (((int)(imm) >= -(1<<16) && (int)(imm) <= ((1<<16)-1)))
Expand Down Expand Up @@ -1783,45 +1783,45 @@ mono_x86_patch_inline (guchar* code, gpointer target)
#if defined(TARGET_X86)
#define x86_branch(inst,cond,target,is_signed) \
do { \
int offset; \
guint8* branch_start; \
int __offset; \
guint8* __branch_start; \
x86_codegen_pre(&(inst), 2); \
offset = (target) - (inst) - 2; \
branch_start = (inst); \
if (x86_is_imm8 ((offset))) \
x86_branch8 ((inst), (cond), offset, (is_signed)); \
else { \
__offset = (target) - (inst) - 2; \
__branch_start = (inst); \
if (x86_is_imm8 ((__offset))) \
x86_branch8 ((inst), (cond), __offset, (is_signed)); \
else { \
x86_codegen_pre(&(inst), 6); \
offset = (target) - (inst) - 6; \
x86_branch32 ((inst), (cond), offset, (is_signed)); \
} \
x86_patch(branch_start, (target)); \
__offset = (target) - (inst) - 6; \
x86_branch32 ((inst), (cond), __offset, (is_signed)); \
} \
x86_patch(__branch_start, (target)); \
} while (0)
#elif defined(TARGET_AMD64)
/* This macro is used directly from mini-amd64.c and other */
/* amd64 specific files, so it needs to be instrumented directly. */

#define x86_branch(inst,cond,target,is_signed) \
do { \
int offset = (target) - (inst) - 2; \
if (x86_is_imm8 ((offset))) \
x86_branch8 ((inst), (cond), offset, (is_signed)); \
else { \
offset = (target) - (inst) - 6; \
x86_branch32 ((inst), (cond), offset, (is_signed)); \
} \
#define x86_branch(inst,cond,target,is_signed) \
do { \
int __offset = (target) - (inst) - 2; \
if (x86_is_imm8 ((__offset))) \
x86_branch8 ((inst), (cond), __offset, (is_signed)); \
else { \
__offset = (target) - (inst) - 6; \
x86_branch32 ((inst), (cond), __offset, (is_signed)); \
} \
} while (0)

#endif /* TARGET_AMD64 */

#define x86_branch_disp(inst,cond,disp,is_signed) \
do { \
int offset = (disp) - 2; \
if (x86_is_imm8 ((offset))) \
x86_branch8 ((inst), (cond), offset, (is_signed)); \
int __offset = (disp) - 2; \
if (x86_is_imm8 ((__offset))) \
x86_branch8 ((inst), (cond), __offset, (is_signed)); \
else { \
offset -= 4; \
x86_branch32 ((inst), (cond), offset, (is_signed)); \
__offset -= 4; \
x86_branch32 ((inst), (cond), __offset, (is_signed)); \
} \
} while (0)

Expand Down
Loading