 +OPTION(PROFILING "Optimize library assembly" ON)
 +
 +OPTION(BUILD_SHARED_LIB "Build and install Shared library" ON)
++
++# internal compiler error from eigen Core/MatrixBase.h
++# in splice_child_die at dwarf2out.c:4706
++# unless we turn OFF LTO for this case (gcc 4.8)
++IF(BUILD_SHARED_LIB AND LTO AND CMAKE_BUILD_TYPE STREQUAL Debug)
++  SET(LTO OFF)
++ENDIF()
  
  SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake; ${CMAKE_MODULE_PATH})
  
-@@ -54,33 +59,33 @@ FIND_PACKAGE(eigen REQUIRED)
+@@ -54,33 +66,33 @@ FIND_PACKAGE(eigen REQUIRED)
  INCLUDE_DIRECTORIES(SYSTEM ${EIGEN3_INCLUDE_DIR})
  
  #This only works if *FIRST* you checkout a commit and *THEN* you run cmake

 ENDIF()
 
 
@@ -227,7 +284,7 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
 # LATEX documentation
 add_subdirectory(${CMAKE_SOURCE_DIR}/doc)
 

-	SET(CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS} -std=c++11 ${DETERMINISTIC} -fno-rtti -fno-exceptions -Wno-unknown-pragmas -Os -DNDEBUG -Wall -pedantic -Wno-padded -fstack-protector-all -fstrict-aliasing ")
-	SET(CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS} -std=c++11 ${DETERMINISTIC} -fno-rtti -fno-exceptions -Wno-unknown-pragmas -Ofast -fvisibility=hidden -fvisibility-inlines-hidden -O4 -DNDEBUG -Wall -pedantic -Wno-padded -fstack-protector-all -fstrict-aliasing -fwrapv -Wformat -Wformat-security -fPIE -fPIC ")
-	SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -std=c++11 ${DETERMINISTIC} -fno-rtti -fno-exceptions -Wno-unknown-pragmas -Ofast -g -fvisibility=hidden -fvisibility-inlines-hidden -O4 -DNDEBUG -Wall -pedantic -Wno-padded -fstack-protector-all -fstrict-aliasing -fwrapv -Wformat -Wformat-security -fPIE -fPIC ")
+	xpCheckCompilerFlags(CMAKE_CXX_FLAGS "-std=c++11 ${DETERMINISTIC} -fno-rtti -fno-exceptions -Wno-unknown-pragmas -Wall -pedantic -Wno-padded -fstack-protector-all -fstrict-aliasing -fwrapv")
+	xpCheckCompilerFlags(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Wno-aggressive-loop-optimizations -ftrapv -fisolate-erroneous-paths-dereference -fisolate-erroneous-paths-attribute")
+	IF(HAS_LIBUBSAN)
+		xpCheckCompilerFlags(CMAKE_CXX_FLAGS_DEBUG "-fsanitize=undefined -fsanitize=shift -fsanitize=integer-divide-by-zero -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow")
+	ENDIF()
+	xpCheckCompilerFlags(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
+	xpCheckCompilerFlags(CMAKE_CXX_FLAGS_RELEASE "-Ofast -fvisibility=hidden -fvisibility-inlines-hidden -O4 -DNDEBUG -Wformat -Wformat-security -fPIE -fPIC")
+	xpCheckCompilerFlags(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Ofast -g -fvisibility=hidden -fvisibility-inlines-hidden -O4 -DNDEBUG -Wformat -Wformat-security -fPIE -fPIC")
 	ENDIF()
 	# else I do not know your compiler options :)
 ENDIF()
@@ -169,20 +226,22 @@ ENDIF()
 # set the proper options for that, too
 #
 IF(${CMAKE_C_COMPILER} MATCHES ".*clang.*")
