From 806820d16697536b5b0bcb2e9129a781556b7fa5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@sury.org>
Date: Mon, 11 May 2015 16:53:46 +0200
Subject: [PATCH] Disable fast zone parser when used with LLVM backed compiler
 (closes #351)

---
 configure.ac     | 10 ++++++++++
 m4/ax_cc_llvm.m4 | 15 +++++++++++++++
 2 files changed, 25 insertions(+)
 create mode 100644 m4/ax_cc_llvm.m4

diff --git a/configure.ac b/configure.ac
index 03bb222e2d..88a90a9304 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,8 @@ AM_CONDITIONAL([HAVE_DOCS], [test "$enable_documentation" = "yes"])
 
 AC_PROG_INSTALL
 
+AX_CC_LLVM
+
 AC_ARG_ENABLE([fastparser],
     AS_HELP_STRING([--disable-fastparser], [Disable use of fastest zone parser]),[],[
     # Set zone parser type - fastest on release build, slowest on dev build
@@ -67,6 +69,14 @@ AC_ARG_ENABLE([fastparser],
     	enable_fastparser=yes
     	])
     ])
+
+AS_IF([test "$enable_fastparser" = "yes"],[
+    AS_IF([test "${CC_LLVM}" = "yes"],[
+        AC_MSG_WARN([LLVM based compiler detected; disabling fastest zone parser, see https://gitlab.labs.nic.cz/labs/knot/issues/351])
+        enable_fastparser=no
+        ])
+    ])
+
 AM_CONDITIONAL([FAST_PARSER], [test "$enable_fastparser" = "yes"])
 
 # GnuTLS crypto backend
diff --git a/m4/ax_cc_llvm.m4 b/m4/ax_cc_llvm.m4
new file mode 100644
index 0000000000..aed8a42ebf
--- /dev/null
+++ b/m4/ax_cc_llvm.m4
@@ -0,0 +1,15 @@
+dnl Check to see if the C compiler is clang or llvm-gcc
+dnl
+AC_DEFUN([AX_CC_LLVM],[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_MSG_CHECKING([whether C compiler has a LLVM backend])
+  $CC -x c /dev/null -dM -E > conftest.txt 2>&1
+  if grep "__llvm__" conftest.txt >/dev/null 2>&1; then
+    CC_LLVM=yes
+  else
+    CC_LLVM=no
+  fi
+  AC_SUBST([CC_LLVM])
+  AC_MSG_RESULT([$CC_LLVM])
+  rm -f conftest.txt
+  ])
-- 
GitLab