[Asterisk-code-review] Moved clang / RAII specific check to their own files Added c... (asterisk[13])

Diederik de Groot asteriskteam at digium.com
Mon Apr 20 07:59:31 CDT 2015


Diederik de Groot has uploaded a new change for review.

  https://gerrit.asterisk.org/157

Change subject: Moved clang / RAII specific check to their own files Added clang warning suppressions to Makefile.rules Adapted configure.ac Ran bootstap
......................................................................

Moved clang / RAII specific check to their own files
Added clang warning suppressions to Makefile.rules
Adapted configure.ac
Ran bootstap

Change-Id: I12ea29d3bda2254ad3908e279b7effbbac6a97cb
---
M Makefile.rules
A autoconf/ast_check_raii.m4
A autoconf/ast_check_strsep_array_bounds.m4
M configure
M configure.ac
M include/asterisk/autoconfig.h.in
M makeopts.in
7 files changed, 265 insertions(+), 108 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/157/1

diff --git a/Makefile.rules b/Makefile.rules
index a24cc72..a274c95 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -65,6 +65,11 @@
 CC_CFLAGS=$(PTHREAD_CFLAGS) $(_ASTCFLAGS) $(ASTCFLAGS)
 CXX_CFLAGS=$(PTHREAD_CFLAGS) $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(AST_DECLARATION_AFTER_STATEMENT),$(_ASTCFLAGS) $(ASTCFLAGS))
 
+# Clang -Werror warning suppressions
+ifeq ($(C_COMPILER_FAMILY),clang)
+	CC_CFLAGS+=-Wno-unused-value -Wno-parentheses-equality
+endif
+
 ifeq ($(GNU_LD),1)
 SO_SUPPRESS_SYMBOLS=-Wl,--version-script,$(subst .so,.exports,$@),--warn-common
 ifneq ($(wildcard $(subst .so,.dynamics,$@)),)
diff --git a/autoconf/ast_check_raii.m4 b/autoconf/ast_check_raii.m4
new file mode 100644
index 0000000..a698110
--- /dev/null
+++ b/autoconf/ast_check_raii.m4
@@ -0,0 +1,51 @@
+dnl check RAII requirements
+dnl gcc / llvm-gcc: -fnested-functions
+dnl clang : -fblocks / -fblocks and -lBlocksRuntime"
+AC_DEFUN([AST_CHECK_RAII], [
+	AC_MSG_CHECKING([for RAII support])
+
+	AST_C_COMPILER_FAMILY=""
+	AS_CASE(["$(${BASENAME} ${CC})"],
+		[gcc*|llvm-gcc*],
+		[
+			dnl Nested functions required for RAII implementation
+			AC_MSG_CHECKING(for gcc -fnested-functions)
+			AC_COMPILE_IFELSE(
+				dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774
+				[
+					AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])
+				],[
+					AST_NESTED_FUNCTIONS=""
+					AC_MSG_RESULT(no)
+				],[
+					AST_NESTED_FUNCTIONS="-fnested-functions"
+					AC_MSG_RESULT(yes)
+				]
+			)
+			AC_SUBST(AST_NESTED_FUNCTIONS)
+			AST_C_COMPILER_FAMILY="gcc"
+		],
+		[clang*|ccc-analyzer],
+		[
+			AC_MSG_CHECKING(for clang -fblocks)
+			if test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
+				AST_CLANG_BLOCKS_LIBS=""
+				AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"
+				AST_C_COMPILER_FAMILY="clang"
+				AC_MSG_RESULT(yes)
+			elif test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
+				AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"
+				AST_CLANG_BLOCKS="-fblocks"
+				AST_C_COMPILER_FAMILY="clang"
+				AC_MSG_RESULT(yes)
+			else
+				AC_MSG_ERROR([BlocksRuntime is required for clang, please install libblocksruntime])
+			fi
+			AC_SUBST(AST_CLANG_BLOCKS_LIBS)
+			AC_SUBST(AST_CLANG_BLOCKS)
+		], [
+			AC_MSG_ERROR([Compiler ${CC} not supported. Mminimum required gcc-4.3 / llvm-gcc-4.3 / clang-3.3 + libblocksruntime-dev])
+		]
+	)
+	AC_SUBST(AST_C_COMPILER_FAMILY)
+])
diff --git a/autoconf/ast_check_strsep_array_bounds.m4 b/autoconf/ast_check_strsep_array_bounds.m4
new file mode 100644
index 0000000..a893895
--- /dev/null
+++ b/autoconf/ast_check_strsep_array_bounds.m4
@@ -0,0 +1,53 @@
+dnl "https://llvm.org/bugs/show_bug.cgi?id=11536" / "https://reviewboard.asterisk.org/r/4546/"
+AC_DEFUN([AST_CHECK_STRSEP_ARRAY_BOUNDS], [
+	AC_MSG_CHECKING([for clang strsep/strcmp optimization])
+	save_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS -O1 -Werror=array-bounds"
+	AC_COMPILE_IFELSE(
+		[
+		    	AC_LANG_SOURCE([
+				#include <stdio.h>
+				#include <string.h>
+
+				/* works with gcc and clang : used to illustrate that the optimized function is not completely broken */
+				/*
+				void test1 (void) {
+					const char delimiter[] = ",";
+					char *teststr1 = "test,test";
+					char *outstr;
+					if ((outstr = strsep(&teststr1, delimiter))) {
+						printf("ok:%s\n", outstr);
+					}
+					const char *teststr2 = "test,test";
+					if (!strcmp(teststr2, delimiter)) {
+						printf("strcmp\n");
+					}
+				}
+				*/
+				/* fails with clang and -O1 */
+				void test_strsep (void) {
+					char *teststr1 = "test,test";
+					char *outstr;
+					if ((outstr = strsep(&teststr1, ","))) {
+						printf("fail:%s\n", outstr);
+					}
+					const char *teststr2 = "test,test";
+					if (!strcmp(teststr2, ",")) {
+						printf("fail\n");
+					}
+				}
+				int main(int argc, char *argv[]) {
+					test_strsep();
+					return 0;
+				}
+			])
+		],[
+			AC_MSG_RESULT(no)
+		],[
+			AC_DEFINE([_HAVE_STRING_ARCH_strcmp], 1, [Prevent clang array-bounds warning when using of bits/string2.h version of strcmp])
+			AC_DEFINE([_HAVE_STRING_ARCH_strsep], 1, [Prevent clang array-bounds warning when using of bits/string2.h version of strsep])
+			AC_MSG_RESULT([prevent use of __string2_1bptr_p / strsep from bits/string2.h])
+		]
+	)
+	CFLAGS="$save_CFLAGS"
+])
diff --git a/configure b/configure
index c7c0608..19e076b 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.ac Revision: 432281 .
+# From configure.ac Revision.
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.69 for asterisk trunk.
 #
@@ -687,9 +687,6 @@
 PBX_GLOB_BRACE
 PBX_GLOB_NOMAGIC
 AST_RPATH
-AST_CLANG_BLOCKS
-AST_CLANG_BLOCKS_LIBS
-AST_NESTED_FUNCTIONS
 AST_NATIVE_ARCH
 AST_SHADOW_WARNINGS
 AST_NO_STRICT_OVERFLOW
@@ -1140,6 +1137,10 @@
 ALSA_DIR
 ALSA_INCLUDE
 ALSA_LIB
+AST_C_COMPILER_FAMILY
+AST_CLANG_BLOCKS
+AST_CLANG_BLOCKS_LIBS
+AST_NESTED_FUNCTIONS
 AST_CODE_COVERAGE
 AST_DEVMODE_STRICT
 AST_DEVMODE
@@ -8215,6 +8216,145 @@
 	esac
 fi
 
+
+
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for RAII support" >&5
+$as_echo_n "checking for RAII support... " >&6; }
+
+	AST_C_COMPILER_FAMILY=""
+	case "$(${BASENAME} ${CC})" in #(
+  gcc*|llvm-gcc*) :
+
+						{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc -fnested-functions" >&5
+$as_echo_n "checking for gcc -fnested-functions... " >&6; }
+			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+auto void foo(void); void foo(void) {}
+  ;
+  return 0;
+}
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+					AST_NESTED_FUNCTIONS=""
+					{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+else
+
+					AST_NESTED_FUNCTIONS="-fnested-functions"
+					{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+			AST_C_COMPILER_FAMILY="gcc"
+		 ;; #(
+  clang*|ccc-analyzer) :
+
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang -fblocks" >&5
+$as_echo_n "checking for clang -fblocks... " >&6; }
+			if test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
+				AST_CLANG_BLOCKS_LIBS=""
+				AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"
+				AST_C_COMPILER_FAMILY="clang"
+				{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+			elif test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
+				AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"
+				AST_CLANG_BLOCKS="-fblocks"
+				AST_C_COMPILER_FAMILY="clang"
+				{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+			else
+				as_fn_error $? "BlocksRuntime is required for clang, please install libblocksruntime" "$LINENO" 5
+			fi
+
+
+		 ;; #(
+  *) :
+
+			as_fn_error $? "Compiler ${CC} not supported. Mminimum required gcc-4.3 / llvm-gcc-4.3 / clang-3.3 + libblocksruntime-dev" "$LINENO" 5
+
+	 ;;
+esac
+
+
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang strsep/strcmp optimization" >&5
+$as_echo_n "checking for clang strsep/strcmp optimization... " >&6; }
+	save_CFLAGS="$CFLAGS"
+	CFLAGS="$CFLAGS -O1 -Werror=array-bounds"
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+				#include <stdio.h>
+				#include <string.h>
+
+				/* works with gcc and clang : used to illustrate that the optimized function is not completely broken */
+				/*
+				void test1 (void) {
+					const char delimiter = ",";
+					char *teststr1 = "test,test";
+					char *outstr;
+					if ((outstr = strsep(&teststr1, delimiter))) {
+						printf("ok:%s\n", outstr);
+					}
+					const char *teststr2 = "test,test";
+					if (!strcmp(teststr2, delimiter)) {
+						printf("strcmp\n");
+					}
+				}
+				*/
+				/* fails with clang and -O1 */
+				void test_strsep (void) {
+					char *teststr1 = "test,test";
+					char *outstr;
+					if ((outstr = strsep(&teststr1, ","))) {
+						printf("fail:%s\n", outstr);
+					}
+					const char *teststr2 = "test,test";
+					if (!strcmp(teststr2, ",")) {
+						printf("fail\n");
+					}
+				}
+				int main(int argc, char *argv) {
+					test_strsep();
+					return 0;
+				}
+
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+else
+
+
+$as_echo "#define _HAVE_STRING_ARCH_strcmp 1" >>confdefs.h
+
+
+$as_echo "#define _HAVE_STRING_ARCH_strsep 1" >>confdefs.h
+
+			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: prevent use of __string2_1bptr_p / strsep from bits/string2.h" >&5
+$as_echo "prevent use of __string2_1bptr_p / strsep from bits/string2.h" >&6; }
+
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+	CFLAGS="$save_CFLAGS"
 
 
 # AST_EXT_LIB_SETUP is used to tell configure to handle variables for
@@ -17376,74 +17516,6 @@
 fi
 
 
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-		#if defined(__clang__)
-		choke
-		#endif
-
-  ;
-  return 0;
-}
-
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
-
-				{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc -fnested-functions" >&5
-$as_echo_n "checking for gcc -fnested-functions... " >&6; }
-		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-auto void foo(void); void foo(void) {}
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-			AST_NESTED_FUNCTIONS=
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-			AST_NESTED_FUNCTIONS=-fnested-functions
-
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-
-
-else
-
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang -fblocks" >&5
-$as_echo_n "checking for clang -fblocks... " >&6; }
-		if test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
-			AST_CLANG_BLOCKS_LIBS=""
-			AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-		elif test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
-			AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"
-			AST_CLANG_BLOCKS="-fblocks"
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-		else
-			as_fn_error $? "\"BlocksRuntime is required for clang\"" "$LINENO" 5
-		fi
-
-
-
-
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
 
 # Check whether --enable-rpath was given.
 if test "${enable_rpath+set}" = set; then :
diff --git a/configure.ac b/configure.ac
index edb4322..971f9bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -386,6 +386,9 @@
 	esac])
 AC_SUBST(AST_CODE_COVERAGE)
 
+AST_CHECK_RAII()
+AST_CHECK_STRSEP_ARRAY_BOUNDS()
+
 # AST_EXT_LIB_SETUP is used to tell configure to handle variables for
 # various packages.
 # $1 is the prefix for the variables in makeopts and autoconfig.h
@@ -1132,42 +1135,6 @@
 fi
 AC_SUBST(AST_NATIVE_ARCH)
 
-dnl Nested functions required for RAII implementation
-AC_LINK_IFELSE(
-	[AC_LANG_PROGRAM([], [
-		#if defined(__clang__)
-		choke
-		#endif
-		])
-	],[
-		dnl Nested functions required for RAII implementation
-		AC_MSG_CHECKING(for gcc -fnested-functions)
-		AC_COMPILE_IFELSE(
-			dnl Prototype needed due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36774
-			[AC_LANG_PROGRAM([], [auto void foo(void); void foo(void) {}])],
-			AC_MSG_RESULT(no)
-			[AST_NESTED_FUNCTIONS=],
-			AC_MSG_RESULT(yes)
-			[AST_NESTED_FUNCTIONS=-fnested-functions]
-		)
-		AC_SUBST(AST_NESTED_FUNCTIONS)
-	],[
-		AC_MSG_CHECKING(for clang -fblocks)
-		if test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c - 2>&1`" = ""; then
-			[AST_CLANG_BLOCKS_LIBS=""]
-			[AST_CLANG_BLOCKS="-Wno-unknown-warning-option -fblocks"]
-			AC_MSG_RESULT(yes)
-		elif test "`echo "int main(){return ^{return 42;}();}" | ${CC} -o /dev/null -fblocks -x c -lBlocksRuntime - 2>&1`" = ""; then
-			[AST_CLANG_BLOCKS_LIBS="-lBlocksRuntime"]
-			[AST_CLANG_BLOCKS="-fblocks"]
-			AC_MSG_RESULT(yes)
-		else
-			AC_MSG_ERROR("BlocksRuntime is required for clang")
-		fi
-		AC_SUBST(AST_CLANG_BLOCKS_LIBS)
-		AC_SUBST(AST_CLANG_BLOCKS)
-	]
-)
 
 dnl Check to see if rpath should be set in LDFLAGS
 AC_ARG_ENABLE(rpath,
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in
index a8293a2..6ed8c16 100644
--- a/include/asterisk/autoconfig.h.in
+++ b/include/asterisk/autoconfig.h.in
@@ -1307,6 +1307,14 @@
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
 
+/* Prevent clang array-bounds warning when using of bits/string2.h version of
+   strcmp */
+#undef _HAVE_STRING_ARCH_strcmp
+
+/* Prevent clang array-bounds warning when using of bits/string2.h version of
+   strsep */
+#undef _HAVE_STRING_ARCH_strsep
+
 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
 #undef _LARGEFILE_SOURCE
 
diff --git a/makeopts.in b/makeopts.in
index 96b031b..4922c2f 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -111,6 +111,7 @@
 AST_NESTED_FUNCTIONS=@AST_NESTED_FUNCTIONS@
 AST_CLANG_BLOCKS=@AST_CLANG_BLOCKS@
 AST_CLANG_BLOCKS_LIBS=@AST_CLANG_BLOCKS_LIBS@
+C_COMPILER_FAMILY=@AST_C_COMPILER_FAMILY@
 AST_RPATH=@AST_RPATH@
 AST_FORTIFY_SOURCE=@AST_FORTIFY_SOURCE@
 AST_MARCH_NATIVE=@AST_MARCH_NATIVE@

-- 
To view, visit https://gerrit.asterisk.org/157
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I12ea29d3bda2254ad3908e279b7effbbac6a97cb
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Diederik de Groot <dkgroot at talon.nl>



More information about the asterisk-code-review mailing list