From e5e69c83957ece0086c2b7a958152857b5930050 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sun, 23 Jan 2022 22:20:10 -0800
Subject: [PATCH v3 4/5] ci: use -fsanitize=undefined,alignment in linux tasks.

---
 .cirrus.yml | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index e5335fede76..820aafce292 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -157,6 +157,21 @@ task:
 
     LINUX_CONFIGURE_FEATURES: *LINUX_CONFIGURE_FEATURES
 
+    # Enable a reasonable set of sanitizers. Use the linux task for that, as
+    # it currently is the fastest task. Also several of the sanitizers work
+    # best on linux.
+    # The overhead of alignment sanitizer is low, undefined behaviour has
+    # moderate overhead. address sanitizer howerever is pretty expensive and
+    # thus not enabled.
+    #
+    # disable_coredump=0, abort_on_error=1: for useful backtraces in case of crashes
+    # print_stacktraces=1,verbosity=2, duh
+    # detect_leaks=0: too many uninteresting leak errors in short-lived binaries
+    UBSAN_OPTIONS: print_stacktrace=1:disable_coredump=0:abort_on_error=1:verbosity=2
+    ASAN_OPTIONS: detect_leaks=0:disable_coredump=0:abort_on_error=1
+    EXTRA_CFLAGS: -fsanitize=alignment,undefined -fno-sanitize-recover=all
+    EXTRA_LDFLAGS: -fno-common
+
   only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
 
   compute_engine_instance:
@@ -201,8 +216,9 @@ task:
         CC="ccache gcc" \
         CXX="ccache g++" \
         CLANG="ccache clang" \
-        CFLAGS="-Og -ggdb" \
-        CXXFLAGS="-Og -ggdb"
+        CFLAGS="-Og -ggdb ${EXTRA_CFLAGS}" \
+        CXXFLAGS="-Og -ggdb ${EXTRA_CXXFLAGS}" \
+        LDFLAGS="${EXTRA_LDFLAGS}"
     EOF
   build_script: su postgres -c "make -s -j${BUILD_JOBS} world-bin"
   upload_caches: ccache
-- 
2.35.1.354.g715d08a9e5

