fix Clang warnings

This commit is contained in:
oltolm 2023-06-28 00:10:25 +02:00
parent 99991e4d48
commit 246fd9a4da
23 changed files with 88 additions and 55 deletions

View file

@ -148,7 +148,9 @@ bool ApplyUcrtPatch(const wchar_t* name, const UcrtPatchInfo& patch)
return true;
}
#ifdef _MSC_VER
#pragma comment(lib, "version.lib")
#endif
struct Version
{
@ -244,6 +246,7 @@ void CompatPatchesInstall(LdrWatcher* watcher)
}});
}
#ifdef _MSC_VER
int __cdecl EnableCompatPatches()
{
static LdrWatcher watcher;
@ -263,4 +266,5 @@ int __cdecl EnableCompatPatches()
extern "C" {
__declspec(allocate(".CRT$XCZ")) decltype(&EnableCompatPatches)
enableCompatPatches = EnableCompatPatches;
}
};
#endif

View file

@ -12,7 +12,7 @@ class GLContextWGL final : public GLContext
public:
~GLContextWGL();
bool IsHeadless() const;
bool IsHeadless() const override;
std::unique_ptr<GLContext> CreateSharedContext() override;

View file

@ -137,8 +137,10 @@ LdrWatcher::~LdrWatcher()
UninstallAll();
}
#ifdef _MSC_VER
// Needed for RtlInitUnicodeString
#pragma comment(lib, "ntdll")
#endif
bool LdrWatcher::InjectCurrentModules(const LdrObserver& observer)
{

View file

@ -464,7 +464,7 @@ void* LazyMemoryRegion::Create(size_t size)
const size_t memory_size = Common::AlignUp(size, BLOCK_SIZE);
const size_t block_count = memory_size / BLOCK_SIZE;
u8* memory =
static_cast<u8*>(static_cast<PVirtualAlloc2>(m_memory_functions.m_address_VirtualAlloc2)(
static_cast<u8*>(reinterpret_cast<PVirtualAlloc2>(m_memory_functions.m_address_VirtualAlloc2)(
nullptr, nullptr, memory_size, MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, PAGE_NOACCESS,
nullptr, 0));
if (!memory)
@ -506,7 +506,7 @@ void* LazyMemoryRegion::Create(size_t size)
// map the zero page into every block
for (size_t i = 0; i < block_count; ++i)
{
void* result = static_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
void* result = reinterpret_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
zero_block, nullptr, memory + i * BLOCK_SIZE, 0, BLOCK_SIZE, MEM_REPLACE_PLACEHOLDER,
PAGE_READONLY, nullptr, 0);
if (!result)
@ -534,7 +534,7 @@ void LazyMemoryRegion::Clear()
continue;
// unmap the writable block
if (!static_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
if (!reinterpret_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
memory + i * BLOCK_SIZE, MEM_PRESERVE_PLACEHOLDER))
{
PanicAlertFmt("Failed to unmap the writable block: {}", GetLastErrorString());
@ -548,9 +548,10 @@ void LazyMemoryRegion::Clear()
m_writable_block_handles[i] = nullptr;
// map the zero block
void* map_result = static_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
m_zero_block, nullptr, memory + i * BLOCK_SIZE, 0, BLOCK_SIZE, MEM_REPLACE_PLACEHOLDER,
PAGE_READONLY, nullptr, 0);
void* map_result =
reinterpret_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
m_zero_block, nullptr, memory + i * BLOCK_SIZE, 0, BLOCK_SIZE, MEM_REPLACE_PLACEHOLDER,
PAGE_READONLY, nullptr, 0);
if (!map_result)
{
PanicAlertFmt("Failed to re-map the zero block: {}", GetLastErrorString());
@ -566,7 +567,7 @@ void LazyMemoryRegion::Release()
u8* const memory = static_cast<u8*>(m_memory);
for (size_t i = 0; i < m_writable_block_handles.size(); ++i)
{
static_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
reinterpret_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
memory + i * BLOCK_SIZE, MEM_PRESERVE_PLACEHOLDER);
if (m_writable_block_handles[i])
{
@ -596,7 +597,7 @@ void LazyMemoryRegion::MakeMemoryBlockWritable(size_t block_index)
u8* const memory = static_cast<u8*>(m_memory);
// unmap the zero block
if (!static_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
if (!reinterpret_cast<PUnmapViewOfFileEx>(m_memory_functions.m_address_UnmapViewOfFileEx)(
memory + block_index * BLOCK_SIZE, MEM_PRESERVE_PLACEHOLDER))
{
PanicAlertFmt("Failed to unmap the zero block: {}", GetLastErrorString());
@ -613,7 +614,7 @@ void LazyMemoryRegion::MakeMemoryBlockWritable(size_t block_index)
}
// map the new block
void* map_result = static_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
void* map_result = reinterpret_cast<PMapViewOfFile3>(m_memory_functions.m_address_MapViewOfFile3)(
block, nullptr, memory + block_index * BLOCK_SIZE, 0, BLOCK_SIZE, MEM_REPLACE_PLACEHOLDER,
PAGE_READWRITE, nullptr, 0);
if (!map_result)

View file

@ -5,8 +5,10 @@
#if defined(_WIN32)
#include <Qos2.h>
#ifdef _MSC_VER
#pragma comment(lib, "qwave")
#endif
#endif
#include "Core/ConfigManager.h"

View file

@ -581,6 +581,10 @@ std::string UTF16BEToUTF8(const char16_t* str, size_t max_size)
#endif
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
std::string UTF16ToUTF8(std::u16string_view input)
{
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
@ -592,6 +596,9 @@ std::u16string UTF8ToUTF16(std::string_view input)
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter;
return converter.from_bytes(input.data(), input.data() + input.size());
}
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
// This is a replacement for path::u8path, which is deprecated starting with C++20.
std::filesystem::path StringToPath(std::string_view path)
@ -625,7 +632,7 @@ std::vector<std::string> CommandLineToUtf8Argv(const wchar_t* command_line)
return {};
std::vector<std::string> argv(nargs);
for (size_t i = 0; i < nargs; ++i)
for (int i = 0; i < nargs; ++i)
{
argv[i] = WStringToUTF8(tokenized[i]);
}

View file

@ -11,7 +11,7 @@ namespace Common
std::optional<std::tm> Localtime(std::time_t time)
{
std::tm local_time;
#ifdef _MSC_VER
#ifdef _WIN32
if (localtime_s(&local_time, &time) != 0)
return std::nullopt;
#else

View file

@ -803,7 +803,12 @@ sf::Socket::Status BbaTcpSocket::Connect(const sf::IpAddress& dest, u16 port, u3
addr.sin_addr.s_addr = net_ip;
addr.sin_family = AF_INET;
addr.sin_port = 0;
(void)::bind(getNativeHandle(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr));
if (::bind(getNativeHandle(), reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) != 0)
{
ERROR_LOG_FMT(SP1, "bind failed: {}", Common::StrNetworkError());
m_connecting_state = ConnectingState::Error;
return sf::Socket::Status::Error;
}
m_connecting_state = ConnectingState::Connecting;
return this->connect(dest, port);
}
@ -837,7 +842,7 @@ BbaTcpSocket::ConnectingState BbaTcpSocket::Connected(StackRef* ref)
{
case ConnectingState::Connecting:
{
const int fd = getNativeHandle();
const sf::SocketHandle fd = getNativeHandle();
const s32 nfds = fd + 1;
fd_set read_fds;
fd_set write_fds;

View file

@ -32,6 +32,7 @@ using ws_ssize_t = int;
#else
#define closesocket close
using ws_ssize_t = ssize_t;
#define SOCKET int
#endif
#ifdef __linux__
@ -260,7 +261,7 @@ void TAPServerConnection::ReadThreadHandler()
{
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(m_fd, &rfds);
FD_SET((SOCKET)m_fd, &rfds);
timeval timeout;
timeout.tv_sec = 0;

View file

@ -36,6 +36,7 @@
#define ERRORCODE(name) name
#define EITHER(win32, posix) posix
#define closesocket close
#define SOCKET int
#endif
namespace IOS::HLE
@ -774,8 +775,8 @@ WiiSocket::ConnectingState WiiSocket::GetConnectingState() const
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&except_fds);
FD_SET(fd, &write_fds);
FD_SET(fd, &except_fds);
FD_SET((SOCKET)fd, &write_fds);
FD_SET((SOCKET)fd, &except_fds);
if (select(nfds, &read_fds, &write_fds, &except_fds, &t) < 0)
{
@ -1011,9 +1012,9 @@ void WiiSockMan::Update()
const WiiSocket& sock = socket_iter->second;
if (sock.IsValid())
{
FD_SET(sock.fd, &read_fds);
FD_SET(sock.fd, &write_fds);
FD_SET(sock.fd, &except_fds);
FD_SET((SOCKET)sock.fd, &read_fds);
FD_SET((SOCKET)sock.fd, &write_fds);
FD_SET((SOCKET)sock.fd, &except_fds);
nfds = std::max(nfds, sock.fd + 1);
++socket_iter;
}
@ -1176,7 +1177,8 @@ WiiSockAddrIn WiiSockMan::ToWiiAddrIn(const sockaddr_in& from, socklen_t addrlen
{
WiiSockAddrIn result;
result.len = u8(addrlen > sizeof(WiiSockAddrIn) ? sizeof(WiiSockAddrIn) : addrlen);
result.len =
u8(static_cast<size_t>(addrlen) > sizeof(WiiSockAddrIn) ? sizeof(WiiSockAddrIn) : addrlen);
result.family = u8(from.sin_family & 0xFF);
result.port = from.sin_port;
result.addr.addr = from.sin_addr.s_addr;

View file

@ -23,6 +23,7 @@ typedef SSIZE_T ssize_t;
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SOCKET int
#endif
#include "Common/Assert.h"
@ -264,7 +265,7 @@ static bool IsDataAvailable()
fd_set _fds, *fds = &_fds;
FD_ZERO(fds);
FD_SET(s_sock, fds);
FD_SET((SOCKET)s_sock, fds);
t.tv_sec = 0;
t.tv_usec = 20;

View file

@ -30,7 +30,7 @@ public:
void SetTitle(const std::string& string) override;
void MainLoop() override;
WindowSystemInfo GetWindowSystemInfo() const;
WindowSystemInfo GetWindowSystemInfo() const override;
private:
static constexpr TCHAR WINDOW_CLASS_NAME[] = _T("DolphinNoGUI");

View file

@ -110,10 +110,6 @@ static bool QtMsgAlertHandler(const char* caption, const char* text, bool yes_no
return false;
}
#ifdef _WIN32
#define main app_main
#endif
int main(int argc, char* argv[])
{
#ifdef _WIN32
@ -320,5 +316,4 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
return main(argc, argv.data());
}
#undef main
#endif

View file

@ -11,8 +11,10 @@
#include "InputCommon/ControllerInterface/DInput/DInputJoystick.h"
#include "InputCommon/ControllerInterface/DInput/DInputKeyboardMouse.h"
#ifdef _MSC_VER
#pragma comment(lib, "Dinput8.lib")
#pragma comment(lib, "dxguid.lib")
#endif
namespace ciface::DInput
{

View file

@ -45,7 +45,7 @@ private:
{
public:
Hat(u8 index, const DWORD& hat, u8 direction)
: m_hat(hat), m_direction(direction), m_index(index)
: m_hat(hat), m_index(index), m_direction(direction)
{
}
std::string GetName() const override;

View file

@ -18,7 +18,9 @@
#include "InputCommon/ControllerInterface/WGInput/WGInput.h"
#include "InputCommon/ControllerInterface/XInput/XInput.h"
#ifdef _MSC_VER
#pragma comment(lib, "OneCoreUAP.Lib")
#endif
static std::mutex s_populate_mutex;
// TODO is this really needed?

View file

@ -15,8 +15,6 @@
namespace DX11
{
std::mutex s_input_layout_lock;
std::unique_ptr<NativeVertexFormat>
Gfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
{

View file

@ -85,7 +85,7 @@ bool VertexManager::Initialize()
D3D11_BIND_INDEX_BUFFER | D3D11_BIND_VERTEX_BUFFER,
D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
for (int i = 0; i < BUFFER_COUNT; i++)
for (u32 i = 0; i < BUFFER_COUNT; i++)
{
HRESULT hr = D3D::device->CreateBuffer(&bufdesc, nullptr, &m_buffers[i]);
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to create buffer: {}", DX11HRWrap(hr));

View file

@ -38,7 +38,7 @@ public:
VertexManager();
~VertexManager();
bool Initialize();
bool Initialize() override;
void UploadUtilityUniforms(const void* uniforms, u32 uniforms_size) override;
bool UploadTexelBuffer(const void* data, u32 data_size, TexelBufferFormat format,

View file

@ -12,8 +12,8 @@ namespace DX12
{
using Microsoft::WRL::ComPtr;
static void ResourceBarrier(ID3D12GraphicsCommandList* cmdlist, ID3D12Resource* resource,
D3D12_RESOURCE_STATES from_state, D3D12_RESOURCE_STATES to_state)
static inline void ResourceBarrier(ID3D12GraphicsCommandList* cmdlist, ID3D12Resource* resource,
D3D12_RESOURCE_STATES from_state, D3D12_RESOURCE_STATES to_state)
{
const D3D12_RESOURCE_BARRIER barrier = {
D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,

View file

@ -45,7 +45,7 @@ static ComPtr<ID3D12Resource> CreateTextureUploadBuffer(u32 buffer_size)
DXTexture::DXTexture(const TextureConfig& config, ID3D12Resource* resource,
D3D12_RESOURCE_STATES state, std::string_view name)
: AbstractTexture(config), m_resource(resource), m_state(state), m_name(UTF8ToWString(name))
: AbstractTexture(config), m_resource(resource), m_name(UTF8ToWString(name)), m_state(state)
{
if (!m_name.empty())
{
@ -331,14 +331,16 @@ void DXTexture::Load(u32 level, u32 width, u32 height, u32 row_length, const u8*
// Issue copy from buffer->texture.
const u32 aligned_width = Common::AlignUp(width, block_size);
const u32 aligned_height = Common::AlignUp(height, block_size);
const D3D12_TEXTURE_COPY_LOCATION dst_loc = {m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{static_cast<UINT>(CalcSubresource(level, layer))}};
const D3D12_TEXTURE_COPY_LOCATION dst_loc = {
m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{{static_cast<UINT>(CalcSubresource(level, layer))}}};
const D3D12_TEXTURE_COPY_LOCATION src_loc = {
upload_buffer_resource,
D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
{{upload_buffer_offset, D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false),
aligned_width, aligned_height, 1, upload_stride}}};
{{upload_buffer_offset,
{D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false), aligned_width,
aligned_height, 1, upload_stride}}}};
const D3D12_BOX src_box{0, 0, 0, aligned_width, aligned_height, 1};
g_dx_context->GetCommandList()->CopyTextureRegion(&dst_loc, 0, 0, 0, &src_loc, &src_box);
@ -363,11 +365,11 @@ void DXTexture::CopyRectangleFromTexture(const AbstractTexture* src,
const D3D12_TEXTURE_COPY_LOCATION dst_loc = {
m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{static_cast<UINT>(CalcSubresource(dst_level, dst_layer))}};
{{static_cast<UINT>(CalcSubresource(dst_level, dst_layer))}}};
const D3D12_TEXTURE_COPY_LOCATION src_loc = {
src_dxtex->m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{static_cast<UINT>(src_dxtex->CalcSubresource(src_level, src_layer))}};
{{static_cast<UINT>(src_dxtex->CalcSubresource(src_level, src_layer))}}};
const D3D12_BOX src_box = RectangleToBox(src_rect);
const D3D12_RESOURCE_STATES old_src_state = src_dxtex->m_state;
src_dxtex->TransitionToState(D3D12_RESOURCE_STATE_COPY_SOURCE);
@ -686,12 +688,13 @@ void DXStagingTexture::CopyFromTexture(const AbstractTexture* src,
const D3D12_TEXTURE_COPY_LOCATION dst_loc = {
m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
{0,
{D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false), m_config.width,
m_config.height, 1u, static_cast<UINT>(m_map_stride)}}};
{{0,
{D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false), m_config.width,
m_config.height, 1u, static_cast<UINT>(m_map_stride)}}}};
const D3D12_TEXTURE_COPY_LOCATION src_loc = {
src_tex->GetResource(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
static_cast<UINT>(src_tex->CalcSubresource(src_level, src_layer))};
src_tex->GetResource(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{{static_cast<UINT>(src_tex->CalcSubresource(src_level, src_layer))}}};
const D3D12_BOX src_box = RectangleToBox(src_rect);
g_dx_context->GetCommandList()->CopyTextureRegion(&dst_loc, dst_rect.left, dst_rect.top, 0,
&src_loc, &src_box);
@ -725,14 +728,15 @@ void DXStagingTexture::CopyToTexture(const MathUtil::Rectangle<int>& src_rect, A
// Copy from VRAM -> host-visible memory.
const D3D12_TEXTURE_COPY_LOCATION dst_loc = {
dst_tex->GetResource(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
static_cast<UINT>(dst_tex->CalcSubresource(dst_level, dst_layer))};
dst_tex->GetResource(),
D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
{{static_cast<UINT>(dst_tex->CalcSubresource(dst_level, dst_layer))}}};
const D3D12_TEXTURE_COPY_LOCATION src_loc = {
m_resource.Get(),
D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
{0,
{D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false), m_config.width,
m_config.height, 1u, static_cast<UINT>(m_map_stride)}}};
{{0,
{D3DCommon::GetDXGIFormatForAbstractFormat(m_config.format, false), m_config.width,
m_config.height, 1u, static_cast<UINT>(m_map_stride)}}}};
const D3D12_BOX src_box = RectangleToBox(src_rect);
g_dx_context->GetCommandList()->CopyTextureRegion(&dst_loc, dst_rect.left, dst_rect.top, 0,
&src_loc, &src_box);

View file

@ -25,7 +25,7 @@ namespace
{
std::chrono::system_clock::time_point FileTimeToSysTime(std::filesystem::file_time_type file_time)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(__clang__)
return std::chrono::clock_cast<std::chrono::system_clock>(file_time);
#else
// Note: all compilers should switch to chrono::clock_cast

View file

@ -76,10 +76,17 @@ VideoBackendBase* g_video_backend = nullptr;
// performance graphics mode or using the IGP.
// AMD drivers >= 13.35 do the same, but for the variable
// named AmdPowerXpressRequestHighPerformance instead.
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-variable-declarations"
#endif
extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
#endif
std::string VideoBackendBase::BadShaderFilename(const char* shader_stage, int counter)