diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 58688e10c68e80f31d4b05062380c2677e9618a7..bd8efaecd57dbc6727ee680425cacf8790be7b2a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -68,6 +68,12 @@ autotools-enable-valgrind-testing:
     INSTALL_EXTRA: libtool valgrind
     CONFIG_FLAGS: --enable-valgrind-testing
 
+autotools-enable-gcc-sanitizers:
+  extends: .autoconf
+  variables:
+    INSTALL_EXTRA: libtool
+    CONFIG_FLAGS: --enable-gcc-sanitizers
+
 scons:
   stage: build
   before_script:
diff --git a/configure.ac b/configure.ac
index 61b4cbddae95602d8d01cabd954f5b3ebb976e44..fb5d9b251dfe6adbcba6a72b93dbb2554091fcf9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,6 +196,18 @@ else
 fi
 CFLAGS="$CFLAGS $cflags_save"
 
+AC_ARG_ENABLE(gcc-sanitizers,
+    AS_HELP_STRING([--enable-gcc-sanitizers], [Enable GCC sanitizers]),
+    [ ac_enable_gcc_sanitizers=$enableval ], [ ac_enable_gcc_sanitizers=no] )
+
+if test "$GCC" && test "x${ac_enable_gcc_sanitizers}" = xyes; then
+  CFLAGS="${CFLAGS} -fsanitize=address -fsanitize=undefined -g"
+  LDFLAGS="${CFLAGS} -fsanitize=address"
+
+  TEST_ENV="env UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1"
+  AC_SUBST(TEST_ENV)
+fi
+
 cpu_x86_64=no
 cpu_x86_32=no
 cpu_arm=no
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bcd60f9207fa1465a6f76b4847cfa09beffb6842..e4c9183e4e2e996a40588d256a2fd3bec6c64d7f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,9 @@ THEORAENC_LIBS = $(THEORADIR)/libtheoraenc.la \
 		 $(THEORADIR)/libtheoradec.la $(OGG_LIBS)
 test: check
 
-LOG_COMPILER=$(LIBTOOL) --mode=execute $(VALGRIND)
+TEST_ENV = @TEST_ENV@
+
+LOG_COMPILER=$(LIBTOOL) --mode=execute $(VALGRIND) $(TEST_ENV)
 
 TESTS_DEC = noop_theora \
 	comment comment_theoradec comment_theora