From e305e4d4d830cff19822468da3058be52559aa1c Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Fri, 10 Dec 2021 16:43:41 -0800 Subject: [PATCH] Suppress common warnings when building by clang (#69710) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69710 Namely no range-loop-analysis (that detect when loop variable can not be const reference Test Plan: Imported from OSS Reviewed By: r-barnes Differential Revision: D32997003 Pulled By: malfet fbshipit-source-id: dba0e7875e5b667e2cc394c70dd75e2403265918 --- CMakeLists.txt | 4 ++++ cmake/public/utils.cmake | 5 ++++- torch/CMakeLists.txt | 9 +++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bc2a18803d..90d6a3e27d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -768,6 +768,10 @@ if(NOT MSVC) string(APPEND CMAKE_CXX_FLAGS " -Wno-strict-overflow") string(APPEND CMAKE_CXX_FLAGS " -Wno-strict-aliasing") string(APPEND CMAKE_CXX_FLAGS " -Wno-error=deprecated-declarations") + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + string(APPEND CMAKE_CXX_FLAGS " -Wno-range-loop-analysis") + string(APPEND CMAKE_CXX_FLAGS " -Wno-pass-failed") + endif() if(CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)) string(APPEND CMAKE_CXX_FLAGS " -Wno-stringop-overflow") string(APPEND CMAKE_CXX_FLAGS " -Wno-noexcept-type") diff --git a/cmake/public/utils.cmake b/cmake/public/utils.cmake index 15f5afd3192..1c02ab3967d 100644 --- a/cmake/public/utils.cmake +++ b/cmake/public/utils.cmake @@ -447,7 +447,10 @@ function(torch_compile_options libname) # warnings, see https://bugs.llvm.org/show_bug.cgi?id=21629 -Wno-missing-braces ) - + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + list(APPEND private_compile_options + -Wno-range-loop-analysis) + endif() if(NOT APPLE) list(APPEND private_compile_options # Considered to be flaky. See the discussion at diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index af747644ef8..c14e8b41476 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -105,10 +105,11 @@ else() -fno-strict-aliasing -Wno-write-strings -Wno-strict-aliasing) - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - list(APPEND TORCH_PYTHON_COMPILE_OPTIONS - -Wno-writable-strings) - endif() +endif() + +if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + list(APPEND TORCH_PYTHON_COMPILE_OPTIONS + -Wno-writable-strings) endif() if(USE_CUDA)