From e081cd01fba0a860a9cb3c0e4c9525e1c4146e57 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Thu, 29 Sep 2022 17:44:45 -0700
Subject: [PATCH v2 2/3] ci: use -fsanitize=undefined,alignment in linux tasks

---
 .cirrus.yml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/.cirrus.yml b/.cirrus.yml
index 7b5cb021027..c329a2befe4 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -169,6 +169,19 @@ task:
     LINUX_CONFIGURE_FEATURES: *LINUX_CONFIGURE_FEATURES
     LINUX_MESON_FEATURES: *LINUX_MESON_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: print_stacktrace=1:disable_coredump=0:abort_on_error=1:detect_leaks=0
+
   only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*linux.*'
 
   compute_engine_instance:
@@ -230,6 +243,10 @@ task:
     - name: Linux - Debian Bullseye - Meson
 
       configure_script: |
+        SANITIZER_FLAGS="-fsanitize=alignment,undefined -fno-sanitize-recover=all -fno-common"
+        CFLAGS="$SANITIZER_FLAGS $CFLAGS"
+        LDFLAGS="$SANITIZER_FLAGS $LDFLAGS"
+
         su postgres <<-EOF
           meson setup \
             --buildtype=debug \
-- 
2.37.3.542.gdd3f6c4cae

