From b4599a48694b78a5db144f17c2ab281a6d9f17d1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 29 May 2015 10:15:29 -0700 Subject: Added Ubsan build target, to check for undefined behavior. --- CMakeLists.txt | 2 +- Makefile | 8 +++++++- src/CMakeLists.txt | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a6f304..a4ebe92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,5 +21,5 @@ add_subdirectory(test testdir) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING - "Choose the type of build, options are: Debug Profile Release." FORCE) + "Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE) endif(NOT CMAKE_BUILD_TYPE) diff --git a/Makefile b/Makefile index 3606368..5ad87d0 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ VERSION?=$(SPECVERSION) RELEASE?=CommonMark-$(VERSION) INSTALL_PREFIX?=/usr/local -.PHONY: all cmake_build spec leakcheck clean fuzztest dingus upload test update-site upload-site debug asan mingw archive bench astyle update-spec afl +.PHONY: all cmake_build spec leakcheck clean fuzztest dingus upload test update-site upload-site debug ubsan asan mingw archive bench astyle update-spec afl all: cmake_build man/man3/cmark.3 @@ -47,6 +47,12 @@ debug: cmake .. -DCMAKE_BUILD_TYPE=Debug; \ make +ubsan: + mkdir -p $(BUILDDIR); \ + cd $(BUILDDIR); \ + cmake .. -DCMAKE_BUILD_TYPE=Ubsan; \ + make + asan: mkdir -p $(BUILDDIR); \ cd $(BUILDDIR); \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba3e18e..f27186e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -164,3 +164,7 @@ endif() if($ENV{TIMER}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTIMER=1") endif($ENV{TIMER}) + +if(CMAKE_BUILD_TYPE STREQUAL "Ubsan") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined") +endif() \ No newline at end of file -- cgit v1.2.3