From 9f3556dc2c81d1dbcc6f871bc1deb92326c44448 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 13 Feb 2024 15:42:20 +0000 Subject: [PATCH] [cmake] Clean up flags and treat warnings as errors in the ci. --- .github/workflows/ci.yml | 3 ++- CMakeLists.txt | 18 +++++++----------- cmake/modules/CladGoogleTest.cmake | 14 +++++++++++++- lib/Differentiator/CladUtils.cpp | 7 +------ lib/Differentiator/VisitorBase.cpp | 2 ++ 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ac9f2cde..6b1665785 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: clang-runtime: '11' coverage: true cuda: true - extra_cmake_options: '-DLLVM_ENABLE_WERROR=On -DCLAD_ENABLE_ENZYME_BACKEND=On' + extra_cmake_options: '-DCLAD_ENABLE_ENZYME_BACKEND=On' #clang-format: true - name: ubu20-gcc7-runtime11-benchmarks @@ -739,6 +739,7 @@ jobs: -DCMAKE_BUILD_TYPE=$([[ -z "$BUILD_TYPE" ]] && echo RelWithDebInfo || echo $BUILD_TYPE) \ -DCLAD_CODE_COVERAGE=${CLAD_CODE_COVERAGE} \ -DLLVM_EXTERNAL_LIT="`which lit`" \ + -DLLVM_ENABLE_WERROR=On \ $GITHUB_WORKSPACE \ ${{ matrix.extra_cmake_options }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 5366dbf54..abe8adf64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,8 +163,8 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) # In rare cases we might want to have clang installed in a different place # than llvm and the header files should be found first (even though the # LLVM_INCLUDE_DIRS) contain clang headers, too. - include_directories(${CLANG_INCLUDE_DIRS}) - include_directories(${LLVM_INCLUDE_DIRS}) + include_directories(SYSTEM ${CLANG_INCLUDE_DIRS}) + include_directories(SYSTEM ${LLVM_INCLUDE_DIRS}) add_definitions(${LLVM_DEFINITIONS}) # If the llvm sources are present add them with higher priority. @@ -176,13 +176,13 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) # # FIXME: We only support in-tree builds of clang, that is clang being built # in llvm_src/tools/clang. - include_directories(${LLVM_BUILD_MAIN_SRC_DIR}/tools/clang/include/) + include_directories(SYSTEM ${LLVM_BUILD_MAIN_SRC_DIR}/tools/clang/include/) if (NOT LLVM_BUILD_BINARY_DIR) message(FATAL "LLVM_BUILD_* values should be available for the build tree") endif() - include_directories(${LLVM_BUILD_BINARY_DIR}/tools/clang/include/) + include_directories(SYSTEM ${LLVM_BUILD_BINARY_DIR}/tools/clang/include/) endif() set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/) @@ -224,24 +224,19 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE ) "`CMakeFiles'. Please delete them.") endif() -# Add appropriate flags for GCC -if (LLVM_COMPILER_IS_GCC_COMPATIBLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings") -endif () - if (APPLE) set(CMAKE_MODULE_LINKER_FLAGS "-Wl,-undefined -Wl,dynamic_lookup") endif () # FIXME: Use merge this with the content from the LLVMConfig and ClangConfig. if (NOT CLAD_BUILT_STANDALONE) -include_directories(BEFORE +include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/../clang/include ${CMAKE_CURRENT_SOURCE_DIR}/../clang/include ) endif() -include_directories(BEFORE +include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/include ) @@ -312,6 +307,7 @@ if (NOT CLAD_BUILD_STATIC_ONLY) set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang) # Filter some unsupported flags by clang. string(REPLACE "-fno-lifetime-dse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "-Wno-class-memaccess" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") add_subdirectory(unittests) add_subdirectory(test) diff --git a/cmake/modules/CladGoogleTest.cmake b/cmake/modules/CladGoogleTest.cmake index 9d3980a8c..36e1f9de1 100644 --- a/cmake/modules/CladGoogleTest.cmake +++ b/cmake/modules/CladGoogleTest.cmake @@ -21,10 +21,22 @@ endif() # Remove the coverage flags when compiling external libraries. string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS}") +string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS}") string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS_NOCOV "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}") string(REPLACE "${GCC_COVERAGE_LINK_FLAGS}" "" CMAKE_EXE_LINKER_FLAGS_NOCOV "${CMAKE_EXE_LINKER_FLAGS}") string(REPLACE "${GCC_COVERAGE_LINK_FLAGS}" "" CMAKE_SHARED_LINKER_FLAGS_NOCOV "${CMAKE_SHARED_LINKER_FLAGS}") +# Turn off -Werror for external packages. +if (LLVM_ENABLE_WERROR) + if (MSVC) + set(CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS_NOCOV} /w ") + set(CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS_NOCOV} /w ") + elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE) + set(CMAKE_CXX_FLAGS_NOCOV "${CMAKE_CXX_FLAGS_NOCOV} -Wno-error ") + set(CMAKE_C_FLAGS_NOCOV "${CMAKE_C_FLAGS_NOCOV} -Wno-error ") + endif() +endif(LLVM_ENABLE_WERROR) + include(ExternalProject) ExternalProject_Add( googletest @@ -41,7 +53,7 @@ ExternalProject_Add( CMAKE_ARGS -G ${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} - -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} + -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS_NOCOV} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS_NOCOV} -DCMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS=${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS_NOCOV} diff --git a/lib/Differentiator/CladUtils.cpp b/lib/Differentiator/CladUtils.cpp index 6be4b8349..526ba31e4 100644 --- a/lib/Differentiator/CladUtils.cpp +++ b/lib/Differentiator/CladUtils.cpp @@ -557,13 +557,8 @@ namespace clad { } void VisitBinaryOperator(clang::BinaryOperator* BO) { - if (BO->isAssignmentOp() || BO->isCompoundAssignmentOp()) { + if (BO->isAssignmentOp() || BO->isCompoundAssignmentOp()) Visit(BO->getLHS()); - } else if (BO->getOpcode() == clang::BO_Comma) { - /**/ - } else { - assert("Unexpected binary operator!!"); - } } void VisitConditionalOperator(clang::ConditionalOperator* CO) { diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index b7c553a1c..eef3e2353 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -72,7 +72,9 @@ namespace clad { #pragma warning(push, 0) #endif // MSVC #pragma GCC diagnostic push +#ifdef __clang__ #pragma clang diagnostic ignored "-Wunknown-warning-option" +#endif // __clang__ #pragma GCC diagnostic ignored "-Wnon-template-friend" friend type get(Tag); #pragma GCC diagnostic pop