[flang-commits] [flang] 3862cbb - [flang] Use LLVM's flags

David Truby via flang-commits flang-commits at lists.llvm.org
Mon Jun 8 07:30:01 PDT 2020


Author: Isuru Fernando
Date: 2020-06-08T15:29:52+01:00
New Revision: 3862cbbc652be3dd731e75500f971e21d8355462

URL: https://github.com/llvm/llvm-project/commit/3862cbbc652be3dd731e75500f971e21d8355462
DIFF: https://github.com/llvm/llvm-project/commit/3862cbbc652be3dd731e75500f971e21d8355462.diff

LOG: [flang] Use LLVM's flags

Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build

This commit fixes some windows issues with the flags

Reviewers: DavidTruby, jdoerfert, sscalpone

Reviewed By: DavidTruby, sscalpone

Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D78306

Added: 
    

Modified: 
    flang/CMakeLists.txt
    flang/lib/Optimizer/CMakeLists.txt
    flang/unittests/Evaluate/CMakeLists.txt
    flang/unittests/Runtime/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index dc8de5070778..fe1809b879c5 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -37,11 +37,19 @@ endif()
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 include(AddFlang)
 
+if (MSVC)
+  set(_FLANG_ENABLE_WERROR_DEFAULT OFF)
+else ()
+  set(_FLANG_ENABLE_WERROR_DEFAULT ON)
+endif()
+option(FLANG_ENABLE_WERROR "Fail and stop building flang if a warning is triggered."
+       "${_FLANG_ENABLE_WERROR_DEFAULT}")
+
 # Check for a standalone build and configure as appropriate from
 # there.
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-message("Building Flang as a standalone project.")
-project(Flang)
+  message("Building Flang as a standalone project.")
+  project(Flang)
 
   set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   if (NOT MSVC_IDE)
@@ -59,6 +67,8 @@ project(Flang)
   if(LLVM_ENABLE_ZLIB)
     find_package(ZLIB REQUIRED)
   endif()
+  option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
+  option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 
   include(CMakeParseArguments)
   include(AddLLVM)
@@ -76,7 +86,6 @@ project(Flang)
       NO_DEFAULT_PATH)
   endif()
 
-  option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
   option(LLVM_INSTALL_TOOLCHAIN_ONLY
     "Only include toolchain files in the 'install' target." OFF)
   option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
@@ -239,8 +248,20 @@ configure_file(
   ${FLANG_SOURCE_DIR}/include/flang/Config/config.h.cmake
   ${FLANG_BINARY_DIR}/include/flang/Config/config.h)
 
-# Add global F18 flags.
-set(CMAKE_CXX_FLAGS "-fno-rtti -fno-exceptions -pedantic -Wall -Wextra -Werror -Wcast-qual -Wimplicit-fallthrough -Wdelete-non-virtual-dtor ${CMAKE_CXX_FLAGS}")
+if (FLANG_ENABLE_WERROR)
+  # The following is taken from llvm/cmake/modules/HandleLLVMOptions.cmake
+  # Keep this up-to-date with that file
+  if( MSVC )
+    append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+  endif()
+  if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
+    append("-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+    append("-Wno-error" CMAKE_REQUIRED_FLAGS)
+  endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
+  if (NOT LLVM_ENABLE_WERROR)
+      message(WARNING "FLANG_ENABLE_WERROR setting is 
diff erent from LLVM_ENABLE_WERROR.")
+  endif()
+endif()
 
 # Builtin check_cxx_compiler_flag doesn't seem to work correctly
 macro(check_compiler_flag flag resultVar)
@@ -250,11 +271,11 @@ endmacro()
 
 check_compiler_flag("-Werror -Wno-deprecated-copy" CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG)
 if (CXX_SUPPORTS_NO_DEPRECATED_COPY_FLAG)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy")
 endif()
 check_compiler_flag("-Wstring-conversion" CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG)
 if (CXX_SUPPORTS_NO_STRING_CONVERSION_FLAG)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-conversion")
 endif()
 
 # Add appropriate flags for GCC

diff  --git a/flang/lib/Optimizer/CMakeLists.txt b/flang/lib/Optimizer/CMakeLists.txt
index 2f8cd269dd9f..5825015fe60d 100644
--- a/flang/lib/Optimizer/CMakeLists.txt
+++ b/flang/lib/Optimizer/CMakeLists.txt
@@ -1,5 +1,2 @@
-# Sources generated by tablegen have unused parameters.
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
-
 add_subdirectory(Dialect)
 add_subdirectory(Support)

diff  --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 21aa2edfccb7..a4315b1072ce 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -90,10 +90,12 @@ target_link_libraries(logical-test
 # IEEE exception flags (
diff erent use of the word "exception")
 # in the actual hardware floating-point status register, so ensure that
 # C++ exceptions are enabled for this test.
-set_source_files_properties(real.cpp PROPERTIES COMPILE_FLAGS -fexceptions)
+set(LLVM_REQUIRES_EH ON)
+set(LLVM_REQUIRES_RTTI ON)
 add_executable(real-test
   real.cpp
 )
+llvm_update_compile_flags(real-test)
 
 target_link_libraries(real-test
   FortranEvaluateTesting

diff  --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index 4d6ac6411fe2..e1464e54e8c5 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -1,11 +1,12 @@
-if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
-endif()
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 
+# RuntimeTesting needs exceptions enabled
+set(LLVM_REQUIRES_EH ON)
+set(LLVM_REQUIRES_RTTI ON)
 add_library(RuntimeTesting
   testing.cpp
 )
+llvm_update_compile_flags(RuntimeTesting)
 
 add_executable(format-test
   format.cpp


        


More information about the flang-commits mailing list