From 02202c637c5ec704e47e33abb236b843cdd084c6 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 13 May 2020 11:50:47 -0500 Subject: [PATCH] build: Fix enabling of build warnings, and handle most warnings discovered. --- src/CMakeLists.txt | 9 ++++++-- src/api_layers/CMakeLists.txt | 4 ---- src/common/gfxwrapper_opengl.c | 9 ++++++++ src/loader/CMakeLists.txt | 6 +----- src/scripts/validation_layer_generator.py | 7 +++++-- src/tests/hello_xr/CMakeLists.txt | 2 -- src/tests/list/CMakeLists.txt | 4 ---- src/tests/loader_test/CMakeLists.txt | 4 +--- .../loader_test/test_layers/CMakeLists.txt | 1 - .../loader_test/test_layers/layer_test.cpp | 15 ++++++------- .../loader_test/test_runtimes/CMakeLists.txt | 1 - .../test_runtimes/runtime_test.cpp | 21 ++++++++++++++----- 12 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3db7a42a6..b319762af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -320,12 +320,17 @@ set_target_properties(xr_global_generated_files PROPERTIES FOLDER ${CODEGEN_FOLD set(COMMON_GENERATED_OUTPUT ${GENERATED_OUTPUT}) if(NOT MSVC) include(CheckCXXCompilerFlag) - foreach(FLAG -Wall -Werror=unused-parameter -Werror=unused-argument) + include(CheckCCompilerFlag) + foreach(FLAG -Wall -Werror=unused-parameter -Werror=unused-argument -Wpointer-arith) string(REGEX REPLACE "[^A-Za-z0-9]" "" _flagvar "${FLAG}") check_cxx_compiler_flag(${FLAG} SUPPORTS_${_flagvar}) - if(SUPPORTS_WARNING_${_flagvar}) + if(SUPPORTS_${_flagvar}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") endif() + check_c_compiler_flag(${FLAG} SUPPORTS_C_${_flagvar}) + if(SUPPORTS_C_${_flagvar}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}") + endif() endforeach() set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined") endif() diff --git a/src/api_layers/CMakeLists.txt b/src/api_layers/CMakeLists.txt index 9429b05af..d47f664d6 100644 --- a/src/api_layers/CMakeLists.txt +++ b/src/api_layers/CMakeLists.txt @@ -186,20 +186,16 @@ if(WIN32) set_target_properties(copy-core_validation-def-file PROPERTIES FOLDER ${HELPER_FOLDER}) elseif(APPLE) # Apple api_dump-specific information - target_compile_options(XrApiLayer_api_dump PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(XrApiLayer_api_dump PROPERTIES LINK_FLAGS "-Wl") # Apple core_validation-specific information - target_compile_options(XrApiLayer_core_validation PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(XrApiLayer_core_validation PROPERTIES LINK_FLAGS "-Wl") else() # Linux api_dump-specific information - target_compile_options(XrApiLayer_api_dump PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(XrApiLayer_api_dump PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL") # Linux core_validation-specific information - target_compile_options(XrApiLayer_core_validation PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(XrApiLayer_core_validation PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL") endif() diff --git a/src/common/gfxwrapper_opengl.c b/src/common/gfxwrapper_opengl.c index a1b1da783..eacdfbc0f 100644 --- a/src/common/gfxwrapper_opengl.c +++ b/src/common/gfxwrapper_opengl.c @@ -3190,6 +3190,10 @@ ksGpuWindowEvent ksGpuWindow_ProcessEvents(ksGpuWindow *window) { #elif defined(OS_LINUX_WAYLAND) +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif static void _keyboard_keymap_cb(void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) { close(fd); } static void _keyboard_modifiers_cb(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {} @@ -3337,11 +3341,16 @@ static void _registry_cb(void *data, struct wl_registry *registry, uint32_t id, static void _registry_remove_cb(void *data, struct wl_registry *registry, uint32_t id) {} +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + const struct wl_registry_listener registry_listener = {_registry_cb, _registry_remove_cb}; bool ksGpuWindow_Create(ksGpuWindow *window, ksDriverInstance *instance, const ksGpuQueueInfo *queueInfo, const int queueIndex, const ksGpuSurfaceColorFormat colorFormat, const ksGpuSurfaceDepthFormat depthFormat, const ksGpuSampleCount sampleCount, const int width, const int height, const bool fullscreen) { + (void)queueIndex; memset(window, 0, sizeof(ksGpuWindow)); window->display = NULL; diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt index de78ad8eb..f12cd3406 100644 --- a/src/loader/CMakeLists.txt +++ b/src/loader/CMakeLists.txt @@ -213,11 +213,7 @@ endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") target_compile_options( openxr_loader - PRIVATE -Wall - -Wextra - -Wno-unused-parameter - -Wno-missing-field-initializers - -Wpointer-arith + PRIVATE -Wextra -fno-strict-aliasing -fno-builtin-memcmp "$<$:-fno-rtti>" diff --git a/src/scripts/validation_layer_generator.py b/src/scripts/validation_layer_generator.py index 0017eb624..9a6107d0e 100644 --- a/src/scripts/validation_layer_generator.py +++ b/src/scripts/validation_layer_generator.py @@ -589,6 +589,11 @@ def outputValidationHeaderInfo(self): validation_header_info += '\n// Current API version of the Core Validation API Layer\n#define XR_CORE_VALIDATION_API_VERSION ' validation_header_info += self.api_version_define validation_header_info += '\n' + validation_header_info += '#if defined(__GNUC__)\n' + validation_header_info += '#pragma GCC diagnostic push\n' + validation_header_info += '#pragma GCC diagnostic ignored "-Wunused-parameter"\n' + validation_header_info += '#pragma GCC diagnostic ignored "-Wunused-variable"\n' + validation_header_info += '#endif\n' validation_header_info += '\n// Externs for Core Validation\n' validation_header_info += self.outputInfoMapDeclarations(extern=True) @@ -1001,8 +1006,6 @@ def writeValidateStructNextCheck(self, struct_type, struct_name, member, indent) validate_struct_next += self.writeIndent(indent) validate_struct_next += '} else if (NEXT_CHAIN_RESULT_DUPLICATE_STRUCT == next_result) {\n' validate_struct_next += self.writeIndent(indent + 1) - validate_struct_next += 'char struct_type_buffer[XR_MAX_STRUCTURE_NAME_SIZE];\n' - validate_struct_next += self.writeIndent(indent + 1) validate_struct_next += 'std::string error_message = "Multiple structures of the same type(s) in \\"next\\" chain for ";\n' validate_struct_next += self.writeIndent(indent + 1) validate_struct_next += 'error_message += "%s : ";\n' % struct_type diff --git a/src/tests/hello_xr/CMakeLists.txt b/src/tests/hello_xr/CMakeLists.txt index 68f4c1538..000e54f89 100644 --- a/src/tests/hello_xr/CMakeLists.txt +++ b/src/tests/hello_xr/CMakeLists.txt @@ -81,8 +81,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") if(NOT D3D_DIRECTXCOLORS_INCLUDE_DIR) target_compile_definitions(hello_xr PRIVATE -DMISSING_DIRECTX_COLORS) endif() -elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_options(hello_xr PRIVATE -Wall) endif() if(Vulkan_LIBRARY) diff --git a/src/tests/list/CMakeLists.txt b/src/tests/list/CMakeLists.txt index 5c081ac9d..a793f950d 100644 --- a/src/tests/list/CMakeLists.txt +++ b/src/tests/list/CMakeLists.txt @@ -40,10 +40,6 @@ if(MSVC) target_compile_options(runtime_list PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX) endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_options(runtime_list PRIVATE -Wall) -endif() - set_target_properties(runtime_list PROPERTIES FOLDER ${TESTS_FOLDER}) set_target_properties(runtime_list PROPERTIES OUTPUT_NAME openxr_runtime_list) diff --git a/src/tests/loader_test/CMakeLists.txt b/src/tests/loader_test/CMakeLists.txt index 02714d981..1a9afd770 100644 --- a/src/tests/loader_test/CMakeLists.txt +++ b/src/tests/loader_test/CMakeLists.txt @@ -53,9 +53,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") endif() elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_options( - loader_test PRIVATE -Wall -Wno-unused-function -Wno-format-truncation - ) + # No special options needed. else() message(FATAL_ERROR "Unsupported Platform") endif() diff --git a/src/tests/loader_test/test_layers/CMakeLists.txt b/src/tests/loader_test/test_layers/CMakeLists.txt index 0c86062a6..a5031f599 100644 --- a/src/tests/loader_test/test_layers/CMakeLists.txt +++ b/src/tests/loader_test/test_layers/CMakeLists.txt @@ -69,7 +69,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") ) set_target_properties(copy-test-def-file PROPERTIES FOLDER ${HELPER_FOLDER}) elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_options(XrApiLayer_test PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(XrApiLayer_test PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL") gen_xr_layer_json( ${PROJECT_BINARY_DIR}/src/tests/loader_test/resources/layers/XrApiLayer_test.json diff --git a/src/tests/loader_test/test_layers/layer_test.cpp b/src/tests/loader_test/test_layers/layer_test.cpp index 9acafac3d..14e652c3c 100644 --- a/src/tests/loader_test/test_layers/layer_test.cpp +++ b/src/tests/loader_test/test_layers/layer_test.cpp @@ -39,7 +39,7 @@ extern "C" { std::map g_next_gipa_map; -XRAPI_ATTR XrResult XRAPI_CALL LayerTestXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) { +XRAPI_ATTR XrResult XRAPI_CALL LayerTestXrCreateInstance(const XrInstanceCreateInfo * /* info */, XrInstance * /* instance */) { // In a layer, LayerTestXrCreateApiLayerInstance is called instead of this function. This should not be called. return XR_ERROR_FUNCTION_UNSUPPORTED; } @@ -118,6 +118,7 @@ LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoader return XR_ERROR_INITIALIZATION_FAILED; } + (void)layerName; layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION; layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0); layerRequest->getInstanceProcAddr = LayerTestXrGetInstanceProcAddr; @@ -127,9 +128,9 @@ LAYER_EXPORT XrResult xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoader } // Always fail -LAYER_EXPORT XrResult TestlayerAlwaysFailNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo *loaderInfo, - const char *layerName, - XrNegotiateApiLayerRequest *layerRequest) { +LAYER_EXPORT XrResult TestlayerAlwaysFailNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo * /* loaderInfo */, + const char * /* layerName */, + XrNegotiateApiLayerRequest * /* layerRequest */) { return XR_ERROR_INITIALIZATION_FAILED; } @@ -148,7 +149,7 @@ LAYER_EXPORT XrResult TestLayerNullGipaNegotiateLoaderApiLayerInterface(const Xr loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) { return XR_ERROR_INITIALIZATION_FAILED; } - + (void)layerName; layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION; layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0); layerRequest->getInstanceProcAddr = nullptr; @@ -171,7 +172,7 @@ LAYER_EXPORT XrResult TestLayerInvalidInterfaceNegotiateLoaderApiLayerInterface( loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) { return XR_ERROR_INITIALIZATION_FAILED; } - + (void)layerName; layerRequest->layerInterfaceVersion = 0; layerRequest->layerApiVersion = XR_MAKE_VERSION(0, 1, 0); layerRequest->getInstanceProcAddr = reinterpret_cast(LayerTestXrGetInstanceProcAddr); @@ -194,7 +195,7 @@ LAYER_EXPORT XrResult TestLayerInvalidApiNegotiateLoaderApiLayerInterface(const loaderInfo->minApiVersion < XR_MAKE_VERSION(0, 1, 0) || loaderInfo->minApiVersion >= XR_MAKE_VERSION(1, 1, 0)) { return XR_ERROR_INITIALIZATION_FAILED; } - + (void)layerName; layerRequest->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION; layerRequest->layerApiVersion = 0; layerRequest->getInstanceProcAddr = reinterpret_cast(LayerTestXrGetInstanceProcAddr); diff --git a/src/tests/loader_test/test_runtimes/CMakeLists.txt b/src/tests/loader_test/test_runtimes/CMakeLists.txt index 3b0b5edca..aea06dd0a 100644 --- a/src/tests/loader_test/test_runtimes/CMakeLists.txt +++ b/src/tests/loader_test/test_runtimes/CMakeLists.txt @@ -77,7 +77,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") ) set_target_properties(copy-test_runtime-def-file PROPERTIES FOLDER ${HELPER_FOLDER}) elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_options(test_runtime PRIVATE -Wpointer-arith -Wno-unused-function -Wno-sign-compare) set_target_properties(test_runtime PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic,--exclude-libs,ALL") gen_xr_runtime_json( ${PROJECT_BINARY_DIR}/src/tests/loader_test/resources/runtimes/test_runtime.json diff --git a/src/tests/loader_test/test_runtimes/runtime_test.cpp b/src/tests/loader_test/test_runtimes/runtime_test.cpp index 800862445..2ffcf7a2c 100644 --- a/src/tests/loader_test/test_runtimes/runtime_test.cpp +++ b/src/tests/loader_test/test_runtimes/runtime_test.cpp @@ -37,12 +37,12 @@ extern "C" { -XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrCreateInstance(const XrInstanceCreateInfo *info, XrInstance *instance) { +XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrCreateInstance(const XrInstanceCreateInfo * /* info */, XrInstance *instance) { *instance = (XrInstance)1; return XR_SUCCESS; } -XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrDestroyInstance(XrInstance instance) { return XR_SUCCESS; } +XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrDestroyInstance(XrInstance /* instance */) { return XR_SUCCESS; } XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrEnumerateInstanceExtensionProperties(const char *layerName, uint32_t propertyCapacityInput, @@ -62,13 +62,20 @@ XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrEnumerateInstanceExtensionProperties return XR_SUCCESS; } -XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetSystem(XrInstance instance, const XrSystemGetInfo *getInfo, XrSystemId *systemId) { +XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetSystem(XrInstance instance, const XrSystemGetInfo * /* getInfo */, + XrSystemId *systemId) { + if (instance == XR_NULL_HANDLE) { + return XR_ERROR_HANDLE_INVALID; + } *systemId = 1; return XR_SUCCESS; } XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetSystemProperties(XrInstance instance, XrSystemId systemId, XrSystemProperties *properties) { + if (instance == XR_NULL_HANDLE) { + return XR_ERROR_HANDLE_INVALID; + } if (systemId != 1) { return XR_ERROR_SYSTEM_INVALID; } @@ -89,7 +96,11 @@ XRAPI_ATTR XrResult XRAPI_CALL RuntimeTestXrGetInstanceProcAddr(XrInstance insta *function = reinterpret_cast(RuntimeTestXrEnumerateInstanceExtensionProperties); } else if (0 == strcmp(name, "xrCreateInstance")) { *function = reinterpret_cast(RuntimeTestXrCreateInstance); - } else if (0 == strcmp(name, "xrDestroyInstance")) { + }; + if (instance == XR_NULL_HANDLE) { + return XR_ERROR_HANDLE_INVALID; + } + if (0 == strcmp(name, "xrDestroyInstance")) { *function = reinterpret_cast(RuntimeTestXrDestroyInstance); } else if (0 == strcmp(name, "xrGetSystem")) { *function = reinterpret_cast(RuntimeTestXrGetSystem); @@ -126,7 +137,7 @@ RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL xrNegotiateLoaderRuntimeInterface( // Always fail RUNTIME_EXPORT XRAPI_ATTR XrResult XRAPI_CALL TestRuntimeAlwaysFailNegotiateLoaderRuntimeInterface( - const XrNegotiateLoaderInfo *loaderInfo, XrNegotiateRuntimeRequest *runtimeRequest) { + const XrNegotiateLoaderInfo * /* loaderInfo */, XrNegotiateRuntimeRequest * /* runtimeRequest */) { return XR_ERROR_INITIALIZATION_FAILED; }