From ad591fa80956f1902d5e82eaf027f3dc81013211 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 12:07:37 +0200 Subject: [PATCH 1/7] Check for compiler typedef redeclaration support at configure-time Closes GH-15070 --- Zend/Zend.m4 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index b7b44fb140872..5dabc4a96122d 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -1,5 +1,15 @@ dnl This file contains Zend specific autoconf macros. +AC_DEFUN([ZEND_CHECK_TYPEDEF_REDECL], [dnl +AC_CACHE_CHECK([if compiler allows typedef redeclarations], + [php_cv_have_typedef_redecl], + [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [dnl + typedef int mytype; + typedef int mytype; + ])], + [], + [AC_MSG_FAILURE([Compiler does not support typedef redeclarations. Does it support C11?])])])]) + dnl dnl ZEND_CHECK_FLOAT_PRECISION dnl @@ -157,6 +167,7 @@ AC_CHECK_FUNC([sigsetjmp],, [AC_MSG_FAILURE([Required sigsetjmp not found.])], [#include ])]) +ZEND_CHECK_TYPEDEF_REDECL ZEND_CHECK_STACK_DIRECTION ZEND_CHECK_FLOAT_PRECISION ZEND_DLSYM_CHECK From d617bef04d84d3d1151e6dea2e2007e8d62115ff Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 13:26:09 +0200 Subject: [PATCH 2/7] Review feedback --- Zend/Zend.m4 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 5dabc4a96122d..036433dd83d49 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -6,6 +6,8 @@ AC_CACHE_CHECK([if compiler allows typedef redeclarations], [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [dnl typedef int mytype; typedef int mytype; + mytype var; + (void)var; ])], [], [AC_MSG_FAILURE([Compiler does not support typedef redeclarations. Does it support C11?])])])]) From af17ad4f99d2719ce52297616366c23231d46ab9 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 14:04:10 +0200 Subject: [PATCH 3/7] Update Zend/Zend.m4 Co-authored-by: Peter Kokot --- Zend/Zend.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 036433dd83d49..ca613db1856fc 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -9,8 +9,12 @@ AC_CACHE_CHECK([if compiler allows typedef redeclarations], mytype var; (void)var; ])], - [], - [AC_MSG_FAILURE([Compiler does not support typedef redeclarations. Does it support C11?])])])]) + [php_cv_have_typedef_redecl=yes], + [php_cv_have_typedef_redecl=no])]) +AS_VAR_IF([php_cv_have_typedef_redecl], [no], + [AC_MSG_FAILURE(m4_text_wrap([ + Compiler does not support typedef redeclarations. Does it support C11? + ]))]) dnl dnl ZEND_CHECK_FLOAT_PRECISION From 6385c0dc0eb67aef3a925de251714df915d7fae0 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 14:06:17 +0200 Subject: [PATCH 4/7] Update Zend/Zend.m4 Co-authored-by: Peter Kokot --- Zend/Zend.m4 | 1 + 1 file changed, 1 insertion(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index ca613db1856fc..22ce4fe9e7bdf 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -15,6 +15,7 @@ AS_VAR_IF([php_cv_have_typedef_redecl], [no], [AC_MSG_FAILURE(m4_text_wrap([ Compiler does not support typedef redeclarations. Does it support C11? ]))]) +]) dnl dnl ZEND_CHECK_FLOAT_PRECISION From fecf518aa77dfbdf666806bcb7ac6f6d1a3207d4 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 14:12:36 +0200 Subject: [PATCH 5/7] Update Zend/Zend.m4 Co-authored-by: Peter Kokot --- Zend/Zend.m4 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 22ce4fe9e7bdf..090621fa313f5 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -1,5 +1,11 @@ dnl This file contains Zend specific autoconf macros. +dnl +dnl ZEND_CHECK_TYPEDEF_REDECL +dnl +dnl Check whether the compiler supports typedef redeclaractions. For example, +dnl GCC 4.2 on Mac OS X 10.6 emits a redefinition of typedef error by default. +dnl AC_DEFUN([ZEND_CHECK_TYPEDEF_REDECL], [dnl AC_CACHE_CHECK([if compiler allows typedef redeclarations], [php_cv_have_typedef_redecl], From fd8bc8bde0eb9f57de66de4bdf0da0113530689f Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Wed, 14 Aug 2024 15:33:21 +0200 Subject: [PATCH 6/7] [skip ci] Adjust CODING_STANDARDS.md to use C11 --- CODING_STANDARDS.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CODING_STANDARDS.md b/CODING_STANDARDS.md index 5fb2586eadd78..c599194ed50e3 100644 --- a/CODING_STANDARDS.md +++ b/CODING_STANDARDS.md @@ -9,12 +9,10 @@ rewritten to comply with these rules. 1. Document your code in source files and the manual. (tm) -1. PHP is implemented in C99. +1. PHP is implemented in C11. For instance, the optional fixed-width integers from stdint.h (int8_t, int16_t, int32_t, int64_t and their unsigned counterparts) are supposed to be available. - However, some features (most notably variable-length arrays) which are not - supported by all relevant compilers, must not be used. 1. Functions that are given pointers to resources should not free them. From d43b742e467799ca4a9612e447ed28a5a1f48260 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 16 Aug 2024 17:54:33 +0200 Subject: [PATCH 7/7] Add -Wno-typedef-redefinition to Clang This allows it to continue to run in C99 mode. --- Zend/Zend.m4 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 090621fa313f5..7ffdfcbf9b583 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -230,6 +230,10 @@ AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes], AX_CHECK_COMPILE_FLAG([-fno-common], [CFLAGS="-fno-common $CFLAGS"],, [-Werror]) +dnl Suppress the Clang typedef redefinition warnings if it has enabled C99 mode. +AX_CHECK_COMPILE_FLAG([-Wno-typedef-redefinition], + [CFLAGS="$CFLAGS -Wno-typedef-redefinition"],, + [-Werror]) ZEND_CHECK_ALIGNMENT ZEND_CHECK_SIGNALS