[LLVMdev] Improved Covered Default Switch detection

Joe Abbey jabbey at arxan.com
Sun Nov 25 15:19:48 PST 2012

If cmake happens to detect GCC for the C compiler and Clang for the C++ compiler, then a manual override of either the C compiler or SUPPORTS_COVERED_SWITCH_DEFAULT_FLAG is required.  This has been happening on my Darwin build environments:

-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 4.1.0

Without the manual overrides, all C sources fail to compile with:

[  4%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o
cd /Users/jabbey/src/llvmCommit/build/lib/Support && /usr/bin/gcc  -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -I/Users/jabbey/src/llvmCommit/build/lib/Support -I/Users/jabbey/src/llvmCommit/lib/Support -I/Users/jabbey/src/llvmCommit/build/include -I/Users/jabbey/src/llvmCommit/include    -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -Wcovered-switch-default -fno-exceptions -o CMakeFiles/LLVMSupport.dir/regcomp.c.o   -c /Users/jabbey/src/llvmCommit/lib/Support/regcomp.c
cc1: error: unrecognized command line option "-Wcovered-switch-default"

The problem stems from HandleLLVMOptions.cmake where a single check of the warning option is performed using check_cxx_compiler_flag, and then upon success add_llvm_definitions appends to the flag to a list consumed by both C and CXX compilers.

Attached is a patch which updates HandleLLVMOptions.cmake to:
  - Test C and CXX compiler separately for -Wcovered-switch-default
  - Replace set( ${variable} "${variable} arg") with list( append $variable "arg" )
  - Check cmake_minimum_required of at least CMake 2.4 (where list append was introduced).

Ok to commit?

Joe Abbey
Director of Software Development
Arxan Technologies
jabbey at arxan.com<mailto:jabbey at arxan.com> www.arxan.com<http://www.arxan.com/>
Protecting the App Economy™

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121125/0871b80a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: improved-covered-default-switch-detection.patch
Type: application/octet-stream
Size: 3163 bytes
Desc: improved-covered-default-switch-detection.patch
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121125/0871b80a/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121125/0871b80a/attachment.htm>

More information about the llvm-dev mailing list