From b496ea27957133f0294aae89b0906660c055382b Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 25 Jul 2017 10:45:07 +0100 Subject: [CMake] Fix bug where we would inherit LLVM's `-DNDEBUG` define when LLVM was built without assertions. This prevented `ENABLE_KLEE_ASSERTS` from working correctly. Reported by @MartinNowack . --- cmake/find_llvm.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/find_llvm.cmake b/cmake/find_llvm.cmake index 770fca84..49ca51d4 100644 --- a/cmake/find_llvm.cmake +++ b/cmake/find_llvm.cmake @@ -227,3 +227,16 @@ else() set(${OUTPUT_VAR} ${targets_to_return} PARENT_SCOPE) endfunction() endif() + +# Filter out `-DNEBUG` from LLVM_DEFINITIONS. The caller can use +# `LLVM_ENABLE_ASSERTIONS` to decide how to set their defines. +set(_new_llvm_definitions "") +foreach (llvm_define ${LLVM_DEFINITIONS}) + if ("${llvm_define}" STREQUAL "-DNDEBUG") + # Skip + else() + list(APPEND _new_llvm_definitions "${llvm_define}") + endif() +endforeach() +set(LLVM_DEFINITIONS "${_new_llvm_definitions}") +unset(_new_llvm_definitions) -- cgit 1.4.1 From df899b02e279ed65dc94f55d4b671560f667497b Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 25 Jul 2017 10:57:40 +0100 Subject: [CMake] Emit warning when mixing assert and non assert builds. This could lead to lots of problems. If we discover that these configurations don't work at all we should make this an error. --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b9d7e61a..e066b89e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,6 +224,21 @@ else() unset(ENABLE_KLEE_DEBUG) # for config.h endif() +# Warn about mixing build types. +# This is likely a bad idea because some of LLVM's header files use the NDEBUG +# macro which can change things like data layout. +if (LLVM_ENABLE_ASSERTIONS AND (NOT ENABLE_KLEE_ASSERTS)) + message(WARNING + "LLVM was built with assertions but KLEE will be built without them.\n" + "This might lead to unexpected behaviour." + ) +elseif ((NOT LLVM_ENABLE_ASSERTIONS) AND ENABLE_KLEE_ASSERTS) + message(WARNING + "LLVM was built without assertions but KLEE will be built with them.\n" + "This might lead to unexpected behaviour." + ) +endif() + if (LLVM_ENABLE_VISIBILITY_INLINES_HIDDEN) list(APPEND KLEE_COMPONENT_CXX_FLAGS "-fvisibility-inlines-hidden") endif() -- cgit 1.4.1