Re: [PHP-DEV] Require C11 in PHP 8.4

On 1 August 2024 22:57:36 BST, Ilija Tovilo <tovilo.ilija@gmail.com> wrote:

Hi everyone

We've gotten a bug report about compile errors in the PHP 8.4 alpha on
old C99 compilers (and on some modern compilers when passing the
-std=c99 flag). Specifically, C99 does not support typedef
redeclarations, which is a C11 feature.

// some_header.h
typedef struct _zval_struct zval;
void some_func(zval *zv);

// zend_types.h
struct _zval_struct { ... };
typedef struct _zval_struct zval;

Some headers might want to forward declare zval so that zend_types.h
doesn't have to be included. The two primary reasons you might want to
avoid that are 1. to reduce compile times if the header is very large
and 2. to prevent recursive header dependencies.

However, in C99 this code is actually illegal if both of these headers
end up being included, because redeclarations of typedefs are not
allowed. To fix it, the typedef must be removed and the signatures
must refer to the struct directly.

// some_header.h
struct _zval_struct;
void some_func(struct _zval_struct *zv);

I started fixing these in a PR [1] which required more changes than
expected. After a short discourse, we were wondering whether it might
be better to switch to a newer C standard instead. Our coding
standards [2] currently specify that compiling php-src requires C99.
The Unix installation page on php.net [3] claims it is ANSI C, which
is certainly outdated. There have been suggestions to require C11 for
a while, which should be well supported by all compilers shipped with
maintained distributions.

GCC gained support for C11 in 4.7 [4], LLVM Clang in 3.1, both
released in 2012. For context, Debian Bullseye comes with GCC 10.2
[5], Ubuntu Focal Fossa comes with GCC 9.3 [6], RHEL 8 comes with GCC
8.x [7].

Even Debian wheezy (out of extended LTS support) or Ubuntu 14.04 have GCC 4.7, so that seems OK.

How about Clang (for OSX) though? I can't check that easily.

cheers
Derick

On 2 Aug 2024, at 05:26, Derick Rethans derick@php.net wrote:

On 1 August 2024 22:57:36 BST, Ilija Tovilo <tovilo.ilija@gmail.com> wrote:

Hi everyone

We’ve gotten a bug report about compile errors in the PHP 8.4 alpha on
old C99 compilers (and on some modern compilers when passing the
-std=c99 flag). Specifically, C99 does not support typedef
redeclarations, which is a C11 feature.

// some_header.h
typedef struct _zval_struct zval;
void some_func(zval *zv);

// zend_types.h
struct _zval_struct { ... };
typedef struct _zval_struct zval;

Some headers might want to forward declare zval so that zend_types.h
doesn’t have to be included. The two primary reasons you might want to
avoid that are 1. to reduce compile times if the header is very large
and 2. to prevent recursive header dependencies.

However, in C99 this code is actually illegal if both of these headers
end up being included, because redeclarations of typedefs are not
allowed. To fix it, the typedef must be removed and the signatures
must refer to the struct directly.

// some_header.h
struct _zval_struct;
void some_func(struct _zval_struct *zv);

I started fixing these in a PR [1] which required more changes than
expected. After a short discourse, we were wondering whether it might
be better to switch to a newer C standard instead. Our coding
standards [2] currently specify that compiling php-src requires C99.
The Unix installation page on php.net [3] claims it is ANSI C, which
is certainly outdated. There have been suggestions to require C11 for
a while, which should be well supported by all compilers shipped with
maintained distributions.

GCC gained support for C11 in 4.7 [4], LLVM Clang in 3.1, both
released in 2012. For context, Debian Bullseye comes with GCC 10.2
[5], Ubuntu Focal Fossa comes with GCC 9.3 [6], RHEL 8 comes with GCC
8.x [7].

Even Debian wheezy (out of extended LTS support) or Ubuntu 14.04 have GCC 4.7, so that seems OK.

How about Clang (for OSX) though? I can’t check that easily.

cheers
Derick

Hi,

According to https://releases.llvm.org/3.1/docs/ClangReleaseNotes.html#cchanges, Clang 3.1 added C11.

According to https://trac.macports.org/wiki/XcodeVersionInfo, Clang 3.1 shipped with Xcode 4.3.3, in May 2012.

In terms of confirming this, the oldest macOS VM I have quick access to is running Sierra (from 2016, last OS update in 2019), and default install now for Clang on that VM is 9.0.0

Hope this helps

Cheers

Stephen

On 02.08.2024 at 07:50, Stephen Reay wrote:

According to Clang 3.1 Release Notes, Clang 3.1 added C11.

According to XcodeVersionInfo – MacPorts, Clang 3.1 shipped with Xcode 4.3.3, in May 2012.

In terms of confirming this, the oldest macOS VM I have quick access to is running Sierra (from 2016, last OS update in 2019), and default install now for Clang on that VM is 9.0.0

According to a comment on the pull request[1], the clang version would
be different between LLVM and Apple's fork. An answer on
StackOverflow[2] confirms that. I figure that there is even no exact
matching of the version numbers possible, as Apple might support some
features, but not others. I can even imagine that general C11 support
is available, but not necessarily the typedef redeclaration which is
most important right now. So unless there is some normative
documentation, it might be necessary to see whether PHP 8.4 can be build
with Apple's clang (and which versions).

[1] <Avoid C99 typedef redeclaration error by iluuu1994 · Pull Request #15079 · php/php-src · GitHub;
[2]
<macos - What is the difference between "clang" and "Apple clang"? - Stack Overflow;

Cheers,
Christoph