[PATCH] Turn off uninitialized-use warnings for gcc in cmake build

Edwin Vane edwin.vane at intel.com
Wed Jan 30 12:18:52 PST 2013


Hi gribozavr,

Copied logic from autoconf/configure.ac and added support to the cmake
build to turn off uninitialized use warnings for gcc. This cleans the
build up somewhat.

http://llvm-reviews.chandlerc.com/D353

Files:
  cmake/config-ix.cmake
  cmake/modules/HandleLLVMOptions.cmake

Index: cmake/config-ix.cmake
===================================================================
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -304,6 +304,35 @@
 
 check_cxx_compiler_flag("-Wno-variadic-macros" SUPPORTS_NO_VARIADIC_MACROS_FLAG)
 
+set(USE_NO_MAYBE_UNINITIALIZED 0)
+set(USE_NO_UNINITIALIZED 0)
+
+# Disable gcc's (potentially) uninitialized use analysis as it presents lots of
+# false positives
+if (CMAKE_COMPILER_IS_GNUCXX)
+  check_cxx_compiler_flag("-Wno-maybe-uninitialized" HAS_NO_MAYBE_UNINITIALIZED)
+  if (NOT HAS_NO_MAYBE_UNINITIALIZED)
+    # If the compiler doesn't support -Wno-maybe-uninitialized, just use
+    # -Wno-uninitialized if available.
+    check_cxx_compiler_flag("-Wno-uninitialized" HAS_NO_UNINITIALIZED)
+    set(USE_NO_UNINITIALIZED ${HAS_NO_UNINITIALIZED})
+  else()
+    # In older versions of gcc, the compiler flag check above will still pass
+    # for unsupported -W flags. In such cases, just use -Wno-uninitialized if
+    # available.
+    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GXX_VERSION)
+
+    if (GXX_VERSION VERSION_LESS "4.7")
+      check_cxx_compiler_flag("-Wno-uninitialized" HAS_NO_UNINITIALIZED)
+      set(USE_NO_UNINITIALIZED ${HAS_NO_UNINITIALIZED})
+    else()
+      # For gcc 4.7, uninitialized use is left on but potential uninitialized use
+      # is turned off.
+      set(USE_NO_MAYBE_UNINITIALIZED 1)
+    endif()
+  endif()
+endif()
+
 include(GetHostTriple)
 get_host_triple(LLVM_HOST_TRIPLE)
 
Index: cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- cmake/modules/HandleLLVMOptions.cmake
+++ cmake/modules/HandleLLVMOptions.cmake
@@ -189,6 +189,12 @@
     if( C_SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG )
       set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcovered-switch-default" )
     endif()
+    if (USE_NO_UNINITIALIZED)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
+    endif()
+    if (USE_NO_MAYBE_UNINITIALIZED)
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
+    endif()
   endif (LLVM_ENABLE_WARNINGS)
   if (LLVM_ENABLE_WERROR)
     add_llvm_definitions( -Werror )
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D353.1.patch
Type: text/x-patch
Size: 2209 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130130/cb27c9ea/attachment.bin>


More information about the llvm-commits mailing list