From d0294dd70edf06548ac0e8b71ff2dce896042edb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= <rene.kijewski@fu-berlin.de>
Date: Thu, 24 Sep 2015 23:51:05 +0200
Subject: [PATCH] make: enable `assert()` in `make scan-build`

Compare scan-build's [documentation][1]:

> ALWAYS analyze a project in its "debug" configuration
>
> Most projects can be built in a "debug" mode that enables assertions.
> Assertions are picked up by the static analyzer to prune infeasible
> paths, which in some cases can greatly reduce the number of false
> positives (bogus error reports) emitted by the tool.

Closes #3960.

  1: http://clang-analyzer.llvm.org/scan-build.html#recommended_debug
---
 Makefile.cflags     | 4 +++-
 Makefile.scan-build | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Makefile.cflags b/Makefile.cflags
index 3755c1028b..4e079d0ccf 100644
--- a/Makefile.cflags
+++ b/Makefile.cflags
@@ -56,7 +56,9 @@ CFLAGS += -fno-common
 CFLAGS += -Wall
 
 ifeq (,$(filter -DDEVELHELP,$(CFLAGS)))
-	CFLAGS += -DNDEBUG
+  ifneq (1,$(FORCE_ASSERTS))
+    CFLAGS += -DNDEBUG
+  endif
 endif
 
 # Default ARFLAGS for platforms which do not specify it.
diff --git a/Makefile.scan-build b/Makefile.scan-build
index a12faf29dc..3442119b22 100644
--- a/Makefile.scan-build
+++ b/Makefile.scan-build
@@ -70,7 +70,7 @@ scan-build-analyze: clean
 	$(AD)mkdir -p '$(SCANBUILD_OUTPUTDIR)'
 	$(AD)env -i $(ENVVARS) \
 	    scan-build -o '$(SCANBUILD_OUTPUTDIR)' $(SCANBUILD_ARGS) \
-	      make -C $(CURDIR) all $(strip $(CMDVARS));
+	      make -C $(CURDIR) all $(strip $(CMDVARS)) FORCE_ASSERTS=1;
 endif # BUILD_IN_DOCKER
 
 ifeq (1,$(INSIDE_DOCKER))
-- 
GitLab