From ca92d4ea3d87bdc0b81c8f3b891501b3e2bcc128 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Dec 2022 15:56:43 +1000 Subject: [PATCH] Common: Warning fixes for clang-cl --- common/CMakeLists.txt | 1 + common/CrashHandler.cpp | 2 +- common/D3D11/ShaderCache.h | 3 ++- common/D3D11/ShaderCompiler.h | 4 +++- common/D3D12/Builders.h | 2 +- common/D3D12/DescriptorHeapManager.h | 2 +- common/D3D12/ShaderCache.h | 2 +- common/D3D12/StreamBuffer.h | 2 +- common/GL/ContextWGL.cpp | 12 +++++----- common/Pcsx2Defs.h | 2 +- common/RedtapeWilCom.h | 34 ++++++++++++++++++++++++++++ common/StackWalker.cpp | 11 +++++++-- common/VirtualMemory.cpp | 2 +- common/Vulkan/Loader.h | 1 + common/Vulkan/SwapChain.cpp | 3 +++ common/Windows/WinHostSys.cpp | 2 -- common/emitter/cpudetect.cpp | 4 ++-- 17 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 common/RedtapeWilCom.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 31f350f638..0221d8f3a4 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -91,6 +91,7 @@ target_sources(common PRIVATE PrecompiledHeader.h ProgressCallback.h ReadbackSpinManager.h + RedtapeWilCom.h RedtapeWindows.h SafeArray.h ScopedGuard.h diff --git a/common/CrashHandler.cpp b/common/CrashHandler.cpp index 9ee1c49230..2224753159 100644 --- a/common/CrashHandler.cpp +++ b/common/CrashHandler.cpp @@ -114,7 +114,7 @@ static void WriteMinidumpAndCallstack(PEXCEPTION_POINTERS exi) { char line[1024]; DWORD written; - std::snprintf(line, std::size(line), "Exception 0x%08X at 0x%p\n", exi->ExceptionRecord->ExceptionCode, + std::snprintf(line, std::size(line), "Exception 0x%08X at 0x%p\n", static_cast(exi->ExceptionRecord->ExceptionCode), exi->ExceptionRecord->ExceptionAddress); WriteFile(hFile, line, static_cast(std::strlen(line)), &written, nullptr); } diff --git a/common/D3D11/ShaderCache.h b/common/D3D11/ShaderCache.h index 5c5fc5a5a0..25f3c40912 100644 --- a/common/D3D11/ShaderCache.h +++ b/common/D3D11/ShaderCache.h @@ -17,13 +17,14 @@ #include "common/Pcsx2Defs.h" #include "common/HashCombine.h" #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" #include "common/D3D11/ShaderCompiler.h" + #include #include #include #include #include -#include namespace D3D11 { diff --git a/common/D3D11/ShaderCompiler.h b/common/D3D11/ShaderCompiler.h index 1c50b88e2e..26c6442b92 100644 --- a/common/D3D11/ShaderCompiler.h +++ b/common/D3D11/ShaderCompiler.h @@ -14,11 +14,13 @@ */ #pragma once + #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" + #include #include #include -#include namespace D3D11::ShaderCompiler { diff --git a/common/D3D12/Builders.h b/common/D3D12/Builders.h index 625b1c0706..37356e2c5c 100644 --- a/common/D3D12/Builders.h +++ b/common/D3D12/Builders.h @@ -17,10 +17,10 @@ #include "common/Pcsx2Defs.h" #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" #include #include -#include namespace D3D12 { diff --git a/common/D3D12/DescriptorHeapManager.h b/common/D3D12/DescriptorHeapManager.h index a0edf9822a..875ee6cb5f 100644 --- a/common/D3D12/DescriptorHeapManager.h +++ b/common/D3D12/DescriptorHeapManager.h @@ -18,13 +18,13 @@ #include "common/Pcsx2Defs.h" #include "common/HashCombine.h" #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" #include #include #include #include #include -#include namespace D3D12 { diff --git a/common/D3D12/ShaderCache.h b/common/D3D12/ShaderCache.h index 48f5b9afa9..7befa3436d 100644 --- a/common/D3D12/ShaderCache.h +++ b/common/D3D12/ShaderCache.h @@ -18,13 +18,13 @@ #include "common/Pcsx2Defs.h" #include "common/HashCombine.h" #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" #include #include #include #include #include -#include namespace D3D12 { diff --git a/common/D3D12/StreamBuffer.h b/common/D3D12/StreamBuffer.h index df371fbd03..4eb467bc43 100644 --- a/common/D3D12/StreamBuffer.h +++ b/common/D3D12/StreamBuffer.h @@ -17,11 +17,11 @@ #include "common/Pcsx2Defs.h" #include "common/RedtapeWindows.h" +#include "common/RedtapeWilCom.h" #include #include #include -#include namespace D3D12MA { diff --git a/common/GL/ContextWGL.cpp b/common/GL/ContextWGL.cpp index 5e6a73f8eb..a0d2ee3022 100644 --- a/common/GL/ContextWGL.cpp +++ b/common/GL/ContextWGL.cpp @@ -20,17 +20,17 @@ static void* GetProcAddressCallback(const char* name) { - void* addr = wglGetProcAddress(name); + void* addr = reinterpret_cast(wglGetProcAddress(name)); if (addr) return addr; // try opengl32.dll - return ::GetProcAddress(GetModuleHandleA("opengl32.dll"), name); + return reinterpret_cast(::GetProcAddress(GetModuleHandleA("opengl32.dll"), name)); } static bool ReloadWGL(HDC dc) { - if (!gladLoadWGLLoader([](const char* name) -> void* { return wglGetProcAddress(name); }, dc)) + if (!gladLoadWGLLoader([](const char* name) -> void* { return reinterpret_cast(wglGetProcAddress(name)); }, dc)) { Console.Error("Loading GLAD WGL functions failed"); return false; @@ -208,7 +208,7 @@ namespace GL if (!hDC) { Console.Error("GetDC() failed: 0x%08X", GetLastError()); - return false; + return {}; } if (!m_pixel_format.has_value()) @@ -218,7 +218,7 @@ namespace GL { Console.Error("ChoosePixelFormat() failed: 0x%08X", GetLastError()); ::ReleaseDC(hwnd, hDC); - return false; + return {}; } m_pixel_format = pf; @@ -397,7 +397,7 @@ namespace GL } // re-init glad-wgl - if (!gladLoadWGLLoader([](const char* name) -> void* { return wglGetProcAddress(name); }, m_dc)) + if (!gladLoadWGLLoader([](const char* name) -> void* { return reinterpret_cast(wglGetProcAddress(name)); }, m_dc)) { Console.Error("Loading GLAD WGL functions failed"); return false; diff --git a/common/Pcsx2Defs.h b/common/Pcsx2Defs.h index f8c71202ef..1d0eed3c98 100644 --- a/common/Pcsx2Defs.h +++ b/common/Pcsx2Defs.h @@ -159,7 +159,7 @@ static constexpr size_t __pagemask = PCSX2_PAGESIZE - 1; // Makes sure that if anyone includes xbyak, it doesn't do anything bad #define XBYAK_ENABLE_OMITTED_OPERAND -#ifdef __x86_64__ +#if defined(__x86_64__) && !defined(_M_AMD64) #define _M_AMD64 #endif diff --git a/common/RedtapeWilCom.h b/common/RedtapeWilCom.h new file mode 100644 index 0000000000..bf398e6f18 --- /dev/null +++ b/common/RedtapeWilCom.h @@ -0,0 +1,34 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2022 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#pragma once + +#ifdef _WIN32 + +#include "common/RedtapeWindows.h" + +// warning : variable 's_hrErrorLast' set but not used [-Wunused-but-set-variable] +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-but-set-variable" +#endif + +#include + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#endif \ No newline at end of file diff --git a/common/StackWalker.cpp b/common/StackWalker.cpp index ce3c5221f9..176ec8f4ab 100644 --- a/common/StackWalker.cpp +++ b/common/StackWalker.cpp @@ -566,6 +566,8 @@ private: case 8: //SymVirtual: szSymType = "Virtual"; break; + default: + break; } } LPCSTR pdbName = Module.LoadedImageName; @@ -1199,9 +1201,12 @@ void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUser OSVERSIONINFOEXA ver; ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA)); ver.dwOSVersionInfoSize = sizeof(ver); -#if _MSC_VER >= 1900 +#if defined(_MSC_VER) && !defined(__clang__) #pragma warning(push) #pragma warning(disable : 4996) +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif if (GetVersionExA((OSVERSIONINFOA*)&ver) != FALSE) { @@ -1211,8 +1216,10 @@ void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUser buffer[STACKWALK_MAX_NAMELEN - 1] = 0; OnOutput(buffer); } -#if _MSC_VER >= 1900 +#if defined(_MSC_VER) && !defined(__clang__) #pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop #endif } diff --git a/common/VirtualMemory.cpp b/common/VirtualMemory.cpp index 17b6994507..418a1be5cb 100644 --- a/common/VirtualMemory.cpp +++ b/common/VirtualMemory.cpp @@ -187,7 +187,7 @@ static bool VMMMarkPagesAsInUse(std::atomic* begin, std::atomic* end for (auto current = begin; current < end; current++) { bool expected = false; - if (!current->compare_exchange_strong(expected, true), std::memory_order_relaxed) + if (!current->compare_exchange_strong(expected, true, std::memory_order_relaxed)) { // This was already allocated! Undo the things we've set until this point while (--current >= begin) diff --git a/common/Vulkan/Loader.h b/common/Vulkan/Loader.h index c767dc0348..039829cca2 100644 --- a/common/Vulkan/Loader.h +++ b/common/Vulkan/Loader.h @@ -99,6 +99,7 @@ #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" +#pragma clang diagnostic ignored "-Wunused-variable" #endif #define VMA_STATIC_VULKAN_FUNCTIONS 1 diff --git a/common/Vulkan/SwapChain.cpp b/common/Vulkan/SwapChain.cpp index cc7748e69a..043c6de14c 100644 --- a/common/Vulkan/SwapChain.cpp +++ b/common/Vulkan/SwapChain.cpp @@ -44,6 +44,8 @@ namespace Vulkan DestroySurface(); } +#if 0 + // Unused for now, can be used for nogui static VkSurfaceKHR CreateDisplaySurface(VkInstance instance, VkPhysicalDevice physical_device, WindowInfo* wi) { Console.WriteLn("Trying to create a VK_KHR_display surface of %ux%u", wi->surface_width, wi->surface_height); @@ -253,6 +255,7 @@ namespace Vulkan return result; } +#endif VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, VkPhysicalDevice physical_device, WindowInfo* wi) { diff --git a/common/Windows/WinHostSys.cpp b/common/Windows/WinHostSys.cpp index 1c1771bbb8..6fc236ca98 100644 --- a/common/Windows/WinHostSys.cpp +++ b/common/Windows/WinHostSys.cpp @@ -286,8 +286,6 @@ bool SharedMemoryMappingArea::Unmap(void* map_base, size_t map_size) pxAssert(Common::IsAlignedPow2(map_offset, __pagesize)); pxAssert(Common::IsAlignedPow2(map_size, __pagesize)); - const size_t page = map_offset / __pagesize; - // unmap the specified range if (!UnmapViewOfFile2(GetCurrentProcess(), map_base, MEM_PRESERVE_PLACEHOLDER)) { diff --git a/common/emitter/cpudetect.cpp b/common/emitter/cpudetect.cpp index baee148596..430686860f 100644 --- a/common/emitter/cpudetect.cpp +++ b/common/emitter/cpudetect.cpp @@ -46,7 +46,7 @@ using namespace x86Emitter; alignas(16) x86capabilities x86caps; -#ifdef _MSC_VER +#if defined(_MSC_VER) // We disable optimizations for this function, because we need x86capabilities for AVX // detection, but if we keep opts on, it'll use AVX instructions for inlining memzero. #pragma optimize("", off) @@ -70,7 +70,7 @@ x86capabilities::x86capabilities() memzero(VendorName); memzero(FamilyName); } -#ifdef _MSC_VER +#if defined(_MSC_VER) #pragma optimize("", on) #endif