From 8b5e2b01fe35a665045a592cc533da557214b296 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?=
 <rmrodriguez@carto.com>
Date: Mon, 19 Nov 2018 16:21:03 +0000
Subject: [PATCH] Travis: Run CI under GCC's undefined behavior sanitizer

References #4244
Closes https://github.com/postgis/postgis/pull/335



git-svn-id: http://svn.osgeo.org/postgis/trunk@17034 b70326c6-7e19-0410-871a-916f4a2858ee
---
 .travis.yml               |  1 +
 ci/travis/run_usan_gcc.sh | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 ci/travis/run_usan_gcc.sh

diff --git a/.travis.yml b/.travis.yml
index 418ec5db1..97761f5e8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ env:
   - tag=latest mode=tests
   - tag=pg11-geos37-gdal23-proj52 mode=debug
   - tag=pg11-geos37-gdal23-proj52 mode=coverage
+  - tag=pg11-geos37-gdal23-proj52 mode=usan_gcc
   - tag=pg11-geos37-gdal23-proj52 mode=tests
   - tag=pg10-geos36-gdal23-proj49 mode=tests
   - tag=pg96-geos36-gdal22-proj49 mode=tests
diff --git a/ci/travis/run_usan_gcc.sh b/ci/travis/run_usan_gcc.sh
new file mode 100644
index 000000000..332006e5c
--- /dev/null
+++ b/ci/travis/run_usan_gcc.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+set -e
+
+# Enable undefined behaviour sanitizer using traps to
+CFLAGS_STD="-g -O2 -mtune=generic -fno-omit-frame-pointer -fsanitize=undefined -fsanitize-undefined-trap-on-error"
+LDFLAGS_STD="-Wl,-Bsymbolic-functions -Wl,-z,relro"
+
+/usr/local/pgsql/bin/pg_ctl -c -l /tmp/logfile start
+./autogen.sh
+
+# Build with GCC and usan flags
+# TODO: Fix topology ubsan
+./configure CC=gcc CFLAGS="${CFLAGS_STD}" LDFLAGS="${LDFLAGS_STD}" --without-topology
+bash ./ci/travis/logbt -- make -j check RUNTESTFLAGS=--verbose
-- 
2.40.0