From 59e59b9e0ef45a8d96bb4ef972e3a0d745f8b4c4 Mon Sep 17 00:00:00 2001 From: Guoyu Wang <62914304+gwang-msft@users.noreply.github.com> Date: Thu, 12 Aug 2021 23:47:03 -0700 Subject: [PATCH] Fix unknown warning "-Wformat-truncation" build failure for arm (#8721) * fix clang arm build failure * address CR comments * Change to cmake check flag option * Add missing __aarch64__ --- cmake/CMakeLists.txt | 7 ++++--- cmake/onnxruntime_config.h.in | 1 + onnxruntime/test/providers/kernel_def_hash_test.cc | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d812082cdb..b705a853db 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -236,7 +236,7 @@ set(onnxruntime_REQUIRE_PYTHON_EMBED_LIB OFF) if (onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) add_compile_definitions(ENABLE_TRAINING_TORCH_INTEROP) - # Python::Python is required for building unit test executables. + # Python::Python is required for building unit test executables. if (onnxruntime_BUILD_UNIT_TESTS) set(onnxruntime_REQUIRE_PYTHON_EMBED_LIB ON) endif() @@ -722,7 +722,7 @@ else() set(protobuf_DISABLE_RTTI OFF CACHE BOOL "Remove runtime type information in the binaries" FORCE) endif() add_subdirectory(${PROJECT_SOURCE_DIR}/external/protobuf/cmake EXCLUDE_FROM_ALL) - + if(TARGET libprotoc) set_target_properties(libprotoc PROPERTIES FOLDER "External/Protobuf") add_executable(protobuf::protoc ALIAS protoc) @@ -933,6 +933,7 @@ else() check_cxx_compiler_flag(-Wambiguous-reversed-operator HAS_AMBIGUOUS_REVERSED_OPERATOR) check_cxx_compiler_flag(-Wdeprecated-anon-enum-enum-conversion HAS_DEPRECATED_ANON_ENUM_ENUM_CONVERSION) check_cxx_compiler_flag(-Wundefined-var-template HAS_UNDEFINED_VAR_TEMPLATE) + check_cxx_compiler_flag(-Wformat-truncation HAS_FORMAT_TRUNCATION) if(HAS_TAUTOLOGICAL_POINTER_COMPARE) #we may have extra null pointer checkings in debug build, it's not an issue @@ -955,7 +956,7 @@ else() endif() #names in this var must match the directory names under onnxruntime/core/providers -#ONNXRUNTIME_PROVIDER_NAMES is the list of providers that needs to export additional symbols in the global namespace. +#ONNXRUNTIME_PROVIDER_NAMES is the list of providers that needs to export additional symbols in the global namespace. #For example CUDA EP exports "OrtSessionOptionsAppendExecutionProvider_CUDA", which is a global function. #However, all these things are legacy and deprecated and should be replaced with functions in onnxruntime_c_api.h. set(ONNXRUNTIME_PROVIDER_NAMES cpu) diff --git a/cmake/onnxruntime_config.h.in b/cmake/onnxruntime_config.h.in index fad0a6d406..6ae4f045ea 100644 --- a/cmake/onnxruntime_config.h.in +++ b/cmake/onnxruntime_config.h.in @@ -17,4 +17,5 @@ #cmakedefine HAS_CLASS_MEMACCESS #cmakedefine HAS_MAYBE_UNINITIALIZED #cmakedefine HAS_DEPRECATED_DECLARATIONS +#cmakedefine HAS_FORMAT_TRUNCATION #cmakedefine ORT_VERSION "@ORT_VERSION@" diff --git a/onnxruntime/test/providers/kernel_def_hash_test.cc b/onnxruntime/test/providers/kernel_def_hash_test.cc index d42d0d63d2..562ddfbfed 100644 --- a/onnxruntime/test/providers/kernel_def_hash_test.cc +++ b/onnxruntime/test/providers/kernel_def_hash_test.cc @@ -57,18 +57,19 @@ #include #include "gtest/gtest.h" +#include "onnxruntime_config.h" #ifdef _WIN32 #pragma warning(push) #pragma warning(disable : 28020) -#elif __aarch64__ +#elif __aarch64__ && defined(HAS_FORMAT_TRUNCATION) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" #endif #include "nlohmann/json.hpp" #ifdef _WIN32 #pragma warning(pop) -#elif __aarch64__ +#elif __aarch64__ && defined(HAS_FORMAT_TRUNCATION) #pragma GCC diagnostic pop #endif